python - 属性错误: 'ColumnTransformer' object has no attribute '_name_to_fitted_passthrough'

标签 python pandas scikit-learn streamlit scikit-learn-pipeline

我正在预测 IPL 比赛获胜概率。使用 Streamlit 部署模型时,它显示此错误:

AttributeError:  'ColumnTransformer' object has no attribute '_name_to_fitted_passthrough'

这是我的代码:

from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder

trf = ColumnTransformer([('trf',OneHotEncoder(sparse=False,drop='first'), 
['batting_team','bowling_team','city'])],remainder='passthrough')

管道代码

pipe = Pipeline(steps=[
('step1',trf),
('step2',LogisticRegression(solver='liblinear'))])

最佳答案

使用构建和保存模型时查看环境中 sklearn 的版本

print(sklearn.__version__)

在使用相同方法加载模型的环境中执行相同的操作。

可能它们不一样。 希望这有帮助!

关于python - 属性错误: 'ColumnTransformer' object has no attribute '_name_to_fitted_passthrough' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75462901/

相关文章:

python - 如何在 scikit-learn 中正确执行交叉验证?

python - 如何获得高斯朴素贝叶斯中的特征重要性

python - 类属性显然没有继承

python - 是否有 python 方法来验证文件或 URL 的存在?

python - 无法为 prange 中的数组赋值

python - 如何在 Pandas 数据框的每一行上使用 .rolling()?

python - 如何在 Django REST 框架中返回自定义 JSON

python - 为什么将 pandas groupby 对象重新转换为数据框以写入 Excel?

不同 DataFrame 并排的 Pandas 箱线图

python - 如何在多类分类的 light gbm python 中编写自定义 F1 分数指标