diff --git "a/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/__pycache__/datas.cpython-310.pyc" "b/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/__pycache__/datas.cpython-310.pyc" new file mode 100644 index 0000000000000000000000000000000000000000..466b3b067ef58f4bd6fe2dd917054784f55abed3 Binary files /dev/null and "b/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/__pycache__/datas.cpython-310.pyc" differ diff --git "a/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/datas.py" "b/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/datas.py" new file mode 100644 index 0000000000000000000000000000000000000000..9e7c261d4e39f39c09b1876df70c46a91252148c --- /dev/null +++ "b/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/datas.py" @@ -0,0 +1,158 @@ + + + + +dates=[ + # 模拟吕梁的第一类房子 + { + "city":"吕梁", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":7000 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 7800 + }, + { + "city": "吕梁", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 8200 + }, + # 模拟吕梁的第二类房子 + { + "city":"吕梁", + "area":130, + "rooms":3, + "school":1, + "style":1, + "price":8300 + }, + { + "city": "吕梁", + "area": 135, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8450 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 3, + "school": 1, + "style": 1, + "price": 8600 + }, + # 模拟吕梁的第三类房子 + { + "city":"吕梁", + "area":130, + "rooms":3, + "school":2, + "style":2, + "price":7000 + }, + { + "city": "吕梁", + "area": 135, + "rooms": 3, + "school": 2, + "style": 2, + "price": 6500 + }, + { + "city": "吕梁", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 6200 + }, +] +# 模拟太原房价数据 +dates=[ + # 模拟太原的第一类房子 + { + "city":"太原", + "area":100, + "rooms":2, + "school":1, + "style":1, + "price":10100 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10300 + }, + { + "city": "太原", + "area": 100, + "rooms": 2, + "school": 1, + "style": 1, + "price": 10500 + }, + # 模拟太原的第二类房子 + { + "city":"太原", + "area":135, + "rooms":3, + "school":1, + "style":1, + "price":12120 + }, + { + "city": "太原", + "area": 135, + "rooms": 3, + "school": 1, + "style": 1, + "price": 12300 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 1, + "style": 1, + "price": 12600 + }, + # 模拟太原的第三类房子 + { + "city":"太原", + "area":130, + "rooms":3, + "school":2, + "style":2, + "price":8000 + }, + { + "city": "太原", + "area": 135, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8300 + }, + { + "city": "太原", + "area": 140, + "rooms": 3, + "school": 2, + "style": 2, + "price": 8600 + },] \ No newline at end of file diff --git "a/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/predict.py" "b/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/predict.py" new file mode 100644 index 0000000000000000000000000000000000000000..684fb5e34f9c21c470ed2acee0b03416f8b160e9 --- /dev/null +++ "b/\350\275\257\345\267\2451\347\217\255\347\231\275\351\234\262\351\234\262/7.5/predict.py" @@ -0,0 +1,28 @@ + +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([2,100,2,1,1]))) \ No newline at end of file