Machine Learning in Production with Python
Background Context:
In this code-along session, we will work with a dataset from a Portuguese banking institution's direct marketing campaigns, sourced from Kaggle. The dataset contains information about various marketing efforts, including telephonic outreach, aimed at promoting term deposits. Term deposits are significant for banks as they provide a stable income stream. Identifying and targeting potential customers effectively can enhance marketing efficiency and reduce costs.
https://www.kaggle.com/datasets/prakharrathi25/banking-dataset-marketing-targets/data
Tasks Covered:
-
Feature Engineering:
- We will develope functions to enhance the DataFrame with new features.
- These functions were combined into a streamlined data transformation process using the Pandas
pipe
method.
-
Unit Testing:
- We implemented unit tests using the
pytest
framework to ensure the new features were correctly added to the DataFrame. - The tests verified that the new columns were accurately calculated and correctly incorporated into the DataFrame.
- We implemented unit tests using the
Overall, this session provided practical experience in enhancing a dataset with valuable features and ensuring the robustness of these enhancements through thorough testing.
To ensure a clean and isolated development environment, use a
virtual environment created with venv
and manage dependencies using
pyproject.toml
.
Additionally, set up pre-commit hooks for code quality checks, including linting with Ruff.
Create and activate a virtual environment:
python -m venv venv
venv\Scripts\activate
Once inside the virtual environment, install project dependencies from the pyproject.toml
file:
pip install -e .
Poetry and pip-tools are excellent package managers. As pip won't necessarily handle all dependencies and constraints as effectively as package managers
Use pre-commit
to enforce code quality standards.
Additionally, use ruff
for linting.
Both packages are in the pyproject.toml
file for install.
Navigate to your project directory and set up pre-commit hooks:
pre-commit install
A .pre-commit-config.yaml
file is in project directory with config for
ruff linting. Whenever you make a commit, pre-commit
will run linting
with Ruff and enforce code quality standards automatically.