1
m = np.array([[1,5,3,6,10,20]])
c = np.array([[100,500,300,600,1000,2000]])

model = LinearRegression()
model.fit(m,c)

I get the error when trying to make the prediction.

model.predict([5])

If I add double brackets, it forces me to pass 6 inputs, but the idea is that it receives only one or as many as I want.

2
  • 1
    Why do you train a model, bit you predict from modelo? Is it a typo just here, or in your code, too? Please edit your post to clarify and remedy this. Commented Sep 23, 2022 at 12:13
  • Are you trying to predict c from m, or are you trying to make a linear model like y = mx + c? Commented Sep 23, 2022 at 17:17

1 Answer 1

1

You trained the wrong model. You train 6 models, each with 6 features (and your dataset is only 1-point).

# should be this
m = np.array([[1,5,3,6,10,20]]).T
c = np.array([100,500,300,600,1000,2000])

model = LinearRegression()
model.fit(m,c)

modelo.predict([[5]])
# array([500])
Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot,it didn't work this way modelo.predict([5]) I had to add double brackets.
I have seen a lot of theory, and the truth is that I have not understood your solution. Could you recommend a reading that will clarify these doubts? <3

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.