【问题标题】:How do I call 'fit' appropriate arguments before using this estimator?在使用此估算器之前,如何调用“适合”适当的参数?
【发布时间】:2020-11-29 14:25:39
【问题描述】:
 # predict - Predict class labels for samples in X
 log_reg.predict(X_train).fit
 y_pred = log_reg.predict(X_train).fit

 # predict_proba - Probability estimates
 pred_proba = log_reg.predict_proba(X_train)

 # coef_ - Coefficient of the features in the decision function
 log_reg.coef_

NotFittedError:此 LogisticRegression 实例尚未拟合。在使用此估算器之前,使用适当的参数调用“fit”。

【问题讨论】:

  • 您需要先将模型拟合到训练集上,然后才能在测试集上进行预测。

标签: python python-3.x jupyter-notebook


【解决方案1】:
# fit classifier on train data
clf = log_reg.fit(X_train, y_train)
# predict on test data
y_pred = clf.predict(X_test)
# predict probabilities on test data
pred_proba = clf.predict_proba(X_test)
# coefficient of the features in the decision function
print(clf.coef_)

【讨论】:

  • 一旦我添加,我会得到错误:typerror:'list'对象不是可调用的 span>
猜你喜欢
  • 2022-11-07
  • 1970-01-01
  • 2019-10-05
  • 2020-04-14
  • 2018-12-26
  • 1970-01-01
  • 2015-07-21
  • 1970-01-01
  • 2020-03-28
相关资源
最近更新 更多