diff --git a/soft/__pycache__/datas.cpython-312.pyc b/soft/__pycache__/datas.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e5c6abc359d463a06693595ba94a97eb94fda38a Binary files /dev/null and b/soft/__pycache__/datas.cpython-312.pyc differ diff --git a/soft/datas.py b/soft/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..7f8fcc5b2474566d9115ef319bcf98faebeb87b5 --- /dev/null +++ b/soft/datas.py @@ -0,0 +1,35 @@ +datas=[ + +{ + "city":"吕梁", + "area":"100", + "rooms":"2", + "school":"1", + "style":"1", + "price":8000, +}, +{ + "city":"吕梁", + "area":"100", + "rooms":"2", + "school":"1", + "style":"1", + "price":8000, +}, +{ + "city":"太原", + "area":"100", + "rooms":"2", + "school":"1", + "style":"1", + "price":8000, +}, +{ + "city":"太原", + "area":"200", + "rooms":"2", + "school":"1", + "style":"0", + "price":9000, +} + ] \ No newline at end of file diff --git a/soft/predict.py b/soft/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..ce599595853ef371aa098a083a5d7581dcaf012b --- /dev/null +++ b/soft/predict.py @@ -0,0 +1,29 @@ +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, dtype=float) +Y = np.array(Y, dtype=float) +print(X) +print(Y) +theta = np.linalg.pinv(X.T.dot(X)).dot(X.T).dot(Y) +print(theta) + +prediction = theta.dot(np.array([2, 100, 2, 1, 1])) +print(prediction)