1

我是机器学习世界的新手,正在从事一个项目,在该项目中我使用 SKlearn 训练了一个欺诈检测模型。我正在以这种方式训练模型:

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)
}

# 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)
        scores_pred = clf.negative_outlier_factor_
    else:
        clf.fit(X)
        scores_pred = clf.decision_function(X)
        y_pred = clf.predict(X)

    # 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 ))

它返回以下输出:

Isolation Forest:7
0.93
         precision    recall  f1-score   support

      0       0.97      0.96      0.96        95
      1       0.33      0.40      0.36         5

avg / total   0.94      0.93      0.93       100

Local Outlier Factor:9
0.91
             precision    recall  f1-score   support

          0       0.96      0.95      0.95        95
          1       0.17      0.20      0.18         5

avg / total       0.92      0.91      0.91       100

现在令人困惑的部分是它的部署,经过很多努力,我决定在烧瓶网络服务的帮助下部署和服务它,但不明白如何将输入传递给我的predict方法以获得预测?

有没有以错误的方式做某事?

如何predict在这里将输入传递给我的方法?

请帮帮我!非常感谢任何有关其部署到谷歌云的分步指南的资源。

提前致谢!

4

0 回答 0