From 47724f377e9e6a4ffe7fe35d1edfde5c438aa931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E5=BA=AD=E5=AE=8F?= <14647641+fan-tinghong@user.noreply.gitee.com> Date: Fri, 5 Jul 2024 19:08:09 +0800 Subject: [PATCH] 7.5 --- 7.5/__pycache__/datas.cpython-312.pyc | Bin 0 -> 727 bytes 7.5/datas.py | 105 ++++++++++++++++++++++++++ 7.5/predict.py | 36 +++++++++ 3 files changed, 141 insertions(+) create mode 100644 7.5/__pycache__/datas.cpython-312.pyc create mode 100644 7.5/datas.py create mode 100644 7.5/predict.py diff --git a/7.5/__pycache__/datas.cpython-312.pyc b/7.5/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3e7d4770dd476c674e9db7436fb386baf45578c2 GIT binary patch literal 727 zcmX@j%ge<81Se0mr%)X-(o9H&dATtxy4#sQkj!_i?yIAGdUGv(vnqA`{w&;GTvfMNi0b$UdiwoXcWUQ z6=$oM(Bjmh;uy!^(BK%C)Z*-t{DK(67;`<-7_dscg34bUHo5sJr8%i~Mf^ZbAV(Bi z0m%={jEsyQI2Z&ZZtx4;5D>f}2qpzYKJv1&vV9O@5R{~~ga|G>uuCxFaurZQ3}lpm vFvt@^U{X*N<_})c8$A3sc=>Mdfk|FLpaednaQeKODV>p>sgbpa7Z`>BOiaPZ literal 0 HcmV?d00001 diff --git a/7.5/datas.py b/7.5/datas.py new file mode 100644 index 0000000..5ee55f8 --- /dev/null +++ b/7.5/datas.py @@ -0,0 +1,105 @@ +# 怎么模拟 城市 面积 户型 学区房 装修风格 +datas=[ + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, +#模拟第二类 + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, +#第三类 +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, +#太原 + + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 2, + "price": 8000 + }, +{ + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 2, + "price": 8000 + }, +{ + "city":"太原", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, + { + "city":"太原", + "area":100, + "rooms":2, + "school":1, + "style":2, + "price":8000 + }, + + +] diff --git a/7.5/predict.py b/7.5/predict.py new file mode 100644 index 0000000..b721fc0 --- /dev/null +++ b/7.5/predict.py @@ -0,0 +1,36 @@ +# 1.先安装一个 科学计算的框架 pip install numpy +import numpy as np +#a=np.array([[3,2,3],[3,2,3],[3,2,3]]) +#b=np.array([1,2,3]) +#print(a.dot(b)) #点乘 +# 奇异矩阵 +#print(np.linalg.pinv(a)) #求逆 +#print(a.T) #转置 + +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([3, 100, 2, 1, 1]))) + # print(theta) + + + + + + -- Gitee