训练了模型,但是如何手动预测新实例?

时间:2019-03-05 03:59:00

标签: python-3.x machine-learning

我有这个脚本来预测梯度提升算法。

app.post("/Login", passport.authenticate("local", {
  successRedirect: "/User",
  failureRedirect: "/Login",
  failureFlash: true,
  successFlash: true,
}));

我现在将如何手动测试此模型的新数组值的预测?假设我要预测[12,44,0]数组的结果。请告知。

1 个答案:

答案 0 :(得分:0)

predict函数接受形状数组(n_samples,n_features)。我猜你是n_features=3,因此:

print('Your prediction for [12,44,0] is', gb_clf.predict([[12,44,0]])

示例:

from sklearn.datasets import make_hastie_10_2
from sklearn.ensemble import GradientBoostingClassifier

X, y = make_hastie_10_2(random_state=0) # has 10 features
X_train, X_test = X[:2000], X[2000:]
y_train, y_test = y[:2000], y[2000:]

clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0, max_depth=1, random_state=0).fit(X_train, y_train)
sample = [list(range(10))] # we provide 10 features for prediction
print('Prediction:', clf.predict(sample))