-
Create an account at Libnosis.com
-
Set the following environment variables so that you can call the
package
function on your trained/partially trained/untrained model:export BRAINIAC_CLIENT_USERNAME="username" export BRAINIAC_CLIENT_PASSWORD="password"
-
Install
brainiac_client
for python withpip install --user brainiac_client --upgrade
-
Pass the model into the package function, with a project name. An example with a model to predict the housing prices in Boston is shown below.
# ############################################################################# # Import necessary libraries import numpy as np from sklearn import ensemble from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.utils import shuffle from typing import Dict from brainiac_client.scientist import package # ############################################################################# # Load data boston = datasets.load_boston() X, y = shuffle(boston.data, boston.target, random_state=13) X = X.astype(np.float32) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1) print("train => ({},{})".format(np.shape(X_train), np.shape(y_train))) print("test => ({},{})".format(np.shape(X_test), np.shape(y_test))) # ############################################################################# # Fit regression model params = { 'n_estimators': 500, 'max_depth': 4, 'min_samples_split': 2, 'learning_rate': 0.01, 'loss': 'ls' } clf = ensemble.GradientBoostingRegressor(**params) clf.fit(X_train, y_train) # ############################################################################# # Create a wrapper object to control inputs class HousingModel: def train(self, body: Dict): clf.fit(body["x"], body["y"]) def score(self, body: Dict): return clf.score(body["x"], body["y"]) def predict(self, body: Dict): return clf.predict(body["x"]) # ############################################################################# # Upload Model to Brainiac model = HousingModel() response = package(model, "housing") print("Response Status Code:", response.status_code) # Check that the upload succeeded
-
Please note that that housing model can have any function the data scientist wants. The only requirement is that it takes in a dictionary called body. This dictionary's only requirement is that it must be protobuf serializable. To be more precise, the body is a
google.protobuf.Struct
. In a future version, it will just be a regular dictionary. -
The data scientist can access events related to his models at
libnosis.com/api/model/event
. More types of events will be collected in the future and the data scientists will be given a way to decide what analytics to collect later. If the analytics are an important issue to you and you would like to have a chat about it, please let us know. 😄
-
Create an account at Libnosis.com
-
Set the following environment variables so that you can call the
package
function on your trained/partially trained/untrained model:export BRAINIAC_CLIENT_USERNAME="username" export BRAINIAC_CLIENT_PASSWORD="password"
-
Install
brainiac_client
for python withpip install --user brainiac_client --upgrade
-
Create a brainiac client for the project you would like to use. Then you can call whatever method is defined by the data scientist on that client. An example for how to use the housing model created by the data scientist above is shown below.
# ############################################################################# # Import libraries from brainiac_client.client import BrainiacClient import numpy as np # ############################################################################# # Load Data testData = np.load("./test_data.npz") x_test = testData.get("X_test") y_test = testData.get("y_test") # ############################################################################# # Use Brainiac brainiac = BrainiacClient() try: model = brainiac.get_model_client("suyogsoti", "housing") response = model.score({"x": x_test.tolist(), "y": y_test.tolist()}) except Exception as e: print("EXCEPTION:", e)
-
Note:
get_model_client
does make a network request in an attempt to cache the model. -
The response for the function actually called,
score
in this case, is defined with the following protobuf structure.message Status { int32 status_code = 1; string status_reason = 2; } message BrainiacResponse { Status status = 1; google.protobuf.Struct body = 2; }