# TeachableHub SDK - Model Deployment and Cloud Predictions
!pip install teachablehub
# Install your custom dependencies below
# ...
Requirement already satisfied: teachablehub in /root/venv/lib/python3.7/site-packages (1.0.32)
Requirement already satisfied: numpy in /root/venv/lib/python3.7/site-packages (from teachablehub) (1.20.3)
Requirement already satisfied: uplink==0.9.3 in /root/venv/lib/python3.7/site-packages (from teachablehub) (0.9.3)
Requirement already satisfied: th-sklearn-json in /root/venv/lib/python3.7/site-packages (from teachablehub) (0.1.0)
Requirement already satisfied: six>=1.12.0 in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from uplink==0.9.3->teachablehub) (1.16.0)
Requirement already satisfied: uritemplate>=3.0.0 in /root/venv/lib/python3.7/site-packages (from uplink==0.9.3->teachablehub) (3.0.1)
Requirement already satisfied: requests>=2.18.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from uplink==0.9.3->teachablehub) (2.25.1)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests>=2.18.0->uplink==0.9.3->teachablehub) (1.26.5)
Requirement already satisfied: certifi>=2017.4.17 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests>=2.18.0->uplink==0.9.3->teachablehub) (2020.12.5)
Requirement already satisfied: idna<3,>=2.5 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests>=2.18.0->uplink==0.9.3->teachablehub) (2.10)
Requirement already satisfied: chardet<5,>=3.0.2 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from requests>=2.18.0->uplink==0.9.3->teachablehub) (3.0.4)
Requirement already satisfied: scikit-learn>=0.21.3 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from th-sklearn-json->teachablehub) (0.24.2)
Requirement already satisfied: joblib>=0.11 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from scikit-learn>=0.21.3->th-sklearn-json->teachablehub) (1.0.1)
Requirement already satisfied: threadpoolctl>=2.0.0 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from scikit-learn>=0.21.3->th-sklearn-json->teachablehub) (2.1.0)
Requirement already satisfied: scipy>=0.19.1 in /shared-libs/python3.7/py/lib/python3.7/site-packages (from scikit-learn>=0.21.3->th-sklearn-json->teachablehub) (1.6.3)
WARNING: You are using pip version 21.1.2; however, version 21.1.3 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
from teachablehub.deployments.sklearn import TeachableDeployment
from teachablehub.clients import TeachableHubPredictAPI
# Setup TeachableHub
deployment = TeachableDeployment(
teachable="user/teachable",
environment="experiments",
deploy_key="your-deploy-key" # use the env var in case you want to hide them. https://docs.deepnote.com/environment/environment-variables
)
teachable = TeachableHubPredictAPI(
teachable="user/teachable",
environment="experiments",
serving_key="your-serving-key", # use the env var in case you want to hide them. https://docs.deepnote.com/environment/environment-variables
)
# Setup your other services and tools (w&b and etc.) below
# ...
from sklearn import svm
from sklearn import datasets
clf = svm.SVC(gamma='scale', probability=True)
iris = datasets.load_iris()
X, y = iris.data, iris.target
clf.fit(X, y)
new_model = clf
deployment.model(new_model)
deployment.classes({"0": "Setosa", "1": "Versicolour", "2": "Virginica" })
# HTTP Request schema + validation
deployment.schema({
"features": {
"sepal_length": {"type": "float"},
"sepal_width": {"type": "float"},
"petal_length": {"type": "float"},
"petal_width": {"type": "float"},
},
"ndarray": [[
"sepal_length",
"sepal_width",
"petal_length",
"petal_width",
]]
})
deployment.samples(
ndarray=[X[0]],
features={"sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2 }
)
import platform
from sklearn import __version__ as sklearn_version
deployment.context({
"author": "Marian Ignev",
"github_commit": "9e91a9d16eecf9e44935788ea777549de4377408",
"dataset_version": "777549de4377408",
"notebook": "https://deepnote.com/project/TeachableHub-dw89hjdw92m6fXJFLzxxCpA/%2Fgetting-started-sklearn.ipynb",
"training_params": {},
"scikit-learn": sklearn_version,
"python": platform.python_version(),
"local_hostname": platform.node(),
"os_info": platform.version()
})
deployment.deploy(
summary="Automated deployment from DeepNote Notebook",
activate=True # make it latest automatically
)
teachable.predict([X[0]])