{"id":14970684,"url":"https://github.com/fridiculous/django-estimators","last_synced_at":"2025-10-26T13:31:10.273Z","repository":{"id":11098158,"uuid":"67751513","full_name":"fridiculous/django-estimators","owner":"fridiculous","description":"a django app to persist and retrieve scikit learn machine learning models","archived":false,"fork":false,"pushed_at":"2022-12-26T20:25:53.000Z","size":83,"stargazers_count":49,"open_issues_count":8,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-28T13:23:02.015Z","etag":null,"topics":["django","machine-learning","scikit-learn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fridiculous.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-09T00:44:57.000Z","updated_at":"2023-12-19T17:39:20.000Z","dependencies_parsed_at":"2023-01-13T16:19:52.741Z","dependency_job_id":null,"html_url":"https://github.com/fridiculous/django-estimators","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fridiculous%2Fdjango-estimators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fridiculous%2Fdjango-estimators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fridiculous%2Fdjango-estimators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fridiculous%2Fdjango-estimators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fridiculous","download_url":"https://codeload.github.com/fridiculous/django-estimators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219862887,"owners_count":16555951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","machine-learning","scikit-learn"],"created_at":"2024-09-24T13:43:59.251Z","updated_at":"2025-10-26T13:31:09.942Z","avatar_url":"https://github.com/fridiculous.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n.. image:: https://travis-ci.org/fridiculous/django-estimators.svg?branch=master\n    :target: https://travis-ci.org/fridiculous/django-estimators\n\n.. image:: https://coveralls.io/repos/github/fridiculous/django-estimators/badge.svg?branch=master\n    :target: https://coveralls.io/github/fridiculous/django-estimators?branch=master\n\n.. image:: https://landscape.io/github/fridiculous/django-estimators/master/landscape.svg?style=flat\n   :target: https://landscape.io/github/fridiculous/django-estimators/master\n\n\nDjango-Estimators\n=================\n\nTidy Persistence and Retrieval for Machine Learning\n\n\nIntro\n-----\nDjango-Estimators helps persist and track machine learning models (aka estimators) and datasets.\n\n\nThis library provides a series of proxy objects that wrap common python machine learning objects and dataset objects.  This library versions, track progress and deploy models.  It's highly extensible and can be used with most any python object (scikit-learn, numpy arrays, modules, methods).\n\nThis repo utilizes django as an ORM.  If you'd like to work outside of django, try the sqlalchemy-based `estimators \u003chttps://github.com/fridiculous/estimators.git\u003e`_ library instead.\n\n\nInstallation\n------------\n\n\nRun: \n::\n\n    pip install django-estimators\n\n\nQuick start\n-----------\n\n1. Add ``estimators`` to your INSTALLED_APPS.\n::\n\n    INSTALLED_APPS = [\n        ...\n        'estimators',\n    ]\n  \n2. Create the estimators table.\n::\n\n    python manage.py migrate\n\n3. Create a new model. Run ``python manage.py shell``\n::\n\n    from sklearn.ensemble import RandomForestClassifier\n    rfc = RandomForestClassifier()\n    \n    from estimators.models import Estimator\n    est = Estimator(estimator=rfc)\n    est.description = 'a simple forest'\n    est.save()\n\n4.  Retrieve your model using the django orm.\n\n    est = Estimator.objects.last()\n    # now use your estimator\n    est.estimator.predict(X)\n\n\nRetrieving Models/Estimators\n----------------------------\n\nUse ``get_or_create`` to retrieve your model safely:\n::\n\n    est = Estimator.objects.get_or_create(estimator=object)\n    # or potentially update it with update_or_create\n    est = Estimator.objects.update_or_create(estimator=object)\n\nIf you have the model:\n\n    est = Estimator.objects.filter(estimator=object).first()\n\nRetrieve by unique hash:\n::\n\n    est = Estimator.objects.filter(object_hash='d9c9f286391652b89978a6961b52b674').first()\n\n\n\nPersisting and Retrieving DataSets\n----------------------------------\n\nThe `DataSet` class functions just like the `Estimator` class.  If you have\na numpy matrix or a pandas dataframe, wrap it with a DataSet object:\n::\n\n    import numpy as np\n    import pandas as pd\n\n    df = pd.DataFrame(np.random.randint(0,10,(100,8)))\n\n    from estimators.models import DataSet\n\n    ds = DataSet(data=df)\n    ds.save()\n\nPull that same DataSet object with:\n::\n\n    ds = DataSet.objects.latest('create_date')\n\nIf you already have the dataset:\n::\n\n    ds = DataSet.objects.filter(data=df).first()\n\n\nPersisting Predictions and Results \n----------------------------------\n\nThe most valuable part of a machine learning is the whole process.\nUsing an ``Evaluator`` object, define the relationships between X_test, y_test and\ny_predicted ahead of time.\n\nThen evaluate the evaluation plan, which in turn calls the ``predict`` method on the estimator\nand then presists all the wrapped objects.\n\n::\n\n    from sklearn.datasets import load_digits\n    from sklearn.ensemble import RandomForestClassifier\n    \n    digits = load_digits() # 1797 by 64\n    X = digits.data\n    y = digits.target\n    \n    # simple splitting for validation testing\n    X_train, X_test = X[:1200], X[1200:]\n    y_train, y_test = y[:1200], y[1200:]\n    \n    rfc = RandomForestClassifier()\n    rfc.fit(X_train, y_train)\n\nCreate the evaluation plan:\n::\n\n    from estimators.models import Evaluator\n    plan = Evaluator(X_test=X_test, y_test=y_test, estimator=rfc)\n\n    result = plan.evaluate() # executes `predict` method on X_test\n\nView all the atributes on the evaluation result:\n::\n\n    result.estimator\n    result.X_test\n    result.y_test # optional, used with supervised classifiers\n    result.y_predicted\n\n\nUsing with Jupyter Notebook (or without a django app)\n-----------------------------------------------------\n\nDjango-Estimators can run as a standalone django app. In order to have access to the django db, set up the environment variable to load up your django project.  In ipython, set the environment variable ``DJANGO_SETTINGS_MODULE`` to ``estimators.template_settings``:\n::\n\n    import os\n    import django\n    os.environ['DJANGO_SETTINGS_MODULE'] = \"estimators.template_settings\"\n    django.setup()\n\nWhen creating a new database (by default ``db.sqlite3``). Run this migration:\n::\n\n    from django.core.management import call_command\n    call_command('migrate')\n\n\nContinue as usual...\n::\n\n    from estimators.models import Estimator\n\n\nTo use custom settings, copy ``estimators.template_settings`` and edit the fields.  Like above, run ``os.environ['DJANGO_SETTINGS_MODULE'] = \"custom_settings_file\"`` before running ``django.setup()``.\n\n\nDevelopment Installation \n------------------------\n\nTo install the latest version of django-estimators, clone the repo, cd into the repo, and pip install with the current virtual environment.::\n\n    $ git clone git@github.com:fridiculous/django-estimators.git\n    $ cd django-estimators\n    $ \u003cactivate your project’s virtual environment\u003e\n    (virtualenv) $ pip install -e .\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffridiculous%2Fdjango-estimators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffridiculous%2Fdjango-estimators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffridiculous%2Fdjango-estimators/lists"}