房价预测模型
学习目标:
监督算法的应用
题目:
面积(54, 29,14,21,50) 厅室(3, 3,2 ,2,4) 钱(400,330,369,292,540) 通过数据分析,找到面积,厅室与钱的关系
代码:
import numpy as np
import matplotlib.pyplot as plt
theta0=np.random.random()
theta1=np.random.random()
theta2=np.random.random()
theta=np.array([theta1,theta2])
x=np.array([[54,3],
[29,3],
[14,2],
[21,2],
[50,4]])
t=np.array([400,330,369,292,540])
a=0.01
eps=1e-4
e0=5
e2=5
e3=5
while e0>=eps or e1>=eps or e2>=eps:
i=0
e0=(np.sum((x[:,i]*theta[i]))+theta0*1-t[i])
e1=e0*x[i,0]
e2=e0*x[i,1]
theta0=theta0-a*e0
theta1=theta1-a*e1
theta2=theta2-a*e2
i+=1
print(theta0,theta1,theta2)
3.7690140588194945 185.72205838301196 10.428825946620965