title: How to split data to train and test ? Cross validation possible ? M-estimation or OLS?
body: <p>I have 26 observations to apply a simple linear regression but when I split the data to 70% for train and 30% for test data usually the results for the test data (R squared / P value) are not good. Is it because the samples for the test are too small ? 8 or 9 observation are not enough ? What should I do ? no random state so he the algorithm choose the data randomly
  Also wondering how to choose between OLS and M-estimation(which is more resistant to outliers which I have on my data check below because Variable B is impacted by other variables except A) to apply for my dataset.
  this is the code I have done so far and looking to do cross validation in the train data.
  Is it possible according to the number of observations I have?</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  import statsmodels.api as sm
  from scipy import stats
  data = pd.read_excel("C:\\Users\\AchourAh\\Desktop\\PL32_PMM_03_09_2018_SP_Level.xlsx",'Sheet1') 
  data1 = data.fillna(0) #Replace null values of the whole dataset with 0
  print(data1)
  X = data1.iloc[0:len(data1),1].values.reshape(-1, 1) 
  Y = data1.iloc[0:len(data1),2].values.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.33)
  from sklearn.linear_model import LinearRegression
  regressor = LinearRegression()
  regressor.fit(X_train, Y_train)
  plt.scatter(X_train, Y_train, color = 'red')
  plt.plot(X_train, regressor.predict(X_train), color = 'blue')
  plt.title('SP00114585')
  plt.xlabel('COP COR Quantity')
  plt.ylabel('PAUS Quantity')
  plt.show()
  plt.scatter(X_test, Y_test, color = 'red')
  plt.plot(X_train, regressor.predict(X_train), color = 'blue')
  plt.title('SP00114585')
  plt.xlabel('COP COR Quantity')
  plt.ylabel('PAUS Quantity')
  plt.show()
  X2 = sm.add_constant(X_train)
  est = sm.OLS(Y_train, X2)
  est2 = est.fit()
  print(est2.summary())
  X3 = sm.add_constant(X_test)
  est3 = sm.OLS(Y_test, X3)
  est4 = est3.fit()
  print(est4.summary())
  </code></pre>
  
  <p>This is an example of the data I have and my goal is not to predict a good model but to describe the impact of variable A on B. Also when analyzing the whole data together results are always better than splitting the data</p>
  
  <pre><code>   Variable A   Variable B
        87.000    573.000
        90.000    99.000
       258.000    339.000
       180.000    618.000
             0    69.000
        90.000    621.000
        90.000    231.000
       210.000    345.000
       255.000    255.000
         0              0
       213.000    372.000
       405.000    405.000
       162.000    162.000
       405.000    405.000
             0    186.000
       105.000    252.000
       474.000    501.000
       531.000    531.000
       549.000    549.000
       525.000    525.000
       360.000    660.000
       546.000    546.000
       645.000    645.000
       561.000    600.000
       978.000    1.104.000
       960.000    960.000
  </code></pre>
  
  <p>Also, plotted the results using SKlearn and analyzing the results based on the statsmodels. Can I assume that the plotted results are represented by the values due to statsmodels or there is something to change in the code ?</p>