Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
import pickle | |
import json | |
# Load all file | |
# Load the model | |
with open('model_lin_reg.pkl', 'rb') as file_1: | |
loaded_model = pickle.load(file_1) | |
# Load the scaler model | |
with open('model_scaler.pkl', 'rb') as file_2: | |
model_scaler = pickle.load(file_2) | |
# Load the list of numerical columns | |
with open('list_num_cols.txt', 'r') as file_3: | |
list_num_cols = json.load(file_3) | |
# Load the list of categorical columns | |
with open('list_cat_cols.txt', 'r') as file_4: | |
list_cat_cols = json.load(file_4) | |
def run(): | |
with st.form(key='from_harga_saham_BBCA'): | |
open = st.number_input('open', min_value=0, max_value=100000, value=7775) | |
low = st.number_input('low', min_value=0, max_value=100000, value=6060) | |
high = st.number_input('high', min_value=0, max_value=100000, value=8050) | |
volume = st.number_input('volume', min_value=0, max_value=200000000, value=135519500) | |
st.markdown('---') | |
Tahun = st.number_input('Tahun', min_value=2020, max_value=2023, value=2020) | |
Bulan = st.number_input('Bulan', min_value=1, max_value=12, value=7) | |
Hari = st.number_input('Hari', min_value=1, max_value=31, value=28) | |
st.markdown('---') | |
Quarter_End = st.selectbox('quarter_end', ['0','1'], help='Akhir Quartal Atau Bukan') | |
Open_close = st.number_input('open-close', min_value=0, max_value=10000, value=50, help='selisih harga pembukaan dengan harga penutupan sebelumnya') | |
High_low = st.number_input('low-high', min_value=0, max_value=10000, value=-1990, help='selisih harga pembukaan dengan harga penutupan sebelumnya') | |
G_L = st.selectbox('G/L', ['0','1'], help='0 untuk harga pembukaan lebih tinggi dari harga sebelumnya dan 1 kebalikannya') | |
submitted = st.form_submit_button('Prediksi Harga Penutupan') | |
data_inf = { | |
'open': 7780, | |
'low': 7760, | |
'high': 8050, | |
'volume': 155519500, | |
'Tahun': 2020, | |
'Bulan': 7, | |
'Hari': 28, | |
'quarter_end': 0, | |
'open-close': 0, | |
'low-high': -1990, | |
'G/L': 0 | |
} | |
data_inf = pd.DataFrame([data_inf]) | |
st.dataframe(data_inf) | |
if submitted: | |
# Split antara kolom numerik dan kategorik | |
data_inf_num = data_inf[list_num_cols] | |
data_inf_cat = data_inf[list_cat_cols] | |
# Feature Scalling | |
data_inf_num_scaled = model_scaler.transform(data_inf_num) | |
data_inf_final = np.concatenate([data_inf_num_scaled], axis=1) | |
# Prediksi menggunakan Linear regression | |
y_pred_inf = loaded_model.predict(data_inf_final) | |
harga_saham = y_pred_inf[0] | |
st.write('# Harga Penutupan : Rp', str(int(harga_saham ))) | |
if __name__== '__main__': | |
run() |