From 07873262c6477d2e60221c4a3b50f9e0c614890d Mon Sep 17 00:00:00 2001 From: lv-jingjing-hh <2974075373@qq.com> Date: Fri, 5 Jul 2024 21:02:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=95=E6=99=B6=E6=99=B6=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 --- 0705/__pycache__/datas.cpython-311.pyc | Bin 0 -> 1198 bytes 0705/datas.py | 152 +++++++++++++++++++++++++ 0705/predict.py | 23 ++++ 3 files changed, 175 insertions(+) create mode 100644 0705/__pycache__/datas.cpython-311.pyc create mode 100644 0705/datas.py create mode 100644 0705/predict.py diff --git a/0705/__pycache__/datas.cpython-311.pyc b/0705/__pycache__/datas.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3241217ab0dbe4ec000b3b1a105ce4020c5746ad GIT binary patch literal 1198 zcmeH_OH0E*5XUEJlh#KxNn34wi=tFP#0P?ic<|s!1P_7)q;#W3swqhnds8o7L=+K4 z1VIGRPvFsyQF0Z9-U8k{Ih$^Z4-mntS@<)*{m;xUv$>U|YQXQ}et-F-2H=T8@FiLB z+Q$K$0Rh4ho`i6PiEt?*i;N?Tql~Kw{h@Pqt@FZqpM@{^3|eR*7|ieKg?#?8!cp}e9l0%@IxblawglY2fo zeYxH(?O|Brso)U7m}&<|i*7h;I0ZMHvGj~9Sf;sdyP}<4HO-tW*iIp*yF%VFvU+Ks z7Hzj-`2mfh9T;t6R0>fX>BNZ8D2Ik|j%bh+$|b&?anuA*zRJ!0^Wl{-(}SB{7fM_} znZjEd58WtoFUn&-_By7$UXch literal 0 HcmV?d00001 diff --git a/0705/datas.py b/0705/datas.py new file mode 100644 index 0000000..84518ab --- /dev/null +++ b/0705/datas.py @@ -0,0 +1,152 @@ +datas=[ + # 模拟的吕梁的第一类房子 + { + "city":"吕梁", + "area":130, + "rooms":2, + "school":1, + "style":1, + "price":8000 + }, + { + "city": "吕梁", + "area": 135, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7800 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + # 模拟的吕梁的第二类房子 + { + "city": "吕梁", + "area": 120, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8500 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8300 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8600 + }, + # 模拟的吕梁的第三类房子 + { + "city": "吕梁", + "area": 130, + "rooms": 2, + "school": 1, + "style": 1, + "price": 6500 + }, + { + "city": "吕梁", + "area": 135, + "rooms": 2, + "school": 1, + "style": 1, + "price": 6300 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 2, + "school": 1, + "style": 1, + "price": 6800 + }, + # 模拟的太原的第一类房子 + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9800 + }, + { + "city": "太原", + "area": 135, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9200 + }, + { + "city": "太原", + "area": 140, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9800 + }, +# 模拟的太原的第二类房子 + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 1300 + }, + { + "city": "太原", + "area": 135, + "rooms": 2, + "school": 1, + "style": 1, + "price": 1600 + }, + { + "city": "太原", + "area": 140, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9400 + }, +# 模拟的太原的第三类房子 + { + "city": "太原", + "area": 100, + "rooms": 3, + "school": 2, + "style": 2, + "price": 10000 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 11200 + }, + { + "city": "太原", + "area": 145, + "rooms": 3, + "school": 2, + "style": 2, + "price": 12800 + }, +] \ No newline at end of file diff --git a/0705/predict.py b/0705/predict.py new file mode 100644 index 0000000..58f9b26 --- /dev/null +++ b/0705/predict.py @@ -0,0 +1,23 @@ +# 1.先安装一个 科学计算的框架 +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,130,2,1,1]))) + + + print(item) \ No newline at end of file -- Gitee