diff --git a/7.5/__pycache__/datas.cpython-311.pyc b/7.5/__pycache__/datas.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cf884644df243a1f865c807c65f88df04522589c Binary files /dev/null and b/7.5/__pycache__/datas.cpython-311.pyc differ diff --git a/7.5/datas.py b/7.5/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..b021efa87e2ca984a64270221aea5f1e13875a80 --- /dev/null +++ b/7.5/datas.py @@ -0,0 +1,160 @@ +#经验来源于数据 +# 大数据 + +#模拟太原和吕梁的房价数据 + +#怎么模拟 影响因素:城市 面积 户型 学区房 1 是 2 不是 装修 精装 1 毛坯 2 。。。。。。 + +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":135, + "rooms":2, + "school":1, + "style":1, + "price":8500 + }, + { + "city":"吕梁", + "area":130, + "rooms":2, + "school":1, + "style":1, + "price":8300 + }, + { + "city":"吕梁", + "area":140, + "rooms":2, + "school":1, + "style":1, + "price":8600 + }, + # 模拟吕梁第三类 + { + "city": "吕梁", + "area": 135, + "rooms": 2, + "school": 2, + "style": 2, + "price": 6300 + }, + { + "city": "吕梁", + "area": 130, + "rooms": 3, + "school": 2, + "style": 2, + "price": 6500 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 5600 + }, + # 模拟太原第一类 + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10000 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10500 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 9800 + }, + # 模拟太原第二类 + { + "city": "太原", + "area": 135, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10500 + }, + { + "city": "太原", + "area": 130, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10300 + }, + { + "city": "太原", + "area": 140, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10600 + }, + # 模拟太原第三类 + { + "city": "太原", + "area": 135, + "rooms": 2, + "school": 2, + "style": 2, + "price": 8300 + }, + { + "city": "太原", + "area": 130, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8500 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8600 + }, + +] diff --git a/7.5/predict.py b/7.5/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..2e1a4e8befd91fad828c93cd1a73fa9988026a5f --- /dev/null +++ b/7.5/predict.py @@ -0,0 +1,36 @@ +#1.先安装一个 科学的计算框架 pip install numpy +import numpy as np +from datas import datas +# a=np.array([[3,2,3],[3,2,3],[3,2,3]]) +# b=np.array([1,2,3]) +# #矩阵的点乘 +# print(a.dot(b)) +# #矩阵的转置 +# print(a.T) +# #矩阵求逆 +# #奇异矩阵 +# print(np.linalg.pinv(a)) +X=[] +Y=[] +cityMark={"吕梁":1,"太原":2} +for item in datas: + single=[] + #城市 + single.append(cityMark[item["city"]]) + #面积 + single.append(item["area"]) + #rooms + single.append(item["rooms"]) + #school + single.append(item["school"]) + #style + 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) + +