-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
166 lines (124 loc) · 5.57 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#################################################################################
# GLOBALS #
#################################################################################
PROJECT_NAME = credit-score-modelling
PYTHON_VERSION = 3.10
PYTHON_INTERPRETER = python
#################################################################################
# COMMANDS #
#################################################################################
## Install Python Dependencies
.PHONY: requirements
requirements:
$(PYTHON_INTERPRETER) -m pip install -U pip
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
## Delete all compiled Python files
.PHONY: clean
clean:
find . -type f -name "*.py[co]" -delete
find . -type d -name "__pycache__" -delete
## Lint using flake8 and black (use `make format` to do formatting)
.PHONY: lint
lint:
flake8 credit_score_modelling
isort --check --diff --profile black credit_score_modelling
black --check --config pyproject.toml credit_score_modelling
## Format source code with black
.PHONY: format
format:
black --config pyproject.toml credit_score_modelling
## Set up python interpreter environment
.PHONY: create_environment
create_environment:
conda create --name $(PROJECT_NAME) python=$(PYTHON_VERSION) -y
@echo ">>> conda env created. Activate with:\nconda activate $(PROJECT_NAME)"
## Create a ipykernel
.PHONY: create_ipykernel
create_ipykernel: requirements
$(PYTHON_INTERPRETER) -m pip install ipykernel
$(PYTHON_INTERPRETER) -m ipykernel install --user --name $(PROJECT_NAME) --display-name "$(PROJECT_NAME) (Python $(PYTHON_VERSION))"
@echo ">>> ipykernel created"
## Create a documentation using numpydoc format
.PHONY: pyment_generate_doc
pyment_generate_doc:
pyment -w -o $(DOC_FORMAT) $(PYTHON_FILE)
@echo ">>> $(DOC_FORMAT) documentation generated"
## Update requirements.text
.PHONY: update_requirements
update_requirements:
echo '-e .' >requirements.txt
pip-chill >> requirements.txt
@echo ">>> requirements.txt updated"
#################################################################################
# MODELLING #
#################################################################################
## Data Preprocessing
.PHONY: data_preprocessing
data_preprocessing:
$(PYTHON_INTERPRETER) credit_score_modelling/data_preprocessing.py
@echo ">>> Data preprocessing completed"
## Train model
.PHONY: train
train:
$(PYTHON_INTERPRETER) credit_score_modelling/modeling/train.py
@echo ">>> Training completed"
## Evaluation
.PHONY: eval
eval:
$(PYTHON_INTERPRETER) credit_score_modelling/modeling/evaluate.py
echo '## Model Train Metrics' > report.md
cat ./reports/train_metrics.json >> report.md
echo '\n' >> report.md
echo '## Train Calibration Plot' >> report.md
echo '![Train Calibration Plot](./reports/figures/train_calibration_curve.png)' >> report.md
echo '## Model Test Metrics' >> report.md
cat ./reports/test_metrics.json >> report.md
echo '\n' >> report.md
echo '## Test Calibration Plot' >> report.md
echo '![Test Calibration Plot](./reports/figures/test_calibration_curve.png)' >> report.md
cml comment create report.md
@echo '>>> Model evaluation completed'
## Push code to the update branch
.PHONY: update-branch
update-branch:
git config --global user.name $(USER_NAME)
git config --global user.email $(USER_EMAIL)
git commit add .
git commit -m "Update with new results"
git push --force origin HEAD:update
#################################################################################
# DEPLOYMENT #
#################################################################################
.PHONY: hf-login
hf-login:
pip install -U "huggingface_hub[cli]"
huggingface-cli login --token $(HF) --add-to-git-credential
.PHONY: push-hub
push-hub:
huggingface-cli upload marcellinus-witarsah/credit-score-app ./app.py --repo-type=space --commit-message="Sync App files"
huggingface-cli upload marcellinus-witarsah/credit-score-app ./models /models --repo-type=space --commit-message="Sync Model"
huggingface-cli upload marcellinus-witarsah/credit-score-app ./credit_score_modelling /credit_score_modelling --repo-type=space --commit-message="Sync Credit Score Modelling Package"
huggingface-cli upload marcellinus-witarsah/credit-score-app ./pyproject.toml /pyproject.toml --repo-type=space --commit-message="Sync pyproject.toml"
.PHONY: deploy
deploy: hf-login push-hub
#################################################################################
# PROJECT RULES #
#################################################################################
## Make Dataset
.PHONY: data
data: requirements
$(PYTHON_INTERPRETER) credit_score_modelling/dataset.py
#################################################################################
# Self Documenting Commands #
#################################################################################
.DEFAULT_GOAL := help
define PRINT_HELP_PYSCRIPT
import re, sys; \
lines = '\n'.join([line for line in sys.stdin]); \
matches = re.findall(r'\n## (.*)\n[\s\S]+?\n([a-zA-Z_-]+):', lines); \
print('Available rules:\n'); \
print('\n'.join(['{:25}{}'.format(*reversed(match)) for match in matches]))
endef
export PRINT_HELP_PYSCRIPT
help:
@$(PYTHON_INTERPRETER) -c "${PRINT_HELP_PYSCRIPT}" < $(MAKEFILE_LIST)