Spaces:
Sleeping
Sleeping
# prediction.py | |
import joblib | |
import pandas as pd | |
from transformers import UnitPriceTransformer | |
# Load the preprocessing pipeline | |
pipeline = joblib.load('full_pipeline_with_unit_price.pkl') | |
# Load the model | |
model = joblib.load('best_model.pkl') | |
def make_prediction(input_features): | |
""" | |
Takes a dictionary of features, transforms it using the pipeline, | |
and makes a prediction with the model. | |
Parameters: | |
- input_features: dict, where keys are feature names and values are the corresponding values | |
Returns: | |
- The predicted value as a float. | |
""" | |
# Convert the input features dictionary into a DataFrame | |
features_df = pd.DataFrame([input_features]) | |
# Process features through the pipeline | |
processed_features = pipeline.transform(features_df) | |
# Make a prediction with the processed features using the model | |
prediction = model.predict(processed_features) | |
return prediction[0] # Assuming we want a single prediction value | |