-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iris example for snapshot creation in python script and jupyter n…
…otebook
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from sklearn import datasets\n", | ||
"from sklearn.linear_model import LogisticRegression\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"import datmo" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"config = { \"solver\": \"newton-cg\" } # extra line" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"iris_dataset = datasets.load_iris()\n", | ||
"X, y = iris_dataset.data, iris_dataset.target\n", | ||
"X_train, X_test, y_train, y_test = train_test_split(X, y)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"model = LogisticRegression(**config).fit(X_train, y_train)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.946428571429\n", | ||
"0.973684210526\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"train_acc = model.score(X_train, y_train)\n", | ||
"test_acc = model.score(X_test, y_test)\n", | ||
"\n", | ||
"print(train_acc)\n", | ||
"print(test_acc)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "AttributeError", | ||
"evalue": "'module' object has no attribute 'snapshot'", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", | ||
"\u001b[0;32m<ipython-input-11-cab2e9246f30>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mstats\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m \u001b[0;34m\"train_accuracy\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtrain_acc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"test_accuracy\"\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mtest_acc\u001b[0m \u001b[0;34m}\u001b[0m \u001b[0;31m# extra line\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mdatmo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msnapshot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mconfig\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstats\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstats\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# extra line\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[0;31mAttributeError\u001b[0m: 'module' object has no attribute 'snapshot'" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"stats = { \"train_accuracy\": train_acc, \"test_accuracy\": test_acc } # extra line\n", | ||
"datmo.snapshot.create(config=config, stats=stats) # extra line" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from sklearn import datasets | ||
from sklearn.linear_model import LogisticRegression | ||
from sklearn.model_selection import train_test_split | ||
import datmo # extra line | ||
|
||
config = { "solver": "newton-cg" } # extra line | ||
iris_dataset = datasets.load_iris() | ||
X, y = iris_dataset.data, iris_dataset.target | ||
X_train, X_test, y_train, y_test = train_test_split(X, y) | ||
model = LogisticRegression(**config).fit(X_train, y_train) | ||
|
||
train_acc = model.score(X_train, y_train) | ||
test_acc = model.score(X_test, y_test) | ||
|
||
print(train_acc) | ||
print(test_acc) | ||
|
||
stats = { "train_accuracy": train_acc, "test_accuracy": test_acc } # extra line | ||
datmo.snapshot.create(config=config, stats=stats) # extra line |