AttributeError: 'Series' object has no attribute 'reshape'

当代码运行到下面位置时:


ss_y=preprocessing.StandardScaler()
y=ss_y.fit_transform(y.reshape(-1,1))

报错:

Traceback (most recent call last):
  File "D:/machineLearning/demo3.py", line 67, in
    y=ss_y.fit_transform(y.reshape(-1,1))
  File "D:\Anaconda\lib\site-packages\pandas\core\generic.py", line 4372, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'reshape'

出错的原因是Series没有reshape这个接口,而Series有values这个接口,

解决的办法是y调用values接口,然后调用values中的reshape方法。

如:

ss_y=preprocessing.StandardScaler()
ss_log_y=preprocessing.StandardScaler()
X=ss_X.fit_transform(X)
y=ss_y.fit_transform(y.values.reshape(-1,1))

就可正常运行。

 

 

 

你可能感兴趣的:(debug)