diff --git a/__pycache__/datas.cpython-312.pyc b/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..65bd38ea3751ea75db48a40deadadef29e9d702e Binary files /dev/null and b/__pycache__/datas.cpython-312.pyc differ diff --git a/datas.py b/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..a81be34c10a992e827b88847c121578c0aaa6226 --- /dev/null +++ b/datas.py @@ -0,0 +1,156 @@ +#城市:吕梁1、太原2 + +#(city-城市) (area-面积) (rooms-房间数) (school-学区) (style-风格) + +datas=[ + #吕梁第一类 + { + "city":"吕梁", + "area":90, + "rooms":2, + "school":1, + "style":2, + "price":4600, + }, + { + "city":"吕梁", + "area":110, + "rooms":3, + "school":1, + "style":2, + "price":5900, + }, + { + "city":"吕梁", + "area":130, + "rooms":3, + "school":3, + "style":1, + "price":6500, + }, + #吕梁第二类 + { + "city":"吕梁", + "area":110, + "rooms":2, + "school":1, + "style":2, + "price":6500, + }, + { + "city":"吕梁", + "area":120, + "rooms":2, + "school":3, + "style":2, + "price":7600, + }, + { + "city":"吕梁", + "area":115, + "rooms":2, + "school":3, + "style":2, + "price":8000, + }, + #吕梁第三类 + { + "city":"吕梁", + "area":140, + "rooms":3, + "school":2, + "style":2, + "price":8600, + }, + { + "city":"吕梁", + "area":140, + "rooms":3, + "school":2, + "style":1, + "price":9000, + }, + { + "city":"吕梁", + "area":140, + "rooms":3, + "school":1, + "style":3, + "price":9500, + }, + # 太原第一类 + { + "city": "太原", + "area": 110, + "rooms": 3, + "school": 1, + "style": 2, + "price": 9000, + }, + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 1, + "style": 2, + "price": 9500, + }, + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 2, + "style": 1, + "price": 9800, + }, + # 太原第二类 + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 2, + "style": 1, + "price": 10000, + }, + { + "city": "太原", + "area": 135, + "rooms": 2, + "school": 1, + "style": 2, + "price": 11000, + }, + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 2, + "style": 2, + "price": 12000, + }, + # 太原第三类 + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 2, + "style": 1, + "price": 11000, + }, + { + "city": "太原", + "area": 125, + "rooms": 3, + "school": 3, + "style": 1, + "price": 12000, + }, + { + "city": "太原", + "area": 120, + "rooms": 3, + "school": 3, + "style": 2, + "price": 12500, + } +] \ No newline at end of file diff --git a/predict.py b/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..ca6b2464ec0ebc3126d0d163b16aa56754ce3e06 --- /dev/null +++ b/predict.py @@ -0,0 +1,21 @@ +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,120,3,2,2]))) +