diff --git a/zuoye/__pycache__/datas.cpython-311.pyc b/zuoye/__pycache__/datas.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..14438810bd6e3696ec710ea018f78b6d7a140ad0 Binary files /dev/null and b/zuoye/__pycache__/datas.cpython-311.pyc differ diff --git a/zuoye/datas.py b/zuoye/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..ee5d055d08259ada53011bfb3596a82f4774454c --- /dev/null +++ b/zuoye/datas.py @@ -0,0 +1,114 @@ +#预测系统 +#模拟太原和吕梁的房价数据 +#怎样模拟 城市 面积 户型 学区房 预测的维度越多,预测出来的房价更精准 +datas=[ + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":7600, + + }, +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":7900, + + }, +{ + "city":"吕梁", + "area":145, + "rooms":2, + "school":1, + "style":1, + "price":8500, + + }, +{ + "city":"吕梁", + "area":135, + "rooms":3, + "school":1, + "style":1, + "price":6300, + + }, +{ + "city":"吕梁", + "area":145, + "rooms":3, + "school":1, + "style":1, + "price":6500, + + }, +{ + "city":"吕梁", + "area":140, + "rooms":3, + "school":1, + "style":1, + "price":6600, + + }, + #taiyuan +{ + "city":"太原", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":10000, + + }, +{ + "city":"太原", + "area":120, + "rooms":2, + "school":1, + "style":1, + "price":9800, + + }, +{ + "city":"太原", + "area":100, + "rooms":3, + "school":1, + "style":1, + "price":9500, + + }, +{ + "city":"太原", + "area":135, + "rooms":3, + "school":2, + "style":2, + "price":9300, + + }, +{ + "city":"太原", + "area":145, + "rooms":3, + "school":2, + "style":2, + "price":9500, + + }, +{ + "city":"太原", + "area":140, + "rooms":3, + "school":2, + "style":2, + "price":9600, + + }, +]#列表 diff --git a/zuoye/predict.py b/zuoye/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..eef602ee654eea20428b83efd8b0ba5986202ff4 --- /dev/null +++ b/zuoye/predict.py @@ -0,0 +1,8 @@ +#1.安装一个科学计算的框架 +import numpy as np +a=np.array([[1,2,3],[1,2,3],[1,2,3]]) +b=np.array([1,2,3]) +print(a.dot(b)) #dot:两个矩阵之间的乘法 +print(a) +print(a.T) # 矩阵称呼.T:求矩阵的转置 +print(np.linalg.pinv(a)) # np.linalg.pinv(矩阵称呼):矩阵的逆 (可以排除奇异矩阵) diff --git a/zuoye/predict1.py b/zuoye/predict1.py new file mode 100644 index 0000000000000000000000000000000000000000..4da7529a6ff7916c14c7a302715a4620a7e0e25a --- /dev/null +++ b/zuoye/predict1.py @@ -0,0 +1,19 @@ +import numpy as np +from datas import datas +X=[] +Y=[] +cityMark={"吕梁":1,"太原":2} +for item in datas: + single=[] + single.append(cityMark[item["city"]]) + single.append(item["area"]) + single.append(item["rooms"]) + single.append(item["school"]) + single.append(item["style"]) + X.append(single) + Y.append(item["price"]) + +X=np.array(X) +Y=np.array(Y) +theta=np.linalg.pinv(X.T.dot(X)).dot(X.T).dot(Y) +print(theta.dot(np.array([2,150,2,1,1]))) \ No newline at end of file