File size: 943 Bytes
51abf05
 
 
8c9dd24
51abf05
8c9dd24
 
51abf05
 
8c9dd24
51abf05
8c9dd24
51abf05
 
 
8c9dd24
51abf05
 
 
 
8c9dd24
 
51abf05
 
 
 
8c9dd24
51abf05
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import joblib
import pandas as pd

# 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