私は機械学習の世界に不慣れで、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
今混乱している部分は展開です。多くの苦労の後、フラスコWebサービスの助けを借りて展開して提供することにしましたが、ここでメソッドに入力を渡して予測を取得する方法がわかりませんか?
何か間違った方法で行われたことはありますか?
predict
ここでメソッドに入力を渡すにはどうすればよいですか?
お願い助けて!Google クラウドへの展開のステップバイステップ ガイドのリソースは非常に高く評価されます。
前もって感謝します!