Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution Christian #2

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

Conversation

christianint
Copy link

Solution for MLE challenge

christianint and others added 26 commits July 26, 2022 12:00
feat(dockerize): Creating dockerfile for create docker image
doc(solution): Included comments in main Readme.md
"""

# Paths
RAW_FILE = "data/raw/listings.csv"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intenta evitar poner paths relativos (o completos). Puedes usar Pathlib para generar paths que se ajusten a todos los entornos

@@ -0,0 +1,180 @@
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿No ves más interesante desarrollar este script como una clase preprocess? El objetivo es tener un objeto data_preprocessing donde podamos ejecutar los métodos necesarios.

@@ -0,0 +1,134 @@
"""
This file contains all test for preprocess.py
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si lo planteamos como clase, también podemos testear no solo que los métodos individualmente funcionan sino que el output es el esperado (que todos los métodos están funcionando bien juntos). Por ejemplo, si nos equivocamos en uno de los métodos y el código se carga todas las columnas salvo la que procesamos, el test sigue pasando, y todos los demás también. Si lo miramos en conjunto podemos ver que falla.


class AppSettings(BaseSettings):
app_name: str = "Inference API"
model_path: str = "models/random_forest_classifier_2022-08-04 08:31:07.734769.pkl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hubiese sido interesante hacer uso del f-string para que podamos pasar la fecha del modelo como parámetro (en Docker por ejemplo)

inference_engine = InferenceEngine(settings=settings)
app = FastAPI()


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Un punto extra hubiese sido meter algo de security, como un API token simple.

Comment on lines +56 to +64
try:
neighbourhood = self.__settings.mapping_columns["neighbourhood"][request.neighbourhood]
except KeyError as key_exc:
raise HTTPException(status_code=400, detail="Neighbourhood not valid")

try:
room_type = self.__settings.mapping_columns["room_type"][request.room_type]
except KeyError as key_exc:
raise HTTPException(status_code=400, detail="Room type not valid")
Copy link
Contributor

@mastertilla mastertilla Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Igual hubiese valido la pena escribir una función para esto ya que parece que el error es el mismo.

@@ -0,0 +1,2 @@
#! /bin/bash
python -m uvicorn api.app:app --host 0.0.0.0 --port 80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Más que un cambio es que puedes lanzar este mismo comando desde Docker, por evitar más dependencias de código.

@@ -0,0 +1,17 @@
FROM python:3.9

ENV PYTHONPATH=lab
Copy link
Contributor

@mastertilla mastertilla Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puedes añadir ENV PYTHONUNBUFFERED=1 para forzar que el stdout salga al terminal (recomendado cuando corremos Python en Docker)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants