From 764df5ee5b1558626cae04f146db1198313925eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=AA=E5=A4=A9=E5=87=AF?= <3222084892@qq.com> Date: Fri, 5 Jul 2024 21:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=AA=E5=A4=A9=E5=87=AF=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 --- htk/data(4).py | 174 ++++++++++++++++++++++++++++++++++++++++++++++ htk/predict(4).py | 8 +++ 2 files changed, 182 insertions(+) create mode 100644 htk/data(4).py create mode 100644 htk/predict(4).py diff --git a/htk/data(4).py b/htk/data(4).py new file mode 100644 index 0000000..f1964a5 --- /dev/null +++ b/htk/data(4).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/htk/predict(4).py b/htk/predict(4).py new file mode 100644 index 0000000..3cae856 --- /dev/null +++ b/htk/predict(4).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