python
runtime_error
ai_generated
true
sklearn.exceptions.NotFittedError: 此 StandardScaler 实例尚未拟合。请先使用适当参数调用 'fit'。
sklearn.exceptions.NotFittedError: This StandardScaler instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator.
ID: python/sklearn-notfitted-error
80%修复率
90%置信度
0证据数
2024-02-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
在 fit 之前调用 transform/predict,或在管道中使用了未拟合的新估计器。
English
Calling transform/predict on an estimator before fit, or using a fresh estimator inside a pipeline instead of the fitted one.
解决方案
-
95% 成功率
scaler = StandardScaler().fit(X_train); X_test_s = scaler.transform(X_test)
-
95% 成功率
Wrap in Pipeline([('scaler', StandardScaler()), ('clf', LogisticRegression())]) so fit handles all steps
无效尝试
常见但无效的做法:
-
90% 失败
Same error, no fitted state
-
60% 失败
StandardScaler supports partial_fit but requires correct usage; often yields wrong stats