diff --git a/doc/接口文档code.md b/doc/接口文档code.md index 51a6105..a0798ab 100644 --- a/doc/接口文档code.md +++ b/doc/接口文档code.md @@ -467,17 +467,14 @@ Content-Type: application/json Request: { - "train_path": "/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/breast_cancer_20250224_170615/train_breast_cancer_20250224_170615.csv", - "val_path": "/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/breast_cancer_20250224_170615/val_breast_cancer_20250224_170615.csv", - "algorithm": "XGBClassifier", - "task_type": "classification", + "train_path": "/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/train_FD001_20250407_174421/train_train_FD001_20250407_174421.csv", + "val_path": "/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/train_FD001_20250407_174421/val_train_FD001_20250407_174421.csv", + "algorithm": "RandomForestRegressor", + "task_type": "regression", "parameters": { - "n_estimators": 100, - "learning_rate": 0.1, - "max_depth": 6, - "random_state": 42 + }, - "experiment_name": "test_post_1" + "experiment_name": "test_FD001_1" } Response: @@ -585,6 +582,18 @@ Request: "metrics": ["accuracy", "f1", "precision", "recall"] } +{ + "run_id": "bb9da59ee214462196f63b18fd715d7c", + "data_path": "/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/train_FD001_20250407_174421/train_train_FD001_20250407_174421.csv", + "output_path": "predictions/train_train_FD001_20250407_174421.csv", + "batch_size": 32, + "device": "cuda", + "return_proba": true, + "metrics": [ + "mae", "mse", "rmse" + ] +} + Response: { "status": "success", diff --git a/function/__pycache__/data_manager.cpython-39.pyc b/function/__pycache__/data_manager.cpython-39.pyc index 4d7a6bc..0f0a313 100644 Binary files a/function/__pycache__/data_manager.cpython-39.pyc and b/function/__pycache__/data_manager.cpython-39.pyc differ diff --git a/function/__pycache__/model_manager.cpython-39.pyc b/function/__pycache__/model_manager.cpython-39.pyc index 73647ac..a30ae1c 100644 Binary files a/function/__pycache__/model_manager.cpython-39.pyc and b/function/__pycache__/model_manager.cpython-39.pyc differ diff --git a/function/data_manager.py b/function/data_manager.py index 0c714ec..cb987de 100644 --- a/function/data_manager.py +++ b/function/data_manager.py @@ -343,9 +343,12 @@ class DataManager: processor = self.feature_engineering_methods[method_name](**params) - # 分离特征和标签 - features = df.drop('target', axis=1) - target = df['target'] + # # 分离特征和标签 + # features = df.drop('target', axis=1) + # target = df['target'] + target_col = df.columns[-1] + features = df.iloc[:, :-1] # 所有列除了最后一列作为特征 + target = df[target_col] # 最后一列作为目标列 # 根据不同类型的特征工程方法进行处理 if method_name in ['LabelEncoder', 'OneHotEncoder']: diff --git a/function/model_manager.py b/function/model_manager.py index b062962..278ae0a 100644 --- a/function/model_manager.py +++ b/function/model_manager.py @@ -38,7 +38,7 @@ class ModelManager: self.parameter_config = self._load_parameter_config() # 初始化MLflow客户端 - self.mlflow_uri = self.config.get('mlflow_uri', 'http://10.0.0.202:5000') + self.mlflow_uri = self.config.get('mlflow_uri', 'http://127.0.0.1:5000') mlflow.set_tracking_uri(self.mlflow_uri) self.client = MlflowClient() @@ -510,16 +510,23 @@ class ModelManager: # 加载数据 try: + X = None data = pd.read_csv(data_path) if 'label' in data.columns: y_true = data.pop('label').values has_labels = True + X = data.values elif 'target' in data.columns: y_true = data.pop('target').values has_labels = True + X = data.values else: - has_labels = False - X = data.values + # 将最后一列默认为真值 + target_col = data.columns[-1] + X = data.iloc[:, :-1] + y_true = data[target_col] + has_labels = True + except Exception as e: return { 'status': 'error', @@ -823,10 +830,12 @@ class ModelManager: } # 准备特征和标签 - X_train = train_data.drop('target', axis=1) - y_train = train_data['target'] - X_val = val_data.drop('target', axis=1) - y_val = val_data['target'] + target_col_train = train_data.columns[-1] + target_col_val = val_data.columns[-1] + X_train = train_data.iloc[:, :-1] + y_train = train_data[target_col_train] + X_val = val_data.iloc[:, :-1] + y_val = val_data[target_col_val] with mlflow.start_run() as run: # 记录基本信息 diff --git a/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/MLmodel b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/MLmodel new file mode 100644 index 0000000..0dccaaf --- /dev/null +++ b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/MLmodel @@ -0,0 +1,20 @@ +artifact_path: model +flavors: + python_function: + env: + conda: conda.yaml + virtualenv: python_env.yaml + loader_module: mlflow.sklearn + model_path: model.pkl + predict_fn: predict + python_version: 3.9.19 + sklearn: + code: null + pickled_model: model.pkl + serialization_format: cloudpickle + sklearn_version: 1.5.2 +mlflow_version: 2.20.1 +model_size_bytes: 146181674 +model_uuid: e6e9a652b1454b419a61bf14ab18e620 +run_id: bb9da59ee214462196f63b18fd715d7c +utc_time_created: '2025-04-07 10:01:44.355103' diff --git a/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/conda.yaml b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/conda.yaml new file mode 100644 index 0000000..2163d2a --- /dev/null +++ b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/conda.yaml @@ -0,0 +1,14 @@ +channels: +- conda-forge +dependencies: +- python=3.9.19 +- pip<=24.0 +- pip: + - mlflow==2.20.1 + - cloudpickle==3.1.0 + - numpy==1.26.4 + - pandas==2.2.2 + - psutil==6.0.0 + - scikit-learn==1.5.2 + - scipy==1.13.1 +name: mlflow-env diff --git a/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/model.pkl b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/model.pkl new file mode 100644 index 0000000..96046c8 Binary files /dev/null and b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/model.pkl differ diff --git a/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/python_env.yaml b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/python_env.yaml new file mode 100644 index 0000000..48af243 --- /dev/null +++ b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/python_env.yaml @@ -0,0 +1,7 @@ +python: 3.9.19 +build_dependencies: +- pip==24.0 +- setuptools==60.2.0 +- wheel==0.43.0 +dependencies: +- -r requirements.txt diff --git a/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/requirements.txt b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/requirements.txt new file mode 100644 index 0000000..7977ec8 --- /dev/null +++ b/mlartifacts/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts/model/requirements.txt @@ -0,0 +1,7 @@ +mlflow==2.20.1 +cloudpickle==3.1.0 +numpy==1.26.4 +pandas==2.2.2 +psutil==6.0.0 +scikit-learn==1.5.2 +scipy==1.13.1 \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/meta.yaml b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/meta.yaml new file mode 100644 index 0000000..4c84967 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/meta.yaml @@ -0,0 +1,15 @@ +artifact_uri: mlflow-artifacts:/403693873596104927/bb9da59ee214462196f63b18fd715d7c/artifacts +end_time: 1744020107001 +entry_point_name: '' +experiment_id: '403693873596104927' +lifecycle_stage: active +run_id: bb9da59ee214462196f63b18fd715d7c +run_name: vaunted-goose-426 +run_uuid: bb9da59ee214462196f63b18fd715d7c +source_name: '' +source_type: 4 +source_version: '' +start_time: 1744020088239 +status: 3 +tags: [] +user_id: admin-root diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/explained_variance b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/explained_variance new file mode 100644 index 0000000..2aa0ce2 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/explained_variance @@ -0,0 +1 @@ +1744020104350 0.5114799809623347 0 diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/mae b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/mae new file mode 100644 index 0000000..3fa103e --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/mae @@ -0,0 +1 @@ +1744020104339 43.59667474551624 0 diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/mse b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/mse new file mode 100644 index 0000000..75e0f32 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/mse @@ -0,0 +1 @@ +1744020104343 3082.0063123121668 0 diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/r2 b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/r2 new file mode 100644 index 0000000..fc1c41f --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/r2 @@ -0,0 +1 @@ +1744020104348 0.5106799014610408 0 diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/rmse b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/rmse new file mode 100644 index 0000000..f6beed7 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/metrics/rmse @@ -0,0 +1 @@ +1744020104345 55.51582037862871 0 diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/advantages b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/advantages new file mode 100644 index 0000000..7f495f9 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/advantages @@ -0,0 +1 @@ +['不容易过拟合,适用于复杂问题', '能够处理缺失数据'] \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/algorithm b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/algorithm new file mode 100644 index 0000000..fdec80f --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/algorithm @@ -0,0 +1 @@ +RandomForestRegressor \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/dataset_train b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/dataset_train new file mode 100644 index 0000000..5038683 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/dataset_train @@ -0,0 +1 @@ +/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/train_FD001_20250407_174421/train_train_FD001_20250407_174421.csv \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/dataset_val b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/dataset_val new file mode 100644 index 0000000..454977e --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/dataset_val @@ -0,0 +1 @@ +/home/admin-root/haotian/MLPlatform/dataset/dataset_processed/train_FD001_20250407_174421/val_train_FD001_20250407_174421.csv \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/disadvantages b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/disadvantages new file mode 100644 index 0000000..18659f2 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/disadvantages @@ -0,0 +1 @@ +['计算复杂度较高', '结果难以解释'] \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/principle b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/principle new file mode 100644 index 0000000..be2b489 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/principle @@ -0,0 +1 @@ +随机森林回归通过集成多棵决策树的结果来提高预测精度,能够处理高维数据。 \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/task_type b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/task_type new file mode 100644 index 0000000..74593ea --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/params/task_type @@ -0,0 +1 @@ +regression \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.log-model.history b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.log-model.history new file mode 100644 index 0000000..c112da8 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.log-model.history @@ -0,0 +1 @@ +[{"run_id": "bb9da59ee214462196f63b18fd715d7c", "artifact_path": "model", "utc_time_created": "2025-04-07 10:01:44.355103", "model_uuid": "e6e9a652b1454b419a61bf14ab18e620", "flavors": {"python_function": {"model_path": "model.pkl", "predict_fn": "predict", "loader_module": "mlflow.sklearn", "python_version": "3.9.19", "env": {"conda": "conda.yaml", "virtualenv": "python_env.yaml"}}, "sklearn": {"pickled_model": "model.pkl", "sklearn_version": "1.5.2", "serialization_format": "cloudpickle", "code": null}}}] \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.runName b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.runName new file mode 100644 index 0000000..3013aa0 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.runName @@ -0,0 +1 @@ +vaunted-goose-426 \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.git.commit b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.git.commit new file mode 100644 index 0000000..0234eb5 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.git.commit @@ -0,0 +1 @@ +9af1e44eba8268173b6fa731efbdac5fc55b0c96 \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.name b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.name new file mode 100644 index 0000000..11a5d8e --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.name @@ -0,0 +1 @@ +main.py \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.type b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.type new file mode 100644 index 0000000..0c2c1fe --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.source.type @@ -0,0 +1 @@ +LOCAL \ No newline at end of file diff --git a/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.user b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.user new file mode 100644 index 0000000..9c59705 --- /dev/null +++ b/mlruns/403693873596104927/bb9da59ee214462196f63b18fd715d7c/tags/mlflow.user @@ -0,0 +1 @@ +admin-root \ No newline at end of file diff --git a/mlruns/403693873596104927/meta.yaml b/mlruns/403693873596104927/meta.yaml new file mode 100644 index 0000000..e03f773 --- /dev/null +++ b/mlruns/403693873596104927/meta.yaml @@ -0,0 +1,6 @@ +artifact_location: mlflow-artifacts:/403693873596104927 +creation_time: 1744019800920 +experiment_id: '403693873596104927' +last_update_time: 1744019800920 +lifecycle_stage: active +name: test_FD001_1