Spaces:
Build error
Build error
Upload 3 files
Browse files- app.py +55 -0
- random_forest_model.joblib +3 -0
- requirements.txt +10 -0
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Modeli yükle
|
| 6 |
+
model_filename = 'random_forest_model.joblib'
|
| 7 |
+
model = joblib.load(model_filename)
|
| 8 |
+
|
| 9 |
+
# Kategorik verileri manuel olarak sayılara dönüştüren bir fonksiyon
|
| 10 |
+
def encode_family(family):
|
| 11 |
+
family_mapping = {'family1': 0, 'family2': 1, 'family3': 2}
|
| 12 |
+
return family_mapping.get(family, -1) # -1, geçersiz kategori
|
| 13 |
+
|
| 14 |
+
def encode_holiday_or_weekday(holiday_or_weekday):
|
| 15 |
+
holiday_mapping = {'weekday': 0, 'holiday': 1}
|
| 16 |
+
return holiday_mapping.get(holiday_or_weekday, -1) # -1, geçersiz kategori
|
| 17 |
+
|
| 18 |
+
# Tahmin fonksiyonu
|
| 19 |
+
def predict(input_data):
|
| 20 |
+
input_df = pd.DataFrame(input_data, index=[0])
|
| 21 |
+
|
| 22 |
+
# Kategorik verileri manuel olarak dönüştür
|
| 23 |
+
input_df['family'] = input_df['family'].apply(encode_family)
|
| 24 |
+
input_df['holiday_or_weekday'] = input_df['holiday_or_weekday'].apply(encode_holiday_or_weekday)
|
| 25 |
+
|
| 26 |
+
# Modelle tahmin yap
|
| 27 |
+
prediction = model.predict(input_df)
|
| 28 |
+
return prediction[0]
|
| 29 |
+
|
| 30 |
+
# Streamlit UI
|
| 31 |
+
st.title("Sales Prediction App")
|
| 32 |
+
st.write("Enter the input features:")
|
| 33 |
+
|
| 34 |
+
# Girdi alanları
|
| 35 |
+
store_nbr = st.number_input('Store Number:', min_value=1)
|
| 36 |
+
family = st.selectbox('Family:', ['family1', 'family2', 'family3'])
|
| 37 |
+
date_conv = st.number_input('Date (YYYYMMDD):')
|
| 38 |
+
dcoilwtico = st.number_input('Oil Price (dcoilwtico):')
|
| 39 |
+
day_week = st.number_input('Day of Week (0=Monday, 6=Sunday):', min_value=0, max_value=6)
|
| 40 |
+
holiday_or_weekday = st.selectbox('Holiday or Weekday:', ['weekday', 'holiday'])
|
| 41 |
+
|
| 42 |
+
# Girdi verilerini hazırla
|
| 43 |
+
input_data = {
|
| 44 |
+
'id': 0,
|
| 45 |
+
'store_nbr': store_nbr,
|
| 46 |
+
'family': family,
|
| 47 |
+
'date_conv': date_conv,
|
| 48 |
+
'dcoilwtico': dcoilwtico,
|
| 49 |
+
'day_week': day_week,
|
| 50 |
+
'holiday_or_weekday': holiday_or_weekday,
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
if st.button('Predict'):
|
| 54 |
+
prediction = predict(input_data)
|
| 55 |
+
st.write(f'Predicted sales: {prediction:.2f}')
|
random_forest_model.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:83ec2b28535f065c788670ece08006bef51e809fa820be76c6901aa7ff6bd15e
|
| 3 |
+
size 4922600817
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|
| 3 |
+
opencv-python
|
| 4 |
+
scikit-learn
|
| 5 |
+
torch
|
| 6 |
+
torchvision
|
| 7 |
+
matplotlib
|
| 8 |
+
transformers
|
| 9 |
+
sentencepiece
|
| 10 |
+
plotly
|