When I run this code I am getting an error. I am a newbie. Please help me. Thanks in advance.
from sklearn import linear_model
from sklearn.metrics import mean_squared_error, r2_score
import pandas as pd
df_percentage = (pd.read_csv("Data.csv", sep=';'))
print(df_percentage)
x=df_percentage.Percentage
y=df_percentage.Peakintensity
x = x.reshape(-1,1)
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2)
model = linear_model.LinearRegression()
m1 = model.fit(x_train,y_train)
print(m1)
y_pred = model.predict(x_test)
print ('Coefficients: ', model.coef_)
print ('Intercept: ',model.intercept_)
CodePudding user response:
x = x.values.reshape(-1,1)
will fix it.
see: https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.Series.reshape.html