I have two variables A and B in a dataframe. When i try this:
x=df.['A']
y=df.['B']
M = LinearRegression()
M.fit(A,B)
I get the following error
Expected 2D array, got 1D array instead:
array=[86. 0. 86. ... 0. 0. 0.].
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.
Although when i try to apply the reshape as suggested, i got a "'Series' object has no attribute 'reshape'"
How can I get around this?
CodePudding user response:
You can try to change x
to DataFrame rather than Series.
x = df[['A']]
y = df['B']