import numpy as np
filename = "diabetes.txt"
data = np.loadtxt(filename)
X = data.T[0:10]
Y = data.T[10]
X.shape
#import mpld3
#mpld3.enable_notebook()
#plt.rcParams['figure.figsize'] = [9.5,6]
import matplotlib.pyplot as plt
for i in range(10):
plt.subplot(1,2,2-(i+1)%2)
X_ = np.vstack([X[i], np.ones(len(X[i]))]).T
w1, w0 = np.linalg.lstsq(X_, Y, rcond=None)[0]
t = np.linspace(np.min(X[i]),np.max(X[i]),20)
plt.plot(X[i],Y,'.')
plt.plot(t, w1*t + w0, 'r')
if ((i+1)%2==0):
plt.show()
plt.plot(X[2],Y,'.')
plt.plot(t, w1*t + w0, 'r')
plt.show()
A = np.vstack([X, np.ones(len(X[i]))]).T
w=np.zeros(11)
w = np.linalg.lstsq(A, Y, rcond=None)[0]
Y_=np.matmul(A,w)
# t = np.linspace(np.min(X[i]),np.max(X[i]),20)
plt.plot(Y,Y_,'.')
plt.plot([-130, 200],[-130, 200],'r-')
plt.show()