0

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?

1 Answer 1

2

You can try to change x to DataFrame rather than Series.

x = df[['A']]
y = df['B']
Sign up to request clarification or add additional context in comments.

3 Comments

I think that worked, whats the difference between dataframe and series?
@ViB row/column in DataFrame is a Series, DataFrame can be 2D array while Series is 1D.
@ViB Locating with list of label is to subset the DataFrame, here you can take df[['A']] as x = df[['a', 'b', 'c']] which mean you want to use feature a, b, c which is columns in DataFrame to predict target B.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.