Skip to content

Commit

Permalink
added model tunning into dvc pipeline and execute it
Browse files Browse the repository at this point in the history
  • Loading branch information
ronylpatil committed Sep 28, 2024
1 parent 17b60c5 commit 294bb68
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
32 changes: 30 additions & 2 deletions dvc.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ stages:
size: 1932798
- path: ./src/models/train_model.py
hash: md5
md5: 19e77eb2eec71235661cbea2f088c3d6
size: 16692
md5: 90f6f48a40e04b569de4dfe36fc48c71
size: 16665
params:
params.yaml:
base.target: Time_taken(min)
Expand Down Expand Up @@ -145,3 +145,31 @@ stages:
hash: md5
md5: 4804de180ead9bca13523f33d5e725b0
size: 866646
tune_model:
cmd: python ./src/models/tune_model.py
deps:
- path: ./data/processed/processed_test.csv
hash: md5
md5: 8fbf4dba54f10d8f1c9d6b1c85b81041
size: 435216
- path: ./data/processed/processed_train.csv
hash: md5
md5: ae10fc577ecbf3cfe7311c1af6e59e2c
size: 1932798
- path: ./src/models/tune_model.py
hash: md5
md5: 9f7e26afd8ac368de8c0de728cdd0fb2
size: 7639
params:
params.yaml:
base.target: Time_taken(min)
feature_engineering.export_path: /data/processed
mlflow.repo_name: delivery-time-estm
mlflow.repo_owner: ronylpatil
tune_model.model_name: xgb_tunned
tune_model.n_trials: 50
outs:
- path: ./models/xgb_tunned.joblib
hash: md5
md5: e45b2fd0bfcb258d1b3fa27cfdc77132
size: 253468
16 changes: 16 additions & 0 deletions dvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,19 @@ stages:
- train_model.xgb
outs:
- ./models/${train_model.model_name}.joblib

tune_model:
cmd: python ./src/models/tune_model.py
deps:
- ./src/models/tune_model.py
- .${feature_engineering.export_path}/${feature_engineering.filename_train}.csv
- .${feature_engineering.export_path}/${feature_engineering.filename_test}.csv
params:
- base.target
- feature_engineering.export_path
- mlflow.repo_name
- mlflow.repo_owner
- tune_model.model_name
- tune_model.n_trials
outs:
- ./models/${tune_model.model_name}.joblib
1 change: 1 addition & 0 deletions models/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/model_rf.joblib
/xgb_tunned.joblib
4 changes: 4 additions & 0 deletions params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ train_model:
max_depth: 7 # {}
lambda: 1
alpha: 0

tune_model:
model_name: xgb_tunned
n_trials: 50
4 changes: 2 additions & 2 deletions src/models/tune_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def objective_xgb(trial) -> float:

# Perform 3-fold cross-validation and calculate accuracy
score = cross_val_score(
model, x_train, y_train, cv=5, scoring="neg_mean_squared_error"
model, x_train, y_train, cv=5, scoring="neg_mean_absolute_error"
).mean()

return score # Return the accuracy score for Optuna to maximize
Expand Down Expand Up @@ -182,7 +182,7 @@ def objective_xgb(trial) -> float:
mlflow.sklearn.log_model(best_model, "tunned xgbR", signature=signature)
mlflow.set_tag("developer", "ronil")
mlflow.set_tag("model", "xgbR")
mlflow.set_tag("objective", "neg_mean_squared_error")
mlflow.set_tag("objective", "neg_mean_absolute_error")
infologger.info("Experiment tracked successfully.")

save_model(
Expand Down

0 comments on commit 294bb68

Please sign in to comment.