ositamiles commited on
Commit
2df06fd
·
verified ·
1 Parent(s): 7e3da9e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -2,16 +2,29 @@ import streamlit as st
2
  import numpy as np
3
  import pandas as pd
4
  import tensorflow as tf
5
- from sklearn.preprocessing import StandardScaler
6
  import joblib
7
 
8
  # Load the trained model
9
  model = tf.keras.models.load_model('trained_game_price_model.h5')
10
 
 
 
 
 
11
  # Function to preprocess the input data
12
- def preprocess_input(data, scaler):
13
  # Convert input into DataFrame for processing
14
- input_data = pd.DataFrame([data])
 
 
 
 
 
 
 
 
 
15
 
16
  # Scale the features
17
  input_data_scaled = scaler.transform(input_data)
@@ -21,16 +34,13 @@ def preprocess_input(data, scaler):
21
  # Function to make a prediction
22
  def make_prediction(input_data):
23
  # Preprocess the data for the model
24
- input_data_scaled = preprocess_input(input_data, scaler)
25
 
26
  # Make prediction
27
  prediction = model.predict(input_data_scaled)
28
 
29
  return prediction[0][0]
30
 
31
- # Load pre-trained StandardScaler
32
- scaler = joblib.load('scaler.pkl')
33
-
34
  # Streamlit application
35
  st.title("Dynamic Game Price Prediction App")
36
 
@@ -63,7 +73,6 @@ if submitted:
63
  'target_platform': target_platform,
64
  'total_sales': total_sales,
65
  'initial_price': initial_price,
66
- 'revenue': revenue,
67
  'avg_market_price': avg_market_price,
68
  'market_saturation': market_saturation / 100, # Convert to 0-1 scale
69
  'user_rating': user_rating
 
2
  import numpy as np
3
  import pandas as pd
4
  import tensorflow as tf
5
+ from sklearn.preprocessing import OneHotEncoder, StandardScaler
6
  import joblib
7
 
8
  # Load the trained model
9
  model = tf.keras.models.load_model('trained_game_price_model.h5')
10
 
11
+ # Load pre-trained OneHotEncoder and StandardScaler (assuming you have these saved)
12
+ ohe = joblib.load('ohe.pkl') # Load the OneHotEncoder
13
+ scaler = joblib.load('scaler.pkl') # Load the StandardScaler
14
+
15
  # Function to preprocess the input data
16
+ def preprocess_input(data, ohe, scaler):
17
  # Convert input into DataFrame for processing
18
+ input_data = pd.DataFrame([data], columns=['genre', 'target_platform', 'total_sales', 'initial_price', 'avg_market_price', 'market_saturation', 'user_rating'])
19
+
20
+ # Apply OneHotEncoder for categorical features
21
+ input_data_transformed = ohe.transform(input_data[['genre', 'target_platform']])
22
+
23
+ # Ensure numerical features are 2D
24
+ numerical_features = input_data[['total_sales', 'initial_price', 'avg_market_price', 'market_saturation', 'user_rating']].values
25
+
26
+ # Merge with numerical features
27
+ input_data = np.hstack((input_data_transformed.toarray(), numerical_features))
28
 
29
  # Scale the features
30
  input_data_scaled = scaler.transform(input_data)
 
34
  # Function to make a prediction
35
  def make_prediction(input_data):
36
  # Preprocess the data for the model
37
+ input_data_scaled = preprocess_input(input_data, ohe, scaler)
38
 
39
  # Make prediction
40
  prediction = model.predict(input_data_scaled)
41
 
42
  return prediction[0][0]
43
 
 
 
 
44
  # Streamlit application
45
  st.title("Dynamic Game Price Prediction App")
46
 
 
73
  'target_platform': target_platform,
74
  'total_sales': total_sales,
75
  'initial_price': initial_price,
 
76
  'avg_market_price': avg_market_price,
77
  'market_saturation': market_saturation / 100, # Convert to 0-1 scale
78
  'user_rating': user_rating