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()