From a721931a27233ea08a6e8035cde61aba4a4a3573 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jul 2024 18:40:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=88=E6=AC=A3=E5=A6=82=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 7.5/__pycache__/datas.cpython-312.pyc | Bin 0 -> 668 bytes 7.5/datas.py | 60 ++++++++++++++++++++++++++ 7.5/predict.py | 33 ++++++++++++++ 3 files changed, 93 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..94e8a20da37d1cf85acbce2cf61e8772d7907a2a GIT binary patch literal 668 zcmc&uJxjw-6n$xvwANOeih|nVId%~gMX2KBEP{(jp@h7CL{cM33uaUl2eG;o7ey(8 zU!X3cVE=)Cpk#2-M6$KiNgTZIwTl118*;ek+;iW#&yh$7LA_k>WT$zAUMcyhaHnZ$ z&>SLymJ#8IkN61>zd*zz5qN+E8Sm=w5X|V;&3O3NAL;NPf6t#e_4iVq6PGzFnvhD{ z5E;TyZspG1yKzrzPHmqFidwXi*f}XXkDE-8jf|Yc-f{K){FVuZt`|(O+?+9LDtTSk zl6VY{V>7R|wW6hEs012bQCD+JT{Bb#RIj?_-tWFWJwR%xB*G=m*_Bg1@d&h@j{*mv zPK+Rw5N)1bWb^b4TVUC?*v_;Cljhh0d)V8gn|`|a1)JVF?KF%~JK~_?RyWk8VGwZ~ z;A04(`Gn67q|-!K(rH^Da#1!fQ499aXM8T1TCkM7Y!p(ao-L-PMkiCuF}h}b24@O7 zDQTHmqYupVTJr*+;paH6$p<;UF@U7OdbF=D#p*GJQhzfN5X468KL?B4SeI`@FeEtk E8?#fx0ssI2 literal 0 HcmV?d00001 diff --git a/7.5/datas.py b/7.5/datas.py new file mode 100644 index 0000000..34a3b28 --- /dev/null +++ b/7.5/datas.py @@ -0,0 +1,60 @@ +# 预测系统 +""" + 数据格式 + city: 城市 + area: 面积 + rooms: 室 + school: 1 2 shi + style: 1 2 jing + price: 预测价格 +""" +datas = [ + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 2, + "price": 8500 + }, + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 1, + "style": 2, + "price": 8700 + }, + { + "city": "太原", + "area": 120, + "rooms": 2, + "school": 2, + "style": 2, + "price": 8300 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 2, + "price": 7000 + }, + { + "city": "吕梁", + "area": 130, + "rooms": 3, + "school": 1, + "style": 2, + "price": 7200 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 2, + "style": 2, + "price": 6900 + }, +] \ No newline at end of file diff --git a/7.5/predict.py b/7.5/predict.py new file mode 100644 index 0000000..eb9bcc4 --- /dev/null +++ b/7.5/predict.py @@ -0,0 +1,33 @@ +import numpy as np +# a = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) +# b = np.array([1, 2, 3]) +# print(a) +# print(a.T) 转置 +# print(a.dot(b))点乘 +# print(np.linalg.pinv(a)) 逆矩阵 +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, 200, 2, 1, 1]))) + + -- Gitee