Nagi-ovo commited on
Commit
1aa7396
·
1 Parent(s): da63474

Initial upload

Browse files
Files changed (3) hide show
  1. app.py +52 -0
  2. models/xgboost.pkl +0 -0
  3. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from sklearn.preprocessing import LabelEncoder
5
+ from sklearn.metrics import accuracy_score
6
+
7
+ def load_model(model_path):
8
+ # 加载保存的模型
9
+ model = joblib.load(model_path)
10
+ return model
11
+
12
+ def preprocess_data(uploaded_file, features):
13
+ # 读取并预处理新数据集
14
+ new_data = pd.read_csv(uploaded_file)
15
+ X_new = new_data[features]
16
+ return X_new, new_data['point_victor']
17
+
18
+ def main():
19
+ st.title('ML Model Prediction Demo with XGBoost')
20
+
21
+ # 文件上传器
22
+ uploaded_file = st.file_uploader("Upload your input CSV file", type="csv")
23
+
24
+ if uploaded_file is not None:
25
+ # 指定特征列和模型路径
26
+ features = [
27
+ 'elapsed_time', 'set_no', 'game_no', 'game_advantage', 'set_advantage',
28
+ 'p1_cumulative_distance', 'p2_cumulative_distance',
29
+ 'p1_max_continuous_scoring', 'p2_max_continuous_scoring',
30
+ 'p1_total_errors', 'p2_total_errors'
31
+ ]
32
+ model_path = './models/xgboost.pkl'
33
+
34
+ # 加载模型
35
+ xgb_model = load_model(model_path)
36
+
37
+ # 预处理数据
38
+ X_new, y_new = preprocess_data(uploaded_file, features)
39
+
40
+ # 如果目标变量也需要编码转换,确保使用与训练数据相同的方式进行转换
41
+ label_encoder = LabelEncoder()
42
+ y_new_encoded = label_encoder.fit_transform(y_new)
43
+
44
+ # 使用加载的模型进行预测
45
+ predictions = xgb_model.predict(X_new)
46
+
47
+ # 计算并显示正确率
48
+ accuracy = accuracy_score(y_new_encoded, predictions)
49
+ st.write("Accuracy on new data:", accuracy)
50
+
51
+ if __name__ == '__main__':
52
+ main()
models/xgboost.pkl ADDED
Binary file (271 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pandas
2
+ matplotlib
3
+ numpy
4
+ scipy
5
+ seaborn
6
+ scicket-learn
7
+ joblib