【发布时间】:2020-08-31 21:37:15
【问题描述】:
当尝试使用 SKlearn 从经过训练的 StackingClassifier 检索系数时,它会显示 coefs_ 不存在。这意味着它认为它还没有被训练。我能够证明它已经通过在外部管道(获得正确的输出)和堆栈中的单个模型(说它还没有拟合)上调用 predict 进行了训练。我怎样才能得到这个模型的权重?
>>> a.named_steps['stackingclassifier'].named_estimators['mlp'].coefs_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'MLPClassifier' object has no attribute 'coefs_'
>>> a.predict_proba([X])
array([[5.69909808e-05, 1.95316594e-05, 1.06791916e-08, 7.99719342e-06,
4.16570282e-04, 9.78260604e-04, 7.43104846e-05, 1.15379667e-08,
9.42032134e-06, 9.98103331e-01, 1.21851461e-04, 1.61161070e-04,
1.97925333e-05, 3.46306792e-07, 3.04140522e-05]])
>>> a.named_steps['stackingclassifier'].named_estimators['mlp'].predict_proba([X])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jbiloki/anaconda3/envs/py36/lib/python3.6/site-packages/sklearn/neural_network/_multilayer_perceptron.py", line 1104, in predict_proba
check_is_fitted(self)
File "/home/jbiloki/anaconda3/envs/py36/lib/python3.6/site-packages/sklearn/utils/validation.py", line 73, in inner_f
return f(**kwargs)
File "/home/jbiloki/anaconda3/envs/py36/lib/python3.6/site-packages/sklearn/utils/validation.py", line 1020, in check_is_fitted
raise NotFittedError(msg % {'name': type(estimator).__name__})
sklearn.exceptions.NotFittedError: This MLPClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.```
【问题讨论】:
标签: python machine-learning scikit-learn