7sugiwa commited on
Commit
8c9dd24
1 Parent(s): ae33b87

Upload 5 files

Browse files
Files changed (1) hide show
  1. prediction.py +9 -10
prediction.py CHANGED
@@ -1,31 +1,30 @@
1
- # prediction.py
2
-
3
  import joblib
4
  import pandas as pd
5
 
6
- # Load the pipeline and model
7
  pipeline = joblib.load('full_pipeline_with_unit_price.pkl')
 
 
8
  model = joblib.load('best_model.pkl')
9
 
10
- def make_prediction(features):
11
  """
12
- Takes an array of original features, transforms it using the pipeline,
13
  and makes a prediction with the model.
14
 
15
  Parameters:
16
- - features: array-like, shape [n_features]
17
 
18
  Returns:
19
  - The predicted value as a float.
20
  """
21
- # Convert the features array into a DataFrame expected by the pipeline
22
- # Note: You need to ensure the columns match those expected by the pipeline
23
- features_df = pd.DataFrame([features], columns=['sales', 'quantity', 'discount', 'sub_category'])
24
 
25
  # Process features through the pipeline
26
  processed_features = pipeline.transform(features_df)
27
 
28
- # Make a prediction
29
  prediction = model.predict(processed_features)
30
 
31
  return prediction[0] # Assuming we want a single prediction value
 
 
 
1
  import joblib
2
  import pandas as pd
3
 
4
+ # Load the preprocessing pipeline
5
  pipeline = joblib.load('full_pipeline_with_unit_price.pkl')
6
+
7
+ # Load the model
8
  model = joblib.load('best_model.pkl')
9
 
10
+ def make_prediction(input_features):
11
  """
12
+ Takes a dictionary of features, transforms it using the pipeline,
13
  and makes a prediction with the model.
14
 
15
  Parameters:
16
+ - input_features: dict, where keys are feature names and values are the corresponding values
17
 
18
  Returns:
19
  - The predicted value as a float.
20
  """
21
+ # Convert the input features dictionary into a DataFrame
22
+ features_df = pd.DataFrame([input_features])
 
23
 
24
  # Process features through the pipeline
25
  processed_features = pipeline.transform(features_df)
26
 
27
+ # Make a prediction with the processed features using the model
28
  prediction = model.predict(processed_features)
29
 
30
  return prediction[0] # Assuming we want a single prediction value