gpt4 book ai didi

python - 使用 JamesSteinEncoder 时出现 "is_categorical is deprecated"错误

转载 作者:行者123 更新时间:2023-12-04 09:00:25 25 4
gpt4 key购买 nike

尝试安装 JamesSteinEncoder 时出现以下错误

encoder = JamesSteinEncoder().fit(X, y)

FutureWarning: is_categorical is deprecated and will be removed in a future version. Use is_categorical_dtype instead
elif pd.api.types.is_categorical(cols):

sklearn.__version__ : '0.23.2'
代码:
speed = ['DE','AU','US','FR','GB','KR','AU']
lifespan = [1, 0, 1, 1, 1, 0, 1]
life = [1, 1, 0, 1, 1, 0, np.nan]
index = ['snail', 'pig', 'elephant',
'rabbit', 'giraffe', 'coyote', 'horse']
df = pd.DataFrame({'speed': speed,
'lifespan': lifespan,
'life':life}, index=index)

df['speed']= df['speed'].astype('category')

from category_encoders import JamesSteinEncoder
X = df['speed']
y = df['lifespan']
enc = JamesSteinEncoder().fit(X, y)

/Users/*/opt/anaconda3/envs/proj/lib/python3.7/site-packages/category_encoders/utils.py:21: FutureWarning: is_categorical is deprecated and will be removed in a future version. Use is_categorical_dtype instead
elif pd.api.types.is_categorical(cols):

最佳答案

python的好处是你可以自己更改源代码。
我做到了,你也可以这样做:
用vim打开文件,/Users/*/opt/anaconda3/envs/proj/lib/python3.7/sitepackages/category_encoders/utils.py
转到第 21 行
改变
elif pd.api.types.is_categorical(cols):

elif pd.api.types.is_categorical_dtype(cols):
保存更改并退出 vim。
你已经完成了。
现在您已经为自己进行了更改,您将不会再收到此警告。

关于python - 使用 JamesSteinEncoder 时出现 "is_categorical is deprecated"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63589556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com