I am trying to implement linear regression but when i run the code I get this error ValueError: Found input variables with inconsistent numbers of samples: [1, 20] in line-->linear.fit(x_train1,y_train1) [data type of x_train1,x is series & y_ is series].
I changed x=dataset.iloc[:,:-1] datatype of x_train, x changes to dataframe(y_ is still series) and it works correctly
So why it only works when x is dataframe eventhough y is still series??
import pandas as pd
import numpy as np
import matplotlib.pyplot
dataset=pd.read_csv('Salary_Data.csv')
x=dataset.iloc[:,0]
y=dataset.iloc[:,1]
from sklearn.model_selection import train_test_split
x_train1,x_test1,y_train1,y_test1=
train_test_split(x,y,test_size=1/3,random_state=0)
#implementing simple linear regression
from sklearn.linear_model import LinearRegression
linear=LinearRegression()
linear.fit(x_train1,y_train1)
y_pred=linear.predict(x_test1)