Python不推荐使用警告:在0.17中不推荐将1d数组作为数据传递,并将在0.19中引发ValueError
基于我前面的问题,我正在将数据帧中的特定列重新缩放为0到1之间Python不推荐使用警告:在0.17中不推荐将1d数组作为数据传递,并将在0.19中引发ValueError,python,pandas,scikit-learn,deprecation-warning,Python,Pandas,Scikit Learn,Deprecation Warning,基于我前面的问题,我正在将数据帧中的特定列重新缩放为0到1之间 scaler = preprocessing.MinMaxScaler(feature_range=(0,1)) email['scaled_quantity'] = scaler.fit_transform(email['Quantity']) 不幸的是,我得到了这个错误 DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will ra
scaler = preprocessing.MinMaxScaler(feature_range=(0,1))
email['scaled_quantity'] = scaler.fit_transform(email['Quantity'])
不幸的是,我得到了这个错误
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning)
@Grr建议我将缩放应用于整个数据帧,但这不是一个选项。我需要按原样维护这些列,只想添加新的附加缩放列
我如何解决这个折旧错误?怎么办
scaler.fit_transform(email[['Quantity']])
而不是
scaler.fit_transform(email['Quantity'])
演示:我使用了上一个问题中的示例数据集:
In [56]: scaler.fit_transform(df[['Event_Counts']])
Out[56]:
array([[ 0.99722347],
[ 1. ],
[ 0. ]])
注意-它生成了一个形状为(3,1)
的数组,而不是(3,)
作为新专栏:
In [58]: df['scaled_event_counts'] = scaler.fit_transform(df[['Event_Counts']])
In [59]: df
Out[59]:
Date Event_Counts Category_A Category_B scaled_event_counts
0 20170401 982457 0 1 0.997223
1 20170402 982754 1 0 1.000000
2 20170402 875786 0 1 0.000000
做什么
scaler.fit_transform(email[['Quantity']])
而不是
scaler.fit_transform(email['Quantity'])
演示:我使用了上一个问题中的示例数据集:
In [56]: scaler.fit_transform(df[['Event_Counts']])
Out[56]:
array([[ 0.99722347],
[ 1. ],
[ 0. ]])
注意-它生成了一个形状为(3,1)
的数组,而不是(3,)
作为新专栏:
In [58]: df['scaled_event_counts'] = scaler.fit_transform(df[['Event_Counts']])
In [59]: df
Out[59]:
Date Event_Counts Category_A Category_B scaled_event_counts
0 20170401 982457 0 1 0.997223
1 20170402 982754 1 0 1.000000
2 20170402 875786 0 1 0.000000
非常感谢。你介意给我解释一下区别吗?@jeangelj只是想解释一下区别。若你们传递一个一维数组,那个么它会在模型中产生一个关于如何解释它的歧义。将其作为一个样本[1,n_个特征],或将其作为多个样本,每个样本具有一个特征[n_个样本,1]。希望这能让事情变得清楚谢谢你;你介意给我解释一下区别吗?@jeangelj只是想解释一下区别。若你们传递一个一维数组,那个么它会在模型中产生一个关于如何解释它的歧义。将其作为一个样本[1,n_个特征],或将其作为多个样本,每个样本具有一个特征[n_个样本,1]。希望这能说明问题