value error encountered when using sklearn for linear regression

Ironkey :

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 :)

Catalina Chircu :

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)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=360590&siteId=1