import statsmodels.api as sm
def fit_line2(x, y):
"""Return slope, intercept of best fit line."""
X = sm.add_constant(x)
model = sm.OLS(y, X, missing='drop') # ignores entires where x or y is NaN
fit = model.fit()
return fit.params[1], fit.params[0] # could also return stderr in each via fit.bse
x = diabetes_X_test[:,0]
y = diabetes_y_test
m, c = fit_line2(x, y)
yy = [m * x[i] + c for i in range(len(x))]
plt.plot(x,y,'bo',x,yy)