python - 使用 JamesSteinEncoder 时出现“is_categorical 已弃用”错误
问题描述
尝试适合 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。你完成了。现在您已经为自己进行了更改,您将不会再收到此警告。
推荐阅读
- c# - 使用使用 localhost 初始化的请求/响应时如何修复 MassTransit.EndpointNotFoundException?
- javascript - (Angular)Js - 如何简化承诺结果?
- csv - PayPal 自动完成付款的月度或周度报告
- javascript - 不断收到 Uncaught TypeError: Illegal invocation?
- vue.js - 使用 mock-axios-adapter 模拟 put 请求
- unity3d - 如果没有 ID,您如何处理根据语言可能具有不同值的下拉菜单?
- image-processing - 如果过滤器与正在执行卷积的图像本身相同,那么卷积层的输出是什么?
- sql - 需要根据总收入之和提取数据
- sql - 基于条件的最大和最小时间的 SQL 代码(输入/输出)
- php - 锚标记在 while 循环中仅应用一次