scikit-learn - 升级的 sklearn 使我之前的 onehotencoder 无法转换
问题描述
我将我以前的一个 ml 模型存储到 pickle 中,并计划稍后将其用于生产。
在很长一段时间内一切正常。几个月后,我升级了我的 sklearn,现在我加载它我收到了这个警告......
> c:\programdata\miniconda3\lib\site-packages\sklearn\base.py:318:
> UserWarning: Trying to unpickle estimator OneHotEncoder from version
> 0.20.1 when using version 0.22.2.post1. This might lead to breaking code or invalid results. Use at your own risk. UserWarning)
当我将它用于转换时,我收到了这个错误:
model_pipeline["ohe"].transform(df)
错误说:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-72436472fbb4> in <module>
----> 1 model_pipeline["ohe"].transform(df_merge[['CATEGORY']][:])
c:\programdata\miniconda3\lib\site-packages\sklearn\preprocessing\_encoders.py in transform(self, X)
392 n_samples, n_features = X_int.shape
393
--> 394 if self.drop is not None:
395 to_drop = self.drop_idx_.reshape(1, -1)
396
AttributeError: 'OneHotEncoder' object has no attribute 'drop'
这是模型管道的训练非常昂贵。我有什么可以在不重新训练所有内容的情况下修复这个模型管道的吗?谢谢!
解决方案
我也遇到了同样的问题。在我的情况下,这是因为尝试加载和使用我用以前版本的 scikit-learn 创建的编码器。当我重新创建编码器并保存时,加载后的问题消失了。
推荐阅读
- jsp - Jsp 在第 9 行和第 12 行返回错误:javax.servlet.jsp.PageContext 无法解析为类型
- html - Vue.js html2canvas 正在捕获黑框
- java - 在请求正文中发送 MultipartFile 文件以及邮递员中的其他数据
- tensorflow-lite - jetson nano install tflite_runtime 2.5.0 不支持 RandomStandardNormal op 怎么了?
- npm - 带有逻辑运算符的无服务器框架选择活动
- scikit-learn - scikit-learn 的 MLPRegressor 的有界输出
- python - 字典操作
- spring - 无法从存储库中读取
- php - Yii2 JWT 401 未经授权
- java - PLS-00306:número o tipos de argumentos erróneos al llamar a 'RESTAR_SERVICIO