diff --git "a/7.5 \345\210\230\345\230\211\346\254\243/__pycache__/datas.cpython-312.pyc" "b/7.5 \345\210\230\345\230\211\346\254\243/__pycache__/datas.cpython-312.pyc" new file mode 100644 index 0000000000000000000000000000000000000000..beea63bbbc4d71b445a39d55068852dea7bb492b Binary files /dev/null and "b/7.5 \345\210\230\345\230\211\346\254\243/__pycache__/datas.cpython-312.pyc" differ diff --git "a/7.5 \345\210\230\345\230\211\346\254\243/datas.py" "b/7.5 \345\210\230\345\230\211\346\254\243/datas.py" new file mode 100644 index 0000000000000000000000000000000000000000..49c658de626a15e5a0bac1339a73d4f56855182c --- /dev/null +++ "b/7.5 \345\210\230\345\230\211\346\254\243/datas.py" @@ -0,0 +1,164 @@ +# 大数据 爬虫 +# 模拟太原和吕梁的房价数据 +# 怎么模拟 城市 面积 户型 是不是学区房 装修风格 + +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": 5600 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 5800 + }, + # 太原模拟第一类房子 + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "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": 8200 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8600 + }, + # 模拟第三类房子 + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7300 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8600 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7800 + }, + # 模拟房价数据的权重计算 + # 3000 10 1000 1300 1500 + # 太原2 100 3 1 1 + # 3000+1400+3000+2600+3000 + # 城市 x1 面积 x2 房间数 x3 学校 x4 样式 x5 + # x1=1 x2=100 x3=3 x4=1 x5=1 + # a1*1+a2*2+a3*3+a4*4+a5*5=y + # [a1,a2,......] 数学模型 机器学习 机器学习软件开发 + ] \ No newline at end of file diff --git "a/7.5 \345\210\230\345\230\211\346\254\243/predict.py" "b/7.5 \345\210\230\345\230\211\346\254\243/predict.py" new file mode 100644 index 0000000000000000000000000000000000000000..84708898873d23db9c5b4c78b9738bd2b4e0a28c --- /dev/null +++ "b/7.5 \345\210\230\345\230\211\346\254\243/predict.py" @@ -0,0 +1,35 @@ +# 1.安装一个科学计算的框架 +# import numpy as np +# a=np.array([[3,2,3],[3,2,3],[3,2,3]]) +# b=np.array([1,2,3]) +# print(a.dot(b)) +# +# print(a) +# print(a.T) +# 奇异矩阵 +# 求 点乘 转置 逆 +# print(np.linalg.pinv(a)) +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) \ No newline at end of file