Я пытаюсь изменить свое значение y_train, чтобы я мог поместить его в StandardScaler и затем использовать его для инвертирования преобразованного значения, полученного из предсказанного значения x_values.
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
dataset = pd.read_csv('/home/ritvik/Desktop/dataset_for_hackathon/wheat-2014-supervised.csv')
dataset = dataset.drop(['CountyName','State','Date'],axis = 1)
df_x = dataset.iloc[:,0:]
df_x = df_x.fillna(df_x.mean())
df_y = dataset.iloc[:,22]
x_train,x_test,y_train,y_test = train_test_split(df_x,df_y,test_size = 0.2)
scaler_x = StandardScaler()
scaler_y = StandardScaler()
scaler_x.fit(x_train)
x_train = scaler_x.transform(x_train)
#this returns the value (146039,) clearly a one dimensional array
print(y_train.shape)
y_train = np.reshape(y_train,(-1,1)) # <-Throws an error saying that the data should be one dimensional
y_train = scaler_y.fit(y_train)
regressor = LinearRegression()
regressor.fit(x_train,y_train)
predicted = regressor.predict(scaler_x.transform(x_test))
print(pd.DataFrame(scaler_y.inverse_transform(predicted),y_test))
Это стек ошибок
File "<ipython-input-53-f4ca71947844>", line 1, in <module>
y_train = np.reshape(y_train,(-1,1))
File "<__array_function__ internals>", line 6, in reshape
File "/home/ritvik/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 301, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
File "/home/ritvik/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 58, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/home/ritvik/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 51, in _wrapit
result = wrap(result)
File "/home/ritvik/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py", line 1999, in __array_wrap__
return self._constructor(result, **d).__finalize__(self)
File "/home/ritvik/anaconda3/lib/python3.7/site-packages/pandas/core/series.py", line 311, in __init__
data = sanitize_array(data, index, dtype, copy, raise_cast_failure=True)
File "/home/ritvik/anaconda3/lib/python3.7/site-packages/pandas/core/internals/construction.py", line 729, in sanitize_array
raise Exception("Data must be 1-dimensional")
Exception: Data must be 1-dimensional
Я понятия не имею, где я иду не так.