Skip to main content


Project description

# Django-Learn
### A simplistic SciKitLearn Machine learning model persistence layer for django.

[![Build Status](]( [![Codacy Badge](](

## Basic Usage
from sklearn import svm
from sklearn import datasets
from djangolearn.models import SciKitLearnModel

iris = datasets.load_iris()

class IrisModel(SciKitLearnModel):

def train(self, X, Y):
clf = svm.SVC(), Y)

def evaluate(self, x):
# This is an example. Don't do this at request time
# Loading the model takes a bit
restored = self.restore()
restored_results = restored.predict(x)

X, y =,

instance = IrisModel.objects.create()
instance.train(X, y)

## Storage:

Django Learn uses [Django Storages](

If you want to specify a different storage system than the default one,
specify it through the setting:

DJANGOLEARN_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

Note that you will need to do the configuration management mentioned in the
Django Storage page.

## What's under the hood?

One simple solution would be to Pickle the model. [That's quite insecure](
For that reason we use joblib to store the models. There's a bit of validation sauce,
like making sure that the scikit version is the same as the one used to
train the system. There is also the option to specify the version of the
code/library used to pre-process the data, so that train data and evaluation
data have the same features.

## Security
Every object de-serialization is dangerous. Only store models you trust and
keep your model storage secure.
We try to make basic validations of the models, but python can only go so far. Use at your own risk.

## Performance
This is supposed to be an MVP for small jobs, and for playing around with machine learning in Django.
Loading models at request time is not recomemdend.

## Requirements
* Python 2.7 3.4 3.5
* Django > 1.7 (tests being deprecated for 1.7)
* SciKitLearn >= 0.15

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangolearn-0.1.tar.gz (25.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page