I am trying to understand what is wrong with the code below. I know that the Y
variable is 1D
array and expected to be 2D
array and need to reshape the structure but that code was working previously fine with a warning.
# Importing the librariesimport numpy as npimport matplotlib.pyplot as pltimport pandas as pd# Importing the datasetdataset = pd.read_csv('Position_Salaries.csv')X = dataset.iloc[:, 1:2].valuesy = dataset.iloc[:, 2].values# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y)
ValueError: Expected 2D array, got a 1D array instead:
array=[ 45000. 50000. 60000. 80000. 110000. 150000. 200000. 300000.500000. 1000000.].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.