Skip to content

Commit

Permalink
added signature in mlflow example input
Browse files Browse the repository at this point in the history
  • Loading branch information
pritesh2000 committed Aug 6, 2024
1 parent 6a444c0 commit af0eeef
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
FROM python:3.10-slim

RUN apt update -y && apt install awscli -y
RUN apt update -y && apt install awscli -y git

# Set the Git executable path for GitPython
ENV GIT_PYTHON_GIT_EXECUTABLE=/usr/bin/git

WORKDIR /app

# Create a virtual environment
RUN python3 -m venv /opt/venv

# Activate the virtual environment
ENV PATH="/opt/venv/bin:$PATH"

COPY . /app
RUN pip install -r requirements.txt

Expand Down
36 changes: 34 additions & 2 deletions src/mlProject/components/model_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from mlProject.entity.config_entity import ModelEvaluationConfig
from pathlib import Path
from mlProject.utils.common import save_json
from mlflow.models import ModelSignature
from mlflow.types import Schema, ColSpec

class ModelEvaluation:
def __init__(self, config: ModelEvaluationConfig):
Expand All @@ -28,6 +30,27 @@ def log_into_mlflow(self):

test_x = test_data.drop([self.config.target_column], axis=1)
test_y = test_data[[self.config.target_column]]

# Create an input example (this should match your model's input shape)
input_example = test_data.drop([self.config.target_column], axis=1).iloc[0:1] # Take the first row as an example

# Define the model signature
input_schema = Schema([
ColSpec("float", "fixed acidity"), # Replace with your actual feature names and types
ColSpec("float", "volatile acidity"),
ColSpec("float", "citric acid"),
ColSpec("float", "residual sugar"),
ColSpec("float", "chlorides"),
ColSpec("float", "free sulfur dioxide"),
ColSpec("float", "total sulfur dioxide"),
ColSpec("float", "density"),
ColSpec("float", "pH"),
ColSpec("float", "sulphates"),
ColSpec("float", "alcohol"),
])

# Create the model signature
signature = ModelSignature(inputs=input_schema)

mlflow.set_registry_uri(self.config.mlflow_uri)
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
Expand Down Expand Up @@ -55,6 +78,15 @@ def log_into_mlflow(self):
# There are other ways to use the Model Registry, which depends on the use case,
# Please refer to the doc for more information
# https://mlflow.org/docs/latest/model-registry.html#api-workflow
mlflow.sklearn.log_model(model, "model", registered_model_name = "ElasticnetModel")
mlflow.sklearn.log_model(model,
"model",
registered_model_name = "ElasticnetModel",
signature=signature,
input_example=input_example.to_dict(orient="records")[0]
)
else:
mlflow.sklearn.log_model(model, "model")
mlflow.sklearn.log_model(model,
"model",
signature=signature,
input_example=input_example.to_dict(orient="records")[0]
)

0 comments on commit af0eeef

Please sign in to comment.