|
import streamlit as st
|
|
import pandas as pd
|
|
from sklearn.ensemble import RandomForestRegressor
|
|
from sklearn.model_selection import train_test_split
|
|
|
|
|
|
@st.cache
|
|
def load_data():
|
|
df = pd.read_csv("demand.csv")
|
|
|
|
df['Total Price'].fillna(df['Total Price'].mean(), inplace=True)
|
|
return df
|
|
|
|
|
|
|
|
|
|
def train_model(df, features, target):
|
|
x = df[features]
|
|
y = df[target]
|
|
model = RandomForestRegressor()
|
|
model.fit(x, y)
|
|
return model
|
|
|
|
|
|
def make_prediction(model, total_price, base_price):
|
|
prediction = model.predict([[total_price, base_price]])
|
|
return prediction[0]
|
|
|
|
def main():
|
|
st.title("Product Demand Prediction App")
|
|
|
|
|
|
df = load_data()
|
|
|
|
|
|
model = train_model(df, ['Total Price', 'Base Price'], 'Units Sold')
|
|
|
|
|
|
total_price = st.number_input("Enter Total Price")
|
|
base_price = st.number_input("Enter Base Price")
|
|
|
|
|
|
if st.button("Predict"):
|
|
prediction = make_prediction(model, total_price, base_price)
|
|
st.write(f"Predicted Units Sold: {prediction}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|