From c5f5a391c355ee6e6d04165531463d29b098bf2b Mon Sep 17 00:00:00 2001 From: Ylt233 <1951833090@qq.com> Date: Fri, 5 Jul 2024 21:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E7=8E=B2=E9=80=9A=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 --- __pycache__/datas.cpython-312.pyc | Bin 0 -> 1078 bytes datas.py | 156 ++++++++++++++++++++++++++++++ predict.py | 21 ++++ 3 files changed, 177 insertions(+) create mode 100644 __pycache__/datas.cpython-312.pyc create mode 100644 datas.py create mode 100644 predict.py diff --git a/__pycache__/datas.cpython-312.pyc b/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..65bd38ea3751ea75db48a40deadadef29e9d702e GIT binary patch literal 1078 zcmX@j%ge<81ZVEFr`2;aFgylvU_b)O_^iRmz%ZR5g&~D8g(-y@h*?rt=dc0!Y$@zu zJ_nS~3FL!BxZv^-^)Nm+P%k?W^FZZ!p?p3lpC2sClp=t_XHF4B;xhx)2!Z*+aQh+h z!YSNf+nM0}ttnH=1`M~S6Q({})c7(A$b88JB7i~2koiN9fkBh)7E5wwN#!k;#G=&1TdYO- z`MJfn*ou=g^7C_Uu@;w9=A_ztpG3S^gLlIY~;;_lhPbtkwwJQR;lmX=1;tN3X12ZEd;|Bo-0f`&@f;R*NZwLy3NCAc}pMM#2*M#Zy)GqE!@ KvKEN~V-^5pkRG}K literal 0 HcmV?d00001 diff --git a/datas.py b/datas.py new file mode 100644 index 0000000..a81be34 --- /dev/null +++ b/datas.py @@ -0,0 +1,156 @@ +#城市:吕梁1、太原2 + +#(city-城市) (area-面积) (rooms-房间数) (school-学区) (style-风格) + +datas=[ + #吕梁第一类 + { + "city":"吕梁", + "area":90, + "rooms":2, + "school":1, + "style":2, + "price":4600, + }, + { + "city":"吕梁", + "area":110, + "rooms":3, + "school":1, + "style":2, + "price":5900, + }, + { + "city":"吕梁", + "area":130, + "rooms":3, + "school":3, + "style":1, + "price":6500, + }, + #吕梁第二类 + { + "city":"吕梁", + "area":110, + "rooms":2, + "school":1, + "style":2, + "price":6500, + }, + { + "city":"吕梁", + "area":120, + "rooms":2, + "school":3, + "style":2, + "price":7600, + }, + { + "city":"吕梁", + "area":115, + "rooms":2, + "school":3, + "style":2, + "price":8000, + }, + #吕梁第三类 + { + "city":"吕梁", + "area":140, + "rooms":3, + "school":2, + "style":2, + "price":8600, + }, + { + "city":"吕梁", + "area":140, + "rooms":3, + "school":2, + "style":1, + "price":9000, + }, + { + "city":"吕梁", + "area":140, + "rooms":3, + "school":1, + "style":3, + "price":9500, + }, + # 太原第一类 + { + "city": "太原", + "area": 110, + "rooms": 3, + "school": 1, + "style": 2, + "price": 9000, + }, + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 1, + "style": 2, + "price": 9500, + }, + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 2, + "style": 1, + "price": 9800, + }, + # 太原第二类 + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 2, + "style": 1, + "price": 10000, + }, + { + "city": "太原", + "area": 135, + "rooms": 2, + "school": 1, + "style": 2, + "price": 11000, + }, + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 2, + "style": 2, + "price": 12000, + }, + # 太原第三类 + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 2, + "style": 1, + "price": 11000, + }, + { + "city": "太原", + "area": 125, + "rooms": 3, + "school": 3, + "style": 1, + "price": 12000, + }, + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 3, + "style": 2, + "price": 12500, + } +] \ No newline at end of file diff --git a/predict.py b/predict.py new file mode 100644 index 0000000..ca6b246 --- /dev/null +++ b/predict.py @@ -0,0 +1,21 @@ +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,120,3,2,2]))) + -- Gitee