ositamiles commited on
Commit
702e6f5
·
verified ·
1 Parent(s): 2df06fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -50
app.py CHANGED
@@ -8,20 +8,16 @@ import joblib
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))
@@ -41,73 +37,49 @@ def make_prediction(input_data):
41
 
42
  return prediction[0][0]
43
 
 
 
 
 
44
  # Streamlit application
45
- st.title("Dynamic Game Price Prediction App")
46
 
47
  st.write("""
48
- ### Enter the game details below to predict its optimal price.
49
- This model considers actual sales data and market trends for more accurate pricing.
50
  """)
51
 
52
  # Game details form
53
  with st.form("game_details_form"):
54
  genre = st.selectbox('Genre', ['Action', 'RPG', 'Puzzle', 'Adventure', 'Simulation', 'Strategy', 'Horror', 'Fighting', 'Sports', 'Racing', 'Casual', 'MOBA', 'Sandbox'])
55
  target_platform = st.selectbox('Platform', ['PC', 'PlayStation', 'Xbox', 'Mobile', 'Switch', 'Nintendo 3DS', 'VR', 'Web'])
56
- total_sales = st.number_input('Total Sales (units)', min_value=0, value=10000)
57
- initial_price = st.number_input('Initial Price Offering ($)', min_value=0.0, value=29.99, format="%.2f")
58
- revenue = total_sales * initial_price
59
- st.write(f"Current Revenue: ${revenue:.2f}")
60
-
61
- avg_market_price = st.number_input('Average Market Price for Similar Games ($)', min_value=0.0, value=24.99, format="%.2f")
62
- market_saturation = st.slider('Market Saturation (0-100%)', min_value=0, max_value=100, value=50)
63
- user_rating = st.slider('User Rating (0-5 stars)', min_value=0.0, max_value=5.0, value=4.0, step=0.1)
64
-
65
  # Submit button
66
- submitted = st.form_submit_button("Predict Optimal Price")
67
 
68
  # Prediction logic
69
  if submitted:
70
  # Prepare input data
71
  input_data = {
72
  'genre': genre,
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
79
  }
80
 
81
  # Make prediction
82
  predicted_price = make_prediction(input_data)
83
 
84
  # Display results
85
- st.write(f"### Predicted Optimal Price: ${predicted_price:.2f}")
86
 
87
  # Show the input details for reference
88
  st.write("#### Input Details:")
89
  st.write(f"- **Genre**: {genre}")
90
  st.write(f"- **Platform**: {target_platform}")
91
- st.write(f"- **Total Sales**: {total_sales}")
92
- st.write(f"- **Initial Price**: ${initial_price:.2f}")
93
- st.write(f"- **Current Revenue**: ${revenue:.2f}")
94
- st.write(f"- **Avg. Market Price**: ${avg_market_price:.2f}")
95
- st.write(f"- **Market Saturation**: {market_saturation}%")
96
- st.write(f"- **User Rating**: {user_rating} stars")
97
-
98
- # Provide some insights
99
- price_difference = predicted_price - initial_price
100
- if abs(price_difference) < 1:
101
- st.write("The predicted optimal price is close to your initial price. Your pricing strategy seems to be aligned with the market.")
102
- elif price_difference > 0:
103
- st.write(f"The model suggests increasing your price by ${price_difference:.2f}. This might help maximize revenue, but consider the potential impact on sales volume.")
104
- else:
105
- st.write(f"The model suggests decreasing your price by ${-price_difference:.2f}. This might help increase sales volume and overall revenue.")
106
-
107
- st.write("Remember, this is a prediction based on the provided data. Always consider other factors like marketing strategies, seasonal trends, and your specific game's unique value proposition when making pricing decisions.")
108
-
109
- # Add a note about the dynamic nature of the marketplace
110
- st.write("""
111
- #### Note on Marketplace Dynamics
112
- This prediction model takes into account current market trends and your game's performance. As the marketplace is dynamic, it's recommended to periodically reassess your pricing strategy using updated sales data and market information.
113
- """)
 
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, ohe, scaler):
13
  # Convert input into DataFrame for processing
14
+ input_data = pd.DataFrame([data], columns=['genre', 'targetPlatform', 'gamePlays', 'competitorPricing', 'currencyFluctuations'])
15
 
16
  # Apply OneHotEncoder for categorical features
17
+ input_data_transformed = ohe.transform(input_data[['genre', 'targetPlatform']])
18
 
19
  # Ensure numerical features are 2D
20
+ numerical_features = input_data[['gamePlays', 'competitorPricing', 'currencyFluctuations']].values.reshape(1, -1)
21
 
22
  # Merge with numerical features
23
  input_data = np.hstack((input_data_transformed.toarray(), numerical_features))
 
37
 
38
  return prediction[0][0]
39
 
40
+ # Load pre-trained OneHotEncoder and StandardScaler (assuming you have these saved)
41
+ ohe = joblib.load('ohe.pkl') # Load the OneHotEncoder
42
+ scaler = joblib.load('scaler.pkl') # Load the StandardScaler
43
+
44
  # Streamlit application
45
+ st.title("Game Price Prediction App")
46
 
47
  st.write("""
48
+ ### Enter the game details below to predict its price.
 
49
  """)
50
 
51
  # Game details form
52
  with st.form("game_details_form"):
53
  genre = st.selectbox('Genre', ['Action', 'RPG', 'Puzzle', 'Adventure', 'Simulation', 'Strategy', 'Horror', 'Fighting', 'Sports', 'Racing', 'Casual', 'MOBA', 'Sandbox'])
54
  target_platform = st.selectbox('Platform', ['PC', 'PlayStation', 'Xbox', 'Mobile', 'Switch', 'Nintendo 3DS', 'VR', 'Web'])
55
+ game_plays = st.number_input('Total Sales (units)', min_value=0, value=50000)
56
+ competitor_pricing = st.number_input('Competitor Pricing', min_value=0.0, value=30.0, format="%.2f")
57
+ currency_fluctuations = st.number_input('Currency Fluctuations', min_value=0.5, max_value=1.5, value=1.0, format="%.2f")
58
+
 
 
 
 
 
59
  # Submit button
60
+ submitted = st.form_submit_button("Predict Price")
61
 
62
  # Prediction logic
63
  if submitted:
64
  # Prepare input data
65
  input_data = {
66
  'genre': genre,
67
+ 'targetPlatform': target_platform,
68
+ 'gamePlays': game_plays,
69
+ 'competitorPricing': competitor_pricing,
70
+ 'currencyFluctuations': currency_fluctuations
 
 
71
  }
72
 
73
  # Make prediction
74
  predicted_price = make_prediction(input_data)
75
 
76
  # Display results
77
+ st.write(f"### Predicted Game Price: ${predicted_price:.2f}")
78
 
79
  # Show the input details for reference
80
  st.write("#### Input Details:")
81
  st.write(f"- **Genre**: {genre}")
82
  st.write(f"- **Platform**: {target_platform}")
83
+ st.write(f"- **Game Plays**: {game_plays}")
84
+ st.write(f"- **Competitor Pricing**: ${competitor_pricing:.2f}")
85
+ st.write(f"- **Currency Fluctuations**: {currency_fluctuations}")