Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active June 28, 2016 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts18/5f5e96438ec7231215fa0aea08f46475 to your computer and use it in GitHub Desktop.
Save jpotts18/5f5e96438ec7231215fa0aea08f46475 to your computer and use it in GitHub Desktop.
Nostradamus

Nostradamus

A framework for creating and deploying prediction application

Command Line

  • nstr new :project_name - create a folder called iris

  • nstr create :model_name - create a set of files inside of iris/svm_classifier/v1

  • nstr load :model_name --csv=raw.csv --model=model.pkl

  • nstr version :model_name - direct copy of folder for last version of model model and increments version. For example iris/svm_classifier/v2

  • nstr serve :model_name - this should run the app.py on localhost

  • nstr test :model_name - this should run the test suite for the app

  • nstr copy :original_name :new_name - this would make a new copy of everything

  • nstr build --model_file=model.pkl - Create a docker file. Warn users if model file is > 1 GB

  • nstr deploy - logs in to aws and published your container to EBS

  • Project structure

iris
└── svm_classifier
    └── v1
        ├── api.py
        ├── data
        │   └── raw.csv
        ├── estimator.py
        ├── models
        │   └── svm_classifier_2016050281212.pkl
        ├── pipeline.py
        ├── transformer.py
        └── worker.py

Notes: Add to pio create script --type=text,regression,classification

from flask import Flask, request, abort, jsonify
from sklearn.externals import joblib
import numpy as np
app = Flask(__name__)
# Treat model like a backing resource that can be changed out with and ENV variable.
MODEL_FILE = 'model/iris_classifier.pkl'
CLASSES = ['setosa',
'versicolor',
'virginica']
print(__doc__)
MODEL_FILE = 'model/iris_classifier.pkl'
from sklearn import svm, datasets
from sklearn.externals import joblib
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2] # we only take the first two features. We could
# avoid this ugly slicing by using a two-dim dataset
y = iris.target
# we create an instance of SVM and fit out data. We do not scale our
# data since we want to plot the support vectors
clf = svm.SVC(kernel='rbf', gamma=0.7, C=1.0).fit(X, y)
joblib.dump(clf, MODEL_FILE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment