File size: 1,602 Bytes
664ba05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Mengimpor library
import pandas as pd
import streamlit as st
import pickle

# Menghilangkan warning
import warnings
warnings.filterwarnings("ignore")

# Menulis judul
st.markdown("<h1 style='text-align: center; '> Model Regresi </h1>", unsafe_allow_html=True)
st.markdown('---'*10)


# Fungsi untuk prediksi
def final_prediction(values, model):
    global prediction
    prediction = model.predict(values)
    return prediction

# Ini merupakan fungsi utama
def main():
    
    # Nilai awal
    rd = 150000.2
    adm = 140000.3
    mkt = 300000.1
    
    with st.container():
        col1, col2, col3 = st.columns(3)
        with col1:
            rd = st.number_input('R&D', value=rd)
        with col2:
            adm = st.number_input('Administrasi', value=adm)
        with col3:
           mkt = st.number_input('Marketing', value=mkt)
    
    
    st.markdown('---'*10)
    
    wly = st.selectbox('Lokasi', ('New York', 'California', 'Florida'))
    
    data = {
        'R&D': rd,
        'Administrasi': adm,
        'Marketing': mkt,
        'Wilayah': wly,
        }
    
    kolom = list(data.keys())
    
    df_final = pd.DataFrame([data.values()],columns=kolom)
    
    # load model
    my_model = pickle.load(open('model_regresi_terbaik.pkl', 'rb'))
    
    # Predict
    result = round(float(final_prediction(df_final, my_model)),2)
    
    st.markdown('---'*10)
    
    st.write('<center><b><h3>Predicted Profit= ', result,'</b></h3>', unsafe_allow_html=True)
           
if __name__ == '__main__':
	main()