From ea0ac2b7db309c3b3a6e7c3cae5c5f355737364c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=98=9F=E5=AE=87?= <1320303802@qq.com> Date: Sat, 6 Jul 2024 08:52:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=98=E6=98=9F=E5=AE=87=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 --- lxy/data(1).py | 174 ++++++++++++++++++++++++++++++++++++++++++++++ lxy/predict(1).py | 8 +++ 2 files changed, 182 insertions(+) create mode 100644 lxy/data(1).py create mode 100644 lxy/predict(1).py diff --git a/lxy/data(1).py b/lxy/data(1).py new file mode 100644 index 0000000..f1964a5 --- /dev/null +++ b/lxy/data(1).py @@ -0,0 +1,174 @@ +datas = [ + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000, + }, + { + "city": "吕梁", + "area": 120, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8300, + }, + { + "city": "吕梁", + "area": 130, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8600, + }, + { + "city": "吕梁", + "area": 140, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9000, + }, + { + "city": "吕梁", + "area": 150, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9300, + }, + { + "city": "吕梁", + "area": 160, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9500, + }, + { + "city": "吕梁", + "area": 170, + "rooms": 4, + "school": 3, + "style": 2, + "price": 9500, + }, + { + "city": "吕梁", + "area": 180, + "rooms": 4, + "school": 4, + "style": 3, + "price": 9600, + }, + { + "city": "吕梁", + "area": 190, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9400, + }, + { + "city": "太原", + "area": 210, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9200, + }, + { + "city": "太原", + "area": 200, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9100, + }, + { + "city": "太原", + "area": 190, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9000, + }, + { + "city": "吕梁", + "area": 180, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8900, + }, + { + "city": "太原", + "area": 170, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8800, + }, + { + "city": "太原", + "area": 160, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8700, + }, + ] + + +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["rooms"]) +single.append(item["school"]) +single.append(item["style"]) +single.append(item["area"]) +X.append(single) +Y.append(item["price"]) + +X=np.array(X) +Y=np.array(Y) + +theta=np.linalg.pinv(X.T.dot(X)).dot(Y) + + +print(theta) + +print(theta.dot(np.array([2,100,2,1,1]))) + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lxy/predict(1).py b/lxy/predict(1).py new file mode 100644 index 0000000..3cae856 --- /dev/null +++ b/lxy/predict(1).py @@ -0,0 +1,8 @@ +import numpy as np +a=np.array([[3,2,3],[3,2,3],[3,2,3]]) +b=np.array([1,2,3]) + + +print(a.T) +print(a.dot(b)) +print(np.linalg.pinv(a)) -- Gitee