title: Sklearn.linear_model : ValueError: Found input variables with inconsistent numbers of samples: [1, 20]
body: <p>I am trying to implement linear regression but when i run the code I get this error <code>ValueError: Found input variables with inconsistent numbers of samples: [1, 20] in line--&gt;linear.fit(x_train1,y_train1) [data type of x_train1,x is series &amp; y_ is series]</code>. </p>
  
  <p>I changed <code>x=dataset.iloc[:,:-1]</code> datatype of x_train, <code>x</code> changes to dataframe(<code>y_</code> is still series) and it works correctly</p>
  
  <p>So why it only works when <code>x</code> is dataframe eventhough <code>y</code> is still series??</p>
  
  <pre><code>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)
  </code></pre>