From 0fe13ae90b15af7614b245a92b9f7616be86aeeb Mon Sep 17 00:00:00 2001 From: cheer36 <1175478916.com> Date: Fri, 5 Jul 2024 18:40:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AB=E7=A7=8B=E5=BD=A4=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 --- Test1/__pycache__/datas.cpython-310.pyc | Bin 0 -> 646 bytes Test1/datas.py | 111 ++++++++++++++++++++++++ Test1/predict.py | 39 +++++++++ 3 files changed, 150 insertions(+) create mode 100644 Test1/__pycache__/datas.cpython-310.pyc create mode 100644 Test1/datas.py create mode 100644 Test1/predict.py diff --git a/Test1/__pycache__/datas.cpython-310.pyc b/Test1/__pycache__/datas.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..47259700407d1a3e56eb0699db62e68ed4380223 GIT binary patch literal 646 zcmd1j<>g`k0@Y3JX*wJX439w^WFQ3OH~?|+2_TWekiwY4l)?;zEGevW*pT>aXnb}k zp94)jX9^csKTJI;pBv451RtUv!H1a7oq}pUcM1>Gd|t5q+$nrOJ`)gv`RP1S3@QA< z44ML^Y(VckoiO#;qQ;jgK;}y(5Wxr}G9Ba@7&O^#u_R}fRNi7qEJ{s`VlB$g&n>>i zR-BxXpPzG!wYa1*C-oLf9*G#PKPrX-dm7O!L|;spwTiC;F(RxzQ)sYS&xA)&z@{-H4emB|^2MY#b* z`B|ySCB-oXl_eSZc~EXlNNRD3VGP(9y@JYH95%W6DWy57b|6m_uL2TG%uI|h$nuMc Y6UJs@#Nct^kwewTN3=?!&E%L503im54gdfE literal 0 HcmV?d00001 diff --git a/Test1/datas.py b/Test1/datas.py new file mode 100644 index 0000000..69c5517 --- /dev/null +++ b/Test1/datas.py @@ -0,0 +1,111 @@ +datas = [ + # 模拟吕梁 + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7600 + }, + # 模拟吕梁第二类 + { + "city": "吕梁", + "area": 300, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "吕梁", + "area": 500, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8200 + }, + { + "city": "吕梁", + "area": 500, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8200 + }, + + + + + # 模拟太原 + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7600 + }, + # 模拟太原第二类 + { + "city": "太原", + "area": 300, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "太原", + "area": 135, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8600 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8600 + }, + + # 3000 10 1000 1300 1500 + # 太原 2 100 3 1 1 + + # 城市 x1 面积 x2 房间数量 x3 学区房 x4 装修 x5 +] diff --git a/Test1/predict.py b/Test1/predict.py new file mode 100644 index 0000000..01706f9 --- /dev/null +++ b/Test1/predict.py @@ -0,0 +1,39 @@ +# import numpy as np +# +# a = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) +# b = np.array([1, 2, 3]) +# # 求点乘 +# print(a.dot(b)) +# # 求转置 +# print(a) +# print(a.T) +# # 奇异矩阵 +# # 求逆 +# print(np.linalg.pinv(a)) + + +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["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([1,100,2,1]))) \ No newline at end of file -- Gitee