【发布时间】:2018-04-20 13:24:13
【问题描述】:
我是机器学习领域的新手,我通过实施 Isolation Forest 和 Local Outlier Factor 分类器使用 SKlearn 构建了一个模型。现在我正在研究这个模型的部署。我已将训练好的模型导出为 Pickle 文件:
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 ))
然后我在 Google Cloud 上创建了一个存储桶并将此 model.joblib 上传到该存储桶的文件。
之后,当我尝试创建 ML Engine 版本时,它会引发错误:
字段:version.deployment_uri 错误:部署目录 gs://fdmlmodel_01/ 应包含以下项之一:[saved_model.pb, saved_model.pbtxt]。
由于我是机器学习的新手,我该如何解决这个问题,或者是否有适当的分步教程将此模型部署到 Google Cloud ML Engine。
请帮帮我!
提前致谢!
【问题讨论】:
-
查看stackoverflow.com/q/43384964/869951,请报告问题是否已解决。
标签: python machine-learning scikit-learn google-cloud-platform pickle