1

I made an basic multiple linear regression model and ı wanted predict some values but ı took this warning

array=np.array([[26,1.5],[27,3]])
multiple_linear_regression.predict(array)


/Users/mali/anaconda3/lib/python3.11/site-packages/sklearn/base.py:464: UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names
  warnings.warn(
array([31926.2169    , 35070.62783243])

but code is worked but ı wondered what is that warning and how can ı fixed it?

1 Answer 1

0

You don't show it in your code but I'm guessing you have something like:

multiple_linear_regression = sklearn.linear_model.LinearRegression()
multiple_linear_regression.fit(df[["A"]], df[["B"]])

array=np.array([[26,1.5],[27,3]])
multiple_linear_regression.predict(array)

In which case, you are fitting the model in a way that keeps the DataFrame features. However, when you try to use the .predict() call, you are passing you are doing so with a structure that does not have the features present.

My suggestion is to not include the features in the original fit. You can do so by using the .values property

multiple_linear_regression = sklearn.linear_model.LinearRegression()
multiple_linear_regression.fit(df[["A"]].values, df[["B"]].values)

array=np.array([[26,1.5],[27,3]])
multiple_linear_regression.predict(array)
Sign up to request clarification or add additional context in comments.

Comments

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.