diff --git a/0705/__pycache__/datas.cpython-311.pyc b/0705/__pycache__/datas.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..13b966558235e0843c13385a8484f72f924f2881 Binary files /dev/null and b/0705/__pycache__/datas.cpython-311.pyc differ diff --git a/0705/datas.py b/0705/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..f954c5ef8b48c47c57b784e8f378c8043dbfd8ee --- /dev/null +++ b/0705/datas.py @@ -0,0 +1,157 @@ +#模拟房价数据 +#怎么模拟 城市 面积 户型 是否是学区房 装修的风格 (维度越多越精准) +datas=[ +#模拟的吕梁第一类房子 + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":8000 + }, +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":7800 + }, +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":8200 + }, +#模拟的吕梁第二类房子 +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":8500 + }, +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":8300 + }, +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":8600 + }, +#模拟的吕梁第三类房子 +{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":6300 + },{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":6500 + },{ + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":6600 + }, +#模拟的太原第一类房子 + { + "city":"太原", + "area":100, + "rooms":3, + "school":1, + "style":1, + "price":8300 + }, +{ + "city":"太原", + "area":135, + "rooms":2, + "school":1, + "style":1, + "price":8800 + }, +{ + "city":"太原", + "area":100, + "rooms":4, + "school":1, + "style":2, + "price":8200 + }, +#模拟的太原第二类房子 +{ + "city":"太原", + "area":140, + "rooms":2, + "school":1, + "style":2, + "price":10600 + }, +{ + "city":"太原", + "area":100, + "rooms":2, + "school":2, + "style":1, + "price":8300 + }, +{ + "city":"太原", + "area":100, + "rooms":4, + "school":1, + "style":1, + "price":8600 + }, +#模拟的太原第三类房子 +{ + "city":"太原", + "area":100, + "rooms":3, + "school":1, + "style":2, + "price":9300 + },{ + "city":"太原", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":6500 + },{ + "city":"太原", + "area":130, + "rooms":4, + "school":2, + "style":1, + "price":8600 + }, + +#权重 +#计算各项权重之和来得出房价 +#城市 x1 面积 x2 房间数量 x3 学区房 x4 装修 x5 +#权重 a1 a2 a3 a4 a5 +#a1x1+a2x2+a3x3+a4x4+a5x5=y +#[a1 a2 a3....]数学模型 机器学习 机器学习软件开发 +] \ No newline at end of file diff --git a/0705/predict.py b/0705/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..6ae405299a5345a0bf7100e2f61645c9120e999b --- /dev/null +++ b/0705/predict.py @@ -0,0 +1,27 @@ +#1.先安装一个科学计算的框架 pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple +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([1,120,2,1,1]))) \ No newline at end of file