# coding: utf-8
# In[1]:
import matplotlib.pyplot as plt
# In[59]:
x=[2,3,4]
y=[1,2,3]
plt.plot(x,y)
plt.show()
# In[18]:
import numpy as np
# In[42]:
a=np.array([1,2,3,6,8,5])
b=np.array([2,3,4,7,3,5])
plt.scatter(a,b)
plt.plot(a,b)
plt.show()
# In[47]:
np.ones([4,4])*8
# In[67]:
a=np.linspace(0,4,50)
y=np.tan(a)
plt.scatter(a,y)
plt.plot(a,y)
plt.show()
# In[77]:
a=np.random.normal(5,3,80)
b=np.random.normal(5,3,80)
plt.scatter(a,b)
a1=np.random.normal(-5,3,80)
b1=np.random.normal(-5,3,80)
plt.scatter(a1,b1)
a2=np.random.normal(0,3,80)
b2=np.random.normal(-15,3,80)
plt.scatter(a2,b2)
plt.show()
# In[79]:
A=np.random.randint(2,8,[3,7])
B=np.random.randint(2,8,[7,3])
A
# In[80]:
B
# In[83]:
np.dot(A,B)
# In[86]:
np.linalg.inv(np.random.randint(2,7,[3,3]))
# In[95]:
X=np.array([[80,86,1],
[82,80,1],
[85,78,1],
[90,90,1],
[86,82,1],
[82,90,1]])
y=np.array([84.2,80.6,80.1,90,83.2,87.6])
X.shape,y.shape
# In[97]:
r1=np.dot(X.T,X)
r2=np.linalg.inv(r1)#(X.T*X)-1
r3=np.dot(r2,X.T)
r4=np.dot(r3,y)
w=r4
# In[100]:
x_test=[78,80,1]
np.dot(x_test,w)
# In[122]:
X=np.array([[2,1],
[4,1],
[6,1]])
w_real=np.array([[0.5],[3.]])
print(X.shape,w_real.shape)
y=np.dot(X,w_real)
print(y.shape)
r1=np.dot(X.T,X)
r2=np.linalg.inv(r1)#(X.T*X)-1
r3=np.dot(r2,X.T)
r4=np.dot(r3,y)
w_pre=r4
w_pre