为什么scikitlearn StandardScaler不支持保留操作?

2024-10-03 04:35:39 发布

您现在位置:Python中文网/ 问答频道 /正文

当我想做机器学习项目时,我想将我的输入扩展到(0,1)

我使用sklearn函数来实现这一点,比如StandScaler() 但我发现,一旦我的数据包含nan,fit_transform()将失败,如下所示:

ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

但我认为有某种需要,希望保留nan,并在其他非nan数据中进行标准缩放

为什么我们不支持这一点?有什么方法可以使用它吗


Tags: or数据项目函数机器inputtransformsklearn
1条回答
网友
1楼 · 发布于 2024-10-03 04:35:39

最可能的情况是,您使用的是旧版(即0.20之前的版本)的scikit learn。该问题确实在v0.20中得到解决;从change log开始:

Major Feature: NaN values are ignored and handled in the following preprocessing methods: preprocessing.MaxAbsScaler, preprocessing.MinMaxScaler, preprocessing.RobustScaler, preprocessing.StandardScaler, preprocessing.PowerTransformer, preprocessing.QuantileTransformer classes and preprocessing.maxabs_scale, preprocessing.minmax_scale, preprocessing.robust_scale, preprocessing.scale, preprocessing.power_transform, preprocessing.quantile_transform functions

另请参见已关闭的Github问题#10404和相应的合并请求#11206

因此,只要将您的scikit learn升级到最新版本,您就可以了,也就是说,在这样的预处理过程中,NaN值确实会被忽略

相关问题 更多 >