-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
118 lines (100 loc) · 4.88 KB
/
Makefile
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
.PHONY: all clean-data clean-results clean-models clean-report clean-all
# download data
data/raw/raw_mushroom.csv: scripts/download_data.py
python scripts/download_data.py \
--dataset_id=848 \
--raw_path=data/raw/raw_mushroom.csv
# clean data by removing some columns and dropping missing values,
# log removed columns and missing entries in columns_to_drop.csv and missing_values_by_column.csv
data/processed/cleaned_mushroom.csv \
data/processed/columns_to_drop.csv \
results/tables/missing_values_by_column.csv: scripts/data_cleaning.py data/raw/raw_mushroom.csv
python scripts/data_cleaning.py \
--input_path=data/raw/raw_mushroom.csv \
--output_path=data/processed/cleaned_mushroom.csv \
--columns_to_drop_path=data/processed/columns_to_drop.csv \
--missing_values_path=results/tables/missing_values_by_column.csv
# Validate data according to specified schema and split into training and testing sets
results/tables/schema_validate.csv \
data/processed/mushroom_train.csv \
data/processed/mushroom_test.csv \
results/tables/numeric_correlation_matrix.csv: scripts/data_split.py data/processed/cleaned_mushroom.csv
python scripts/data_split.py \
--input_path data/processed/cleaned_mushroom.csv \
--output_dir data/processed \
--results_dir results \
--seed 123
# build and save preprocessor, save preprocessed training and testing data. Also plot target proportions
results/figures/target_variable_distribution.png \
results/models/mushroom_preprocessor.pickle \
data/processed/scaled_mushroom_train.csv \
data/processed/scaled_mushroom_test.csv : scripts/data_preprocess.py \
data/processed/cleaned_mushroom.csv \
data/processed/mushroom_train.csv \
data/processed/mushroom_test.csv
python scripts/data_preprocess.py \
--input_path data/processed/cleaned_mushroom.csv \
--output_dir data/processed \
--results_dir results \
--seed 123
# Perform exploratory data analysis on training dataset, by producing histograms of numeric features
# by target and frequency tables of categorical data
results/tables/*_summary.csv results/figures/*_histogram.png: scripts/eda.py data/processed/mushroom_train.csv
python scripts/eda.py \
--processed-training-data=data/processed/mushroom_train.csv \
--plot-to=results/figures \
--table-to=results/tables
# Build three model pipelines with the preprocessor, using KNN, SVM, and Logistic Regression classifiers.
# Tune each model using cross validation on the training data, and select the model with the best F2 score.
# Record cross-validation results and save the selected best model. Also save the confusion matrix for the best model.
results/tables/cross_val_results.csv \
results/models/mushroom_best_model.pickle \
results/figures/train_confusion_matrix.png: scripts/fit_mushroom_classifier.py data/processed/mushroom_train.csv
python scripts/fit_mushroom_classifier.py \
--processed-training-data=data/processed/mushroom_train.csv \
--preprocessor=results/models/mushroom_preprocessor.pickle \
--pipeline-to=results/models \
--results-to=results \
--seed=123
# Evaluate the model performance on the test data, output final scores and test confusion matrix
results/tables/test_confusion_matrix.csv \
results/tables/test_scores.csv: scripts/evaluate_mushroom_predictor.py data/processed/mushroom_test.csv results/models/mushroom_best_model.pickle
python scripts/evaluate_mushroom_predictor.py \
--cleaned-test-data=data/processed/mushroom_test.csv \
--pipeline-from=results/models/mushroom_best_model.pickle \
--results-to=results \
--seed=123
# Render report to HTML and PDF
report/mushroom_classifier_report.html report/mushroom_classifier_report.pdf: report/mushroom_classifier_report.qmd \
report/references.bib \
data/processed/cleaned_mushroom.csv \
data/processed/columns_to_drop.csv \
results/tables/numeric_correlation_matrix.csv \
results/figures/target_variable_distribution.png \
results/tables/*_summary.csv \
results/figures/*_histogram.png \
results/tables/cross_val_results.csv \
results/figures/train_confusion_matrix.png \
results/tables/test_confusion_matrix.csv \
results/tables/test_scores.csv
quarto render report/mushroom_classifier_report.qmd --to pdf
quarto render report/mushroom_classifier_report.qmd --to html
# run entire analysis
all: report/mushroom_classifier_report.html report/mushroom_classifier_report.pdf
# remove preprocessed data (do not delete raw data in case it becomes unavailable in the future!)
clean-data:
rm -r data/processed/*
# remove all tables,figures, etc.
clean-results:
rm -r results/figures/*
rm -r results/tables/*
# remove model and preprocessor
clean-models:
rm -r results/models/*
# remove rendered reports
clean-report:
rm -rf report/mushroom_classifier_report.html \
report/mushroom_classifier_report.pdf \
report/mushroom_classifier_report_files
# remove all analysis output
clean-all: clean-data clean-results clean-models clean-report