From 8fdeb3e9fe14e2617b334815b745b8a593bc6fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=90=E6=80=A1=E6=98=95?= <14647838+chengyixin111@user.noreply.gitee.com> Date: Fri, 5 Jul 2024 21:39:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=90=E6=80=A1=E6=98=95=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 --- 07.05/0705/__pycache__/datas.cpython-312.pyc | Bin 0 -> 1073 bytes 07.05/0705/datas.py | 172 +++++++++++++++++++ 07.05/0705/predict.py | 26 +++ 3 files changed, 198 insertions(+) create mode 100644 07.05/0705/__pycache__/datas.cpython-312.pyc create mode 100644 07.05/0705/datas.py create mode 100644 07.05/0705/predict.py diff --git a/07.05/0705/__pycache__/datas.cpython-312.pyc b/07.05/0705/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1abbbc37bae56cbd7b711932b5989ca0f67ccec6 GIT binary patch literal 1073 zcmd6kJxjw-6oyaICaoW_Nm^^G;K!r|Kk6Wgh&Z?i;wFf6iM>?=Eh$L~W>Xgz5f{-x z5JV6i{Tu#)l2sJkDsE1mliq5nh#(H$z{`1V&N=tI_ueZ?JK&nVJJ`Hd03HY$E5?J@ zQ32o-7%+i}EQDW}N#}AC%Pkz?9A#}memmz5&YheU&RtFUBAyXz$|qKv@`*L#t+sVw z`o~Q1Am@`4E!@qyF+;M2dpI{{N^vF+bY|VN&ZwTa?n!5qPaJrlnY?tSw<6=+JszJt zUG6<0;MyH zGBXLVk`a7~8Lr{nz$-R`x535PT-nQS8+K{TaVyNrP3E%G*{NKRHD31KqH`sSRf>gq zJB|fp&GAudAwdvoNl;VOm|j)2surl4cu^vfT+=~ISJgP}>VazAKm17i%T`O`vJeq> krP_x0Wxj76CBL)Ee|)w2hpm47088Sk5RvyJTf;Yg2fj%bHvj+t literal 0 HcmV?d00001 diff --git a/07.05/0705/datas.py b/07.05/0705/datas.py new file mode 100644 index 0000000..57e5d36 --- /dev/null +++ b/07.05/0705/datas.py @@ -0,0 +1,172 @@ +# 经验来源于数据 +# 大数据 很多的数据 + +# 预测地方房价 +# 预测太原,吕梁房价 +# 1. 模拟太原和吕梁的房价数据 +# 模拟吕梁的房子数据 +datas=[ + # 模拟吕梁的第一类房子 + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":8000 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7800 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + # 模拟吕梁的第二类房子 + { + "city":"吕梁", + "area":130, + "rooms":3, + "school":1, + "style":1, + "price":8300 + }, + { + "city": "吕梁", + "area": 135, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8450 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8600 + }, + # 模拟吕梁的第三类房子 + { + "city":"吕梁", + "area":130, + "rooms":3, + "school":2, + "style":2, + "price":7000 + }, + { + "city": "吕梁", + "area": 135, + "rooms": 3, + "school": 2, + "style": 2, + "price": 6500 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 6200 + }, +] +# 模拟太原房价数据 +datas=[ + # 模拟太原的第一类房子 + { + "city":"太原", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":10100 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10300 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10500 + }, + # 模拟太原的第二类房子 + { + "city":"太原", + "area":135, + "rooms":3, + "school":1, + "style":1, + "price":12120 + }, + { + "city": "太原", + "area": 135, + "rooms": 3, + "school": 1, + "style": 1, + "price": 12300 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 1, + "style": 1, + "price": 12600 + }, + # 模拟太原的第三类房子 + { + "city":"太原", + "area":130, + "rooms":3, + "school":2, + "style":2, + "price":8000 + }, + { + "city": "太原", + "area": 135, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8300 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8600 + }, + # 模拟房价数据的权重计算 + # 3000 10 1000 1300 1500 + # 太原2 100 3 1 1 + # 3000+1400+3000+2600+3000 + # 城市 x1 面积 x2 房间数 x3 学校 x4 样式 x5 + # x1=1 x2=100 x3=3 x4=1 x5=1 + # a1*1+a2*2+a3*3+a4*4+a5*5=y + # [a1,a2,......] 数学模型 机器学习 机器学习软件开发 + + ] + diff --git a/07.05/0705/predict.py b/07.05/0705/predict.py new file mode 100644 index 0000000..b21590e --- /dev/null +++ b/07.05/0705/predict.py @@ -0,0 +1,26 @@ +# 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"]) + #rooms + single.append(item["rooms"]) + #school + single.append(item["school"]) + #style + 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) + -- Gitee