2

I am working with linear regression (SKlearn) and when predicting a value I am getting an error. I'm not sure what to do and have tried switching up the format in which I input the prediction value but so far I have drawn a blank.

Here's my code:

import pandas as pd import numpy as np from sklearn.linear_model import LinearRegression data = pd.read_csv("data.csv") print(data.head()) X = data['Machine Age (Months)'].values y = data['Mean Time Between Failure (Days)'].values X.shape # (30,) y.shape # (30,) X = [X] y = [y] model = LinearRegression() model.fit(X,y) prediction = model.predict([[30]]) 

when running this code i get this error:

matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 30 is different from 1) 

here's the data I'm importing (i made it a CSV file)

https://drive.google.com/file/d/10fEjJj2znOmRufq3cFuc0CB_t2HAgudI/view?usp=sharing

any help would be appreciated :)

8
  • 1
    remove this line: y = [y] Commented Mar 27, 2020 at 19:12
  • it just returned: ValueError: Found input variables with inconsistent numbers of samples: [1, 30] Commented Mar 27, 2020 at 19:13
  • 1
    im not sure if thats improvement Commented Mar 27, 2020 at 19:13
  • 1
    sure ill add it to the question Commented Mar 27, 2020 at 19:18
  • 2
    do you think passing X and y into numpy arrays and then reshaping them with (-1,1) would help? Commented Mar 27, 2020 at 19:24

1 Answer 1

4

I am not sure about your input for the prediction.

Try this:

import numpy as np X_test = np.array([[30]]) prediction = model.predict(X_test) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.