I'm new to Machine learning world and I have build a model using SKlearn by implementing the Isolation Forest and Local Outlier Factor classifiers.Now I'm working on the deployment of this model. I have exported the trained model to a Pickle file as:
from sklearn.metrics import classification_report, accuracy_score
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor
# define a random state
state = 1
# define the outlier detection method
classifiers = {
"Isolation Forest": IsolationForest(max_samples=len(X),
contamination=outlier_fraction,
random_state=state),
"Local Outlier Factor": LocalOutlierFactor(
n_neighbors = 20,
contamination = outlier_fraction)
}
from sklearn.externals import joblib
# fit the model
n_outliers = len(Fraud)
for i, (clf_name, clf) in enumerate(classifiers.items()):
# fit te data and tag outliers
if clf_name == "Local Outlier Factor":
y_pred = clf.fit_predict(X)
# Export the classifier to a file
joblib.dump(clf, 'model.joblib')
scores_pred = clf.negative_outlier_factor_
else:
clf.fit(X)
scores_pred = clf.decision_function(X)
y_pred = clf.predict(X)
# Export the classifier to a file
joblib.dump(clf, 'model.joblib')
# Reshape the prediction values to 0 for valid and 1 for fraudulent
y_pred[y_pred == 1] = 0
y_pred[y_pred == -1] = 1
n_errors = (y_pred != Y).sum()
# run classification metrics
print('{}:{}'.format(clf_name, n_errors))
print(accuracy_score(Y, y_pred ))
print(classification_report(Y, y_pred ))
Then I have created a storage bucket on Google Cloud and upload this model.joblib
to file to that bucket.
After that when I have try to create a ML Engine version it throws an error as:
Field: version.deployment_uri Error: Deployment directory gs://fdmlmodel_01/ is expected to contain exactly one of: [saved_model.pb, saved_model.pbtxt].
As i'm new to machine learning, how can i solve this issue or is there a proper step by step tutorial to deploy this model to Google Cloud ML Engine.
Help me, please!
Thanks in advance!
Please refer this docs and official docs to build and deploy scikit-learn model in cloud-ml.
To Save as pickle file,