Development

Author

Alfa Pradana

Checking workdir

import os
os.getcwd()
'D:\\My_Course\\Zoomcamp\\mlzoomcamp-homework\\linear_regression'
  • Use --version to find out uv version
!uv --version
uv 0.8.24 (252f88733 2025-10-07)
  • The first hash for Scikit-Learn you get in the lock file

sha256:b4fc2525eca2c69a59260f583c56a7557c6ccdf8deafdba6e060f94c1c59738e

Model

Prepare a pipeline with a dictionary vectorizer and a model.

categorical = ['lead_source']
numeric = ['number_of_courses_viewed', 'annual_income']

df[categorical] = df[categorical].fillna('NA')
df[numeric] = df[numeric].fillna(0)

train_dict = df[categorical + numeric].to_dict(orient='records')

pipeline = make_pipeline(
    DictVectorizer(),
    LogisticRegression(solver='liblinear')
)

pipeline.fit(train_dict, y_train)

Publishing to Docker hub

Dockerfile_base:

#| eval: false
FROM agrigorev/zoomcamp-model:2025
WORKDIR /code

COPY pyproject.toml pyproject.toml
RUN pip install .

COPY load_fastapi.py load_fastapi.py
COPY pipeline_v1.bin pipeline_v1.bin
COPY test.py test.py

EXPOSE 9696
ENTRYPOINT ["uvicorn", "load_fastapi:app", "--host", "0.0.0.0", "--port", "9696"]

Publishing:

#| eval: false
docker build -t hw05 .
docker run -it --rm -p 9696:9696 hw05
uv run python test.py