diff --git a/7.5/__pycache__/datas.cpython-312.pyc b/7.5/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..94e8a20da37d1cf85acbce2cf61e8772d7907a2a Binary files /dev/null and b/7.5/__pycache__/datas.cpython-312.pyc differ diff --git a/7.5/datas.py b/7.5/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..34a3b28b0e2eccaacb7684701bdbeb472eaf2468 --- /dev/null +++ b/7.5/datas.py @@ -0,0 +1,60 @@ +# 预测系统 +""" + 数据格式 + city: 城市 + area: 面积 + rooms: 室 + school: 1 2 shi + style: 1 2 jing + price: 预测价格 +""" +datas = [ + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 2, + "price": 8500 + }, + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 1, + "style": 2, + "price": 8700 + }, + { + "city": "太原", + "area": 120, + "rooms": 2, + "school": 2, + "style": 2, + "price": 8300 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 2, + "price": 7000 + }, + { + "city": "吕梁", + "area": 130, + "rooms": 3, + "school": 1, + "style": 2, + "price": 7200 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 2, + "style": 2, + "price": 6900 + }, +] \ No newline at end of file diff --git a/7.5/predict.py b/7.5/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..eb9bcc453b5123c3b21cb79690d4bb351a8e30ab --- /dev/null +++ b/7.5/predict.py @@ -0,0 +1,33 @@ +import numpy as np +# a = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) +# b = np.array([1, 2, 3]) +# print(a) +# print(a.T) 转置 +# print(a.dot(b))点乘 +# print(np.linalg.pinv(a)) 逆矩阵 +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, 200, 2, 1, 1]))) + +