def lm(x, y, alpha=ALPHA):
 x_is_date = _isdate(x.iloc[0])
 if x_is_date:
  x = np.array([i.toordinal() for i in x])
 X = sm.add_constant(x)
 fit = sm.OLS(y, X).fit()
 (prstd, iv_l, iv_u) = wls_prediction_std(fit)
 (_, summary_values, summary_names) = summary_table(fit, alpha=alpha)
 df = pd.DataFrame(summary_values, columns=map(_snakify, summary_names))
 fittedvalues = df[u'predicted_value'].values
 predict_mean_ci_low = df[u'mean_ci_95%_low'].values
 predict_mean_ci_upp = df[u'mean_ci_95%_upp'].values
 predict_ci_low = df[u'predict_ci_95%_low'].values
 predict_ci_upp = df[u'predict_ci_95%_upp'].values
 if x_is_date:
  x = [Timestamp.fromordinal(int(i)) for i in x]
 return (x, fittedvalues, predict_mean_ci_low, predict_mean_ci_upp)

def lm ( x , y , alpha = ALPHA ) : x_is_date = _isdate ( x . iloc [ 0 ] ) if x_is_date : x = np . array ( [ i . toordinal ( ) for i in x ] ) X = sm . add_constant ( x ) fit = sm . OLS ( y , X ) . fit ( ) ( prstd , iv_l , iv_u ) = wls_prediction_std ( fit ) ( _ , summary_values , summary_names ) = summary_table ( fit , alpha = alpha ) df = pd . DataFrame ( summary_values , columns = map ( _snakify , summary_names ) ) fittedvalues = df [ u'predicted_value' ] . values predict_mean_ci_low = df [ u'mean_ci_95%_low' ] . values predict_mean_ci_upp = df [ u'mean_ci_95%_upp' ] . values predict_ci_low = df [ u'predict_ci_95%_low' ] . values predict_ci_upp = df [ u'predict_ci_95%_upp' ] . values if x_is_date : x = [ Timestamp . fromordinal ( int ( i ) ) for i in x ] return ( x , fittedvalues , predict_mean_ci_low , predict_mean_ci_upp )
fits an ols from statsmodels .