本文主要是介绍jupyter notebook 报错:TypeError: __init__() got an unexpected keyword argument ‘categorical_features‘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 问题
- 解决
- 参考
问题
报错代码:
# 创建虚拟变量
onehotencoder = OneHotEncoder(categorical_features = [0])
X = onehotencoder.fit_transform(X).toarray()
labelencoder_Y = LabelEncoder()
Y = labelencoder_Y.fit_transform(Y)
解决
新版的sklearn升级了函数接口,导致上述代码不可用。
# 创建虚拟变量
from sklearn.compose import ColumnTransformer
onehotencoder = ColumnTransformer([('encoder', OneHotEncoder(), [0])], remainder = 'passthrough')
X = onehotencoder.fit_transform(X)
labelencoder_Y = LabelEncoder()
Y = labelencoder_Y.fit_transform(Y)
参考
https://stackoverflow.com/questions/59476165/typeerror-init-got-an-unexpected-keyword-argument-categorical-features
这篇关于jupyter notebook 报错:TypeError: __init__() got an unexpected keyword argument ‘categorical_features‘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!