Google机器学习引擎deployment_uri错误 [英] Google Machine Learning Engine deployment_uri Error

查看:674
本文介绍了Google机器学习引擎deployment_uri错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是机器学习领域的新手,我已经通过实施隔离林本地异常因子分类器,使用SKlearn建立模型。现在我正在研究这个模型的部署。我已经将训练好的模型导出到Pickle文件中,如下所示:

  from sklearn.metrics从sklearn导入classification_report,accuracy_score 
.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor

#定义一个随机状态
state = 1

#定义异常值检测方法
classifiers = {
Isolation Forest:IsolationForest(max_samples = len(X),
contamination = outlier_fraction,
random_state = state),
本地异常因子: LocalOutlierFactor(
n_neighbors = 20,
contamination = outlier_fraction)
}
from sklearn.externals import joblib
#fit the model
n_outliers = len(Fraud )

在枚举(classifiers.items())中为i,(clf_name,clf):

#fit te数据和标记离群值
if clf_name == 本地异常因素:
y_pred = clf.fit_predict (X)
#将分类器导出到文件
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)
#将分类器导出到文件
joblib.dump(clf, 'model.joblib')

#将预测值重新整形为0代表有效,1代表欺诈性
y_pred [y_pred == 1] = 0
y_pred [y_pred == - 1] = 1

n_errors =(y_pred!= Y).sum()

#运行分类指标
print('{}:{}'。格式(clf_name,n_errors))
print(accuracy_score(Y,y_pred))
print(classification_report(Y,y_pred))

然后,我在Google Cloud上创建了一个存储分区,并将此 model.joblib 上传到该存储分区。
之后,当我尝试创建一个ML引擎版本时,它会抛出一个错误:


字段:version.deployment_uri错误:部署目录gs:// fdmlmodel_01 /预计完全包含以下之一:[saved_model.pb,saved_model.pbtxt]。

由于我是机器学习新手,我该如何解决这个问题,或者是否有适当的一步一步的教程,将此模型部署到Google Cloud ML引擎中。



帮助 文档和官方 docs 在云-ml中构建和部署scikit-learn模型。

保存为pickle文件,

  import pickle 
with op en('model.pkl','wb')as model_file:
pickle.dump(classifier,model_file)


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,

import pickle
with open('model.pkl', 'wb') as model_file:
pickle.dump(classifier, model_file)

这篇关于Google机器学习引擎deployment_uri错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆