File size: 1,300 Bytes
a1c79e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split

# Veri setini yükleme
@st.cache
def load_data():
    df = pd.read_csv("demand.csv")
    #Bos verileri doldurma
    df['Total Price'].fillna(df['Total Price'].mean(), inplace=True)
    return df



# Model eğitimi
def train_model(df, features, target):
    x = df[features]
    y = df[target]
    model = RandomForestRegressor()
    model.fit(x, y)
    return model

# Tahmin yapma
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")

    # Veri setini yükleme
    df = load_data()

    # Model eğitimi
    model = train_model(df, ['Total Price', 'Base Price'], 'Units Sold')

    # Kullanıcıdan input alınması
    total_price = st.number_input("Enter Total Price")
    base_price = st.number_input("Enter Base Price")

    # Tahmin yapma ve sonucu gösterme
    if st.button("Predict"):
        prediction = make_prediction(model, total_price, base_price)
        st.write(f"Predicted Units Sold: {prediction}")

if __name__ == "__main__":
    main()