-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoML_LCZ_classfier.py
More file actions
42 lines (39 loc) · 1.55 KB
/
Copy pathAutoML_LCZ_classfier.py
File metadata and controls
42 lines (39 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pandas as pd
import numpy as np
from flaml import AutoML
from sklearn.model_selection import StratifiedShuffleSplit
from sklearn.metrics import accuracy_score
from sklearn.utils import resample
import joblib
import pickle
import matplotlib.pyplot as plt
# 保存 splits 到 pickle 文件
with open('your_Manchester_TA_splits.pkl', 'rb') as f:
splits = pickle.load(f)
with open('your_Manchester_TA_features.pkl', 'rb') as f:
polygon_features = pickle.load(f)
for i, (train_gdf, test_gdf) in enumerate(splits):
# 合并训练和测试数据
train_data = pd.concat([polygon_features[idx] for idx in train_gdf.index], ignore_index=True)
test_data = pd.concat([polygon_features[idx] for idx in test_gdf.index], ignore_index=True)
training_all = pd.concat([train_data, test_data], axis=0)
# 提取特征和标签
X_train = training_all.drop(['Name'], axis=1)
y_train = training_all['Name'].astype('int32')
break
# 定义 AutoML
automl = AutoML()
settings = {
"time_budget": 3600, # 时间预算
"task": "classification", # 任务类型
"metric": "accuracy", # 优化目标
"log_file_name": f"/home/jiyang/P2_LCZ/log/automl_4lcz_new_training_20250130.log"
}
# 训练模型
automl.fit(X_train=X_train.values, y_train=y_train.values, **settings)
# 保存最佳模型
model_path = f"/home/jiyang/P2_LCZ/ml_outputs/best_newRS4LCZ_Manchester_20250130.pkl"
# Save the model
with open(f"{model_path}", "wb") as f:
pickle.dump(automl, f, pickle.HIGHEST_PROTOCOL)
print(f"Model for Manchester LCZ mapping saved as {model_path}")