diff --git a/Test1/__pycache__/datas.cpython-310.pyc b/Test1/__pycache__/datas.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..47259700407d1a3e56eb0699db62e68ed4380223 Binary files /dev/null and b/Test1/__pycache__/datas.cpython-310.pyc differ diff --git a/Test1/datas.py b/Test1/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..69c5517d97cc43837fe1a002b2533fc15033b2c9 --- /dev/null +++ b/Test1/datas.py @@ -0,0 +1,111 @@ +datas = [ + # 模拟吕梁 + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7600 + }, + # 模拟吕梁第二类 + { + "city": "吕梁", + "area": 300, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "吕梁", + "area": 500, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8200 + }, + { + "city": "吕梁", + "area": 500, + "rooms": 3, + "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": 8200 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7600 + }, + # 模拟太原第二类 + { + "city": "太原", + "area": 300, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8000 + }, + { + "city": "太原", + "area": 135, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8600 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8600 + }, + + # 3000 10 1000 1300 1500 + # 太原 2 100 3 1 1 + + # 城市 x1 面积 x2 房间数量 x3 学区房 x4 装修 x5 +] diff --git a/Test1/predict.py b/Test1/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..01706f9258373c21ecff579b59f73f70719b688b --- /dev/null +++ b/Test1/predict.py @@ -0,0 +1,39 @@ +# import numpy as np +# +# a = np.array([[1, 2, 3], [1, 2, 3], [1, 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["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,100,2,1]))) \ No newline at end of file