diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..35410cacdc5e87f985c93a96520f5e11a5c822e4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..2a01189048dd51552f6ba99bf21b7c67f3613c98 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..e15ec35fe054f3b2c7c21e3dcca866d6a79ca0ba --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pythonProject.iml b/.idea/pythonProject.iml new file mode 100644 index 0000000000000000000000000000000000000000..74d515a027de98657e9d3d5f0f1831882fd81374 --- /dev/null +++ b/.idea/pythonProject.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git "a/320/\346\210\277\344\273\267\351\242\204\346\265\213\347\263\273\347\273\237\345\210\230\346\226\260\345\256\207.docx" "b/320/\346\210\277\344\273\267\351\242\204\346\265\213\347\263\273\347\273\237\345\210\230\346\226\260\345\256\207.docx" new file mode 100644 index 0000000000000000000000000000000000000000..2525260b68ac70dc11198f2e7ff9b9194ca86a76 Binary files /dev/null and "b/320/\346\210\277\344\273\267\351\242\204\346\265\213\347\263\273\347\273\237\345\210\230\346\226\260\345\256\207.docx" differ diff --git a/datas.py b/datas.py new file mode 100644 index 0000000000000000000000000000000000000000..8ba7d2fa714e1a640b5c0fd464d39cf226e715b0 --- /dev/null +++ b/datas.py @@ -0,0 +1,9 @@ +# data.py +import numpy as np + +# 示例数据,实际应用中应从数据库或文件读取 +years = np.array([1950, 1960, 1970, 1980, 1990, 2000, 2010]) +population = np.array([2.53, 3.02, 3.68, 4.45, 5.27, 6.07, 6.9]) + +# 计算斜率和截距以拟合线性回归模型 +slope, intercept = np.polyfit(years, population, 1) \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000000000000000000000000000000000000..fe3c9ef0c44c893d4e5f52a65266e9c290b56a79 --- /dev/null +++ b/index.html @@ -0,0 +1,54 @@ + + + + + 人口数量预测 + + + + +

人口数量预测

+
+ + + + + +
+ +
+ + + + + \ No newline at end of file diff --git a/predict.py b/predict.py new file mode 100644 index 0000000000000000000000000000000000000000..4e3e368263dac51e6c7bda51bda8b9df42384d1a --- /dev/null +++ b/predict.py @@ -0,0 +1,8 @@ +# predict.py +import numpy as np + + +def predict_population(start_year, end_year, slope, intercept): + years_to_predict = np.arange(start_year, end_year+1) + predicted_pop = slope * years_to_predict + intercept + return years_to_predict, predicted_pop \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 0000000000000000000000000000000000000000..fea255775b8c0d13e2f7a5fe4b88971fdf845849 --- /dev/null +++ b/server.py @@ -0,0 +1,24 @@ +# app.py +from flask import Flask, jsonify, request +import predict + +app = Flask(__name__) + + +@app.route('/predict', methods=['POST']) +def predict_api(): + data = request.get_json() + start_year = data['start_year'] + end_year = data['end_year'] + + years, predicted_pop = predict.predict_population(start_year, end_year, predict.slope, predict.intercept) + + response = { + 'years': years.tolist(), + 'predicted_population': predicted_pop.tolist() + } + return jsonify(response) + + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file