Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python不推荐使用警告:在0.17中不推荐将1d数组作为数据传递,并将在0.19中引发ValueError_Python_Pandas_Scikit Learn_Deprecation Warning - Fatal编程技术网

Python不推荐使用警告:在0.17中不推荐将1d数组作为数据传递,并将在0.19中引发ValueError

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

基于我前面的问题,我正在将数据帧中的特定列重新缩放为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 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]。希望这能说明问题