File size: 3,534 Bytes
6616b86
 
f457204
 
2df06fd
f457204
5985633
f457204
9a53454
5985633
f457204
2df06fd
f457204
702e6f5
2df06fd
 
702e6f5
2df06fd
 
702e6f5
2df06fd
 
 
f457204
9a53454
f457204
 
 
5985633
f457204
 
 
2df06fd
f457204
 
 
 
 
 
702e6f5
 
 
 
f457204
702e6f5
f457204
 
702e6f5
f457204
 
 
 
 
 
02bc549
63e4296
 
 
702e6f5
 
f457204
702e6f5
f457204
 
 
9a53454
 
 
702e6f5
63e4296
702e6f5
 
9a53454
 
 
 
 
 
702e6f5
9a53454
 
 
 
 
02bc549
 
 
702e6f5
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
import numpy as np
import pandas as pd
import tensorflow as tf
from sklearn.preprocessing import OneHotEncoder, StandardScaler
import joblib

# Load the trained model
model = tf.keras.models.load_model('trained_game_price_model.h5')

# Function to preprocess the input data
def preprocess_input(data, ohe, scaler):
    # Convert input into DataFrame for processing
    input_data = pd.DataFrame([data], columns=['genre', 'targetPlatform', 'gamePlays', 'competitorPricing', 'currencyFluctuations'])
    
    # Apply OneHotEncoder for categorical features
    input_data_transformed = ohe.transform(input_data[['genre', 'targetPlatform']])
    
    # Ensure numerical features are 2D
    numerical_features = input_data[['gamePlays', 'competitorPricing', 'currencyFluctuations']].values.reshape(1, -1)
    
    # Merge with numerical features
    input_data = np.hstack((input_data_transformed.toarray(), numerical_features))
    
    # Scale the features
    input_data_scaled = scaler.transform(input_data)
    
    return input_data_scaled

# Function to make a prediction
def make_prediction(input_data):
    # Preprocess the data for the model
    input_data_scaled = preprocess_input(input_data, ohe, scaler)
    
    # Make prediction
    prediction = model.predict(input_data_scaled)
    
    return prediction[0][0]

# Load pre-trained OneHotEncoder and StandardScaler (assuming you have these saved)
ohe = joblib.load('ohe.pkl')  # Load the OneHotEncoder
scaler = joblib.load('scaler.pkl')  # Load the StandardScaler

# Streamlit application
st.title("Game Price Prediction App")

st.write("""
### Enter the game details below to predict its price.
""")

# Game details form
with st.form("game_details_form"):
    genre = st.selectbox('Genre', ['Action', 'RPG', 'Puzzle', 'Adventure', 'Simulation', 'Strategy', 'Horror', 'Fighting', 'Sports', 'Racing', 'Casual', 'MOBA', 'Sandbox'])
    target_platform = st.selectbox('Platform', ['PC', 'PlayStation', 'Xbox', 'Mobile', 'Switch', 'Nintendo 3DS', 'VR', 'Web'])
    total_sales = st.number_input('Total Sales (units)', min_value=0, value=50000)
    initial_price = st.number_input('Initial Price Offering ($)', min_value=0.0, value=29.99, format="%.2f")
    revenue = total_sales * initial_price
    competitor_pricing = st.number_input('Average Market Price for Similar Games ($)', min_value=0.0, value=30.0, format="%.2f")
    currency_fluctuations = st.number_input('Currency Fluctuations', min_value=0.5, max_value=1.5, value=1.0, format="%.2f")

    # Submit button
    submitted = st.form_submit_button("Predict Price")

# Prediction logic
if submitted:
    # Prepare input data
    input_data = {
        'genre': genre,
        'targetPlatform': target_platform,
        'gamePlays': revenue,
        'competitorPricing': competitor_pricing,
        'currencyFluctuations': currency_fluctuations
    }
    
    # Make prediction
    predicted_price = make_prediction(input_data)
    
    # Display results
    st.write(f"### Predicted Game Price: ${predicted_price:.2f}")
    
    # Show the input details for reference
    st.write("#### Input Details:")
    st.write(f"- **Genre**: {genre}")
    st.write(f"- **Platform**: {target_platform}")
    st.write(f"- **Total Sales**: {total_sales}")
    st.write(f"- **Initial Price**: ${initial_price:.2f}")
    st.write(f"- **Current Revenue**: ${revenue:.2f}")
    st.write(f"- **Competitor Pricing**: ${competitor_pricing:.2f}")
    st.write(f"- **Currency Fluctuations**: {currency_fluctuations}")