Skip to content

Commit

Permalink
housekeeping in CI-tested notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSkolasinski committed May 22, 2020
1 parent 7fd05d1 commit 0c14de6
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 125 deletions.
15 changes: 5 additions & 10 deletions examples/ambassador/custom/ambassador_custom.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
"metadata": {},
"outputs": [],
"source": [
"!kubectl rollout status deploy/$(kubectl get deploy -l seldon-deployment-id=production-model-example -o jsonpath='{.items[0].metadata.name}')"
"%%bash\n",
"dep_name=$(kubectl get deploy -l seldon-deployment-id=example -o jsonpath='{.items[0].metadata.name}')\n",
"kubectl rollout status deploy/${dep_name}"
]
},
{
Expand Down Expand Up @@ -116,13 +118,6 @@
"source": [
"!kubectl delete -f model_custom_ambassador.json"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -142,7 +137,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.6"
},
"varInspector": {
"cols": {
Expand Down Expand Up @@ -175,5 +170,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
17 changes: 17 additions & 0 deletions examples/models/metadata/graph_metadata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,23 @@
"\n",
"meta"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cleanup resources"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"%%bash\n",
"kubectl delete -f graph-metadata/"
]
}
],
"metadata": {
Expand Down
3 changes: 2 additions & 1 deletion examples/models/sklearn_iris/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
IrisClassifier.sav
sklearn_iris_jsondata.py
sklearn_iris_jsondata.py
sklearn_iris.py
2 changes: 1 addition & 1 deletion examples/models/sklearn_iris/IrisClassifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sklearn.externals import joblib
import joblib

class IrisClassifier(object):

Expand Down
77 changes: 37 additions & 40 deletions examples/models/sklearn_iris/sklearn_iris.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,44 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"from sklearn.linear_model import LogisticRegression\n",
"%%writefile train_iris.py\n",
"import joblib\n",
"from sklearn.pipeline import Pipeline\n",
"from sklearn.externals import joblib\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn import datasets\n",
"\n",
"\n",
"OUTPUT_FILE = \"IrisClassifier.sav\"\n",
"\n",
"\n",
"def main():\n",
" clf = LogisticRegression()\n",
" p = Pipeline([('clf', clf)])\n",
" print('Training model...')\n",
" clf = LogisticRegression(solver=\"liblinear\", multi_class=\"ovr\")\n",
" p = Pipeline([(\"clf\", clf)])\n",
" print(\"Training model...\")\n",
" p.fit(X, y)\n",
" print('Model trained!')\n",
" print(\"Model trained!\")\n",
"\n",
" print(f\"Saving model in {OUTPUT_FILE}\")\n",
" joblib.dump(p, OUTPUT_FILE)\n",
" print(\"Model saved!\")\n",
"\n",
"\n",
" filename_p = 'IrisClassifier.sav'\n",
" print('Saving model in %s' % filename_p)\n",
" joblib.dump(p, filename_p)\n",
" print('Model saved!')\n",
" \n",
"if __name__ == \"__main__\":\n",
" print('Loading iris data set...')\n",
" print(\"Loading iris data set...\")\n",
" iris = datasets.load_iris()\n",
" X, y = iris.data, iris.target\n",
" print('Dataset loaded!')\n",
" main()\n"
" print(\"Dataset loaded!\")\n",
"\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!python train_iris.py"
]
},
{
Expand All @@ -65,20 +78,12 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting IrisClassifier.py\n"
]
}
],
"outputs": [],
"source": [
"%%writefile IrisClassifier.py\n",
"from sklearn.externals import joblib\n",
"import joblib\n",
"\n",
"class IrisClassifier(object):\n",
"\n",
Expand Down Expand Up @@ -109,7 +114,7 @@
"metadata": {},
"outputs": [],
"source": [
"!s2i build -E environment_rest . seldonio/seldon-core-s2i-python3:0.18 seldonio/sklearn-iris:0.1"
"!s2i build -E environment_rest . seldonio/seldon-core-s2i-python3:1.1.0 seldonio/sklearn-iris:0.1"
]
},
{
Expand Down Expand Up @@ -187,17 +192,9 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting sklearn_iris_deployment.yaml\n"
]
}
],
"outputs": [],
"source": [
"%%writefile sklearn_iris_deployment.yaml\n",
"apiVersion: machinelearning.seldon.io/v1alpha2\n",
Expand Down Expand Up @@ -321,7 +318,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
},
"varInspector": {
"cols": {
Expand Down Expand Up @@ -354,5 +351,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion examples/models/sklearn_iris/sklearn_iris_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ spec:
name: sklearn-iris-classifier
type: MODEL
name: sklearn-iris-predictor
replicas: 1
replicas: 1
33 changes: 18 additions & 15 deletions examples/models/sklearn_iris/train_iris.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import numpy as np
import os
from sklearn.linear_model import LogisticRegression
import joblib
from sklearn.pipeline import Pipeline
from sklearn.externals import joblib
from sklearn.linear_model import LogisticRegression
from sklearn import datasets


OUTPUT_FILE = "IrisClassifier.sav"


def main():
clf = LogisticRegression()
p = Pipeline([('clf', clf)])
print('Training model...')
clf = LogisticRegression(solver="liblinear", multi_class="ovr")
p = Pipeline([("clf", clf)])
print("Training model...")
p.fit(X, y)
print('Model trained!')
print("Model trained!")

print(f"Saving model in {OUTPUT_FILE}")
joblib.dump(p, OUTPUT_FILE)
print("Model saved!")


filename_p = 'IrisClassifier.sav'
print('Saving model in %s' % filename_p)
joblib.dump(p, filename_p)
print('Model saved!')

if __name__ == "__main__":
print('Loading iris data set...')
print("Loading iris data set...")
iris = datasets.load_iris()
X, y = iris.data, iris.target
print('Dataset loaded!')
print("Dataset loaded!")

main()
2 changes: 1 addition & 1 deletion examples/models/sklearn_iris_jsondata/IrisClassifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sklearn.externals import joblib
import joblib
import sys


Expand Down
77 changes: 37 additions & 40 deletions examples/models/sklearn_iris_jsondata/sklearn_iris_jsondata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,44 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import os\n",
"from sklearn.linear_model import LogisticRegression\n",
"%%writefile train_iris.py\n",
"import joblib\n",
"from sklearn.pipeline import Pipeline\n",
"from sklearn.externals import joblib\n",
"from sklearn.linear_model import LogisticRegression\n",
"from sklearn import datasets\n",
"\n",
"\n",
"OUTPUT_FILE = \"IrisClassifier.sav\"\n",
"\n",
"\n",
"def main():\n",
" clf = LogisticRegression()\n",
" p = Pipeline([('clf', clf)])\n",
" print('Training model...')\n",
" clf = LogisticRegression(solver=\"liblinear\", multi_class=\"ovr\")\n",
" p = Pipeline([(\"clf\", clf)])\n",
" print(\"Training model...\")\n",
" p.fit(X, y)\n",
" print('Model trained!')\n",
" print(\"Model trained!\")\n",
"\n",
" print(f\"Saving model in {OUTPUT_FILE}\")\n",
" joblib.dump(p, OUTPUT_FILE)\n",
" print(\"Model saved!\")\n",
"\n",
"\n",
" filename_p = 'IrisClassifier.sav'\n",
" print('Saving model in %s' % filename_p)\n",
" joblib.dump(p, filename_p)\n",
" print('Model saved!')\n",
" \n",
"if __name__ == \"__main__\":\n",
" print('Loading iris data set...')\n",
" print(\"Loading iris data set...\")\n",
" iris = datasets.load_iris()\n",
" X, y = iris.data, iris.target\n",
" print('Dataset loaded!')\n",
" main()\n"
" print(\"Dataset loaded!\")\n",
"\n",
" main()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!python train_iris.py"
]
},
{
Expand All @@ -65,20 +78,12 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting IrisClassifier.py\n"
]
}
],
"outputs": [],
"source": [
"%%writefile IrisClassifier.py\n",
"from sklearn.externals import joblib\n",
"import joblib\n",
"import sys\n",
"\n",
"\n",
Expand Down Expand Up @@ -118,7 +123,7 @@
"metadata": {},
"outputs": [],
"source": [
"!s2i build -E environment_rest . seldonio/seldon-core-s2i-python3:0.18 seldonio/sklearn-iris-jsondata:0.1"
"!s2i build -E environment_rest . seldonio/seldon-core-s2i-python3:1.1.0 seldonio/sklearn-iris-jsondata:0.1"
]
},
{
Expand Down Expand Up @@ -203,17 +208,9 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting sklearn_iris_jsondata_deployment.yaml\n"
]
}
],
"outputs": [],
"source": [
"%%writefile sklearn_iris_jsondata_deployment.yaml\n",
"apiVersion: machinelearning.seldon.io/v1alpha2\n",
Expand Down Expand Up @@ -340,7 +337,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
},
"varInspector": {
"cols": {
Expand Down Expand Up @@ -373,5 +370,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
Loading

0 comments on commit 0c14de6

Please sign in to comment.