diff --git a/pythonProject/.idea/.gitignore b/pythonProject/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..35410cacdc5e87f985c93a96520f5e11a5c822e4 --- /dev/null +++ b/pythonProject/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/pythonProject/.idea/inspectionProfiles/profiles_settings.xml b/pythonProject/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99 --- /dev/null +++ b/pythonProject/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/pythonProject/.idea/misc.xml b/pythonProject/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..2a01189048dd51552f6ba99bf21b7c67f3613c98 --- /dev/null +++ b/pythonProject/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/modules.xml b/pythonProject/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..e15ec35fe054f3b2c7c21e3dcca866d6a79ca0ba --- /dev/null +++ b/pythonProject/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/pythonProject/.idea/pythonProject.iml b/pythonProject/.idea/pythonProject.iml new file mode 100644 index 0000000000000000000000000000000000000000..74d515a027de98657e9d3d5f0f1831882fd81374 --- /dev/null +++ b/pythonProject/.idea/pythonProject.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/pythonProject/datas.py b/pythonProject/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..e512f7bbdf6cd96a9074fc78cbd66c02206f64e5 --- /dev/null +++ b/pythonProject/datas.py @@ -0,0 +1,82 @@ +datas = [ + { +#吕梁第一类房子 + "city":"吕梁", + "area":100, + "room":1, + "school":1, + "style":1, + "price":8000 + }, + { + "city":"吕梁", + "area":100, + "room":1, + "school":1, + "style":1, + "price":8100 + }, + { + "city":"吕梁", + "area":100, + "room":1, + "school":1, + "style":1, + "price":8200 +}, +{ +#吕梁第二类房子 + "city":"吕梁", + "area":100, + "room":2, + "school":1, + "style":1, + "price":8100 + }, + { + "city":"吕梁", + "area":100, + "room":2, + "school":1, + "style":1, + "price":8200 + }, + { + "city":"吕梁", + "area":100, + "room":2, + "school":1, + "style":1, + "price":8300 + }, + { + #吕梁第三类房子 + "city":"吕梁", + "area":100, + "room":3, + "school":1, + "style":1, + "price":8500 + }, + { + "city":"吕梁", + "area":100, + "room":3, + "school":1, + "style":1, + "price":8700 + }, + { + "city":"吕梁", + "area":100, + "room":3, + "school":1, + "style":1, + "price":8900 + }, + { + + + + +}] diff --git a/pythonProject/predict.py b/pythonProject/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..32035ad9636ccbdf93b4d30b777a77ae17278fcf --- /dev/null +++ b/pythonProject/predict.py @@ -0,0 +1,38 @@ +import numpy as np + +# 示例数据 +datas = [ + {"city":"吕梁", "area":100, "room":1, "school":1, "style":1, "price":8000}, + {"city":"吕梁", "area":100, "room":1, "school":1, "style":1, "price":8100}, + {"city":"吕梁", "area":100, "room":1, "school":1, "style":1, "price":8200}, + {"city":"吕梁", "area":100, "room":2, "school":1, "style":1, "price":8100}, + {"city":"吕梁", "area":100, "room":2, "school":1, "style":1, "price":8200}, + {"city":"吕梁", "area":100, "room":2, "school":1, "style":1, "price":8300}, + {"city":"吕梁", "area":100, "room":3, "school":1, "style":1, "price":8500}, + {"city":"吕梁", "area":100, "room":3, "school":1, "style":1, "price":8700}, + {"city":"吕梁", "area":100, "room":3, "school":1, "style":1, "price":8900} +] + +# 特征和目标变量提取 +features = np.array([[data["area"], data["room"], data["school"], data["style"]] for data in datas]) +prices = np.array([data["price"] for data in datas]) + +# 扩展特征矩阵,添加一列1(偏置项) +X = np.column_stack((np.ones(len(features)), features)) + +# 手动实现多元线性回归 +# 计算正规方程的解 +theta = np.linalg.inv(X.T.dot(X)).dot(X.T).dot(prices) + +# 预测函数 +def predict_price(area, room, school, style): + input_features = np.array([1, area, room, school, style]) + return input_features.dot(theta) + +# 测试预测 +test_area = 100 +test_room = 2 +test_school = 7 +test_style = 4 +predicted_price = predict_price(test_area, test_room, test_school, test_style) +print(f"预测的房价(基于面积、房间数、学校评分、装修度):{predicted_price}") \ No newline at end of file