import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import random
Q0=random.random()
Q1=random.random()
Q2=random.random()
a=0.01
E=1e-04
x=np.array([[2104,3],
[1600,3],
[2400,3],
[1416,2],
[3000,4]])
t=np.array([[400],
[330],
[269],
[232],
[540]])
e0=1
e1=1
e2=1
h=1
while e0>=E or e1>=E or e2>=E:
b=random.randint(0,4)
i=b
h=Q0+Q1*x[i,0]+Q2*x[i,1]
e0=h-t[i]
e1=((h-t[i])+e0)*x[i,0]
ey=h-t[i]+e0
e2=((h-t[i])+e0+ey)*x[i,1]
else:
Q0=Q0-a*e0
Q1=Q1-a*e1
Q2=Q2-a*e2
print(Q0,Q1,Q2)
fig1=plt.figure()
ax=Axes3D(fig1)
X1,X2=np.mgrid[0:10000:500j, 0:50:500j]
h=Q0+(Q1*X1+Q2*X2)
plt.title("tu xiang")
ax.plot_surface(X1, X2, h , rstride=1, cstride=1, cmap=plt.cm.coolwarm, alpha=0.5)
ax.set_xlabel('X1', color='r')
ax.set_ylabel('X2', color='g')
ax.set_zlabel('h', color='b')
plt.show()
[2.58278175] [8448.67392082] [21.12753069]
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ec080e702381e236c5f7bf7ca84fb536.png#pic_center)