Milestone2P1 / prediction.py
casheu's picture
commit
be7643a
import streamlit as st
from PIL import Image
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import joblib
# Load All Files
with open('model.pkl', 'rb') as file_1:
model = joblib.load(file_1)
with open('pipeline.pkl', 'rb') as file_2:
preprocessor = joblib.load(file_2)
def run():
# Membuat Form
with st.form(key='form_parameters'):
income = st.number_input('Average Income', min_value=0, max_value=150000, value=50000, step=1000)
age = st.number_input('House Age', min_value=0, max_value=50, value=5, step=1)
rooms = st.number_input('Number of Rooms', min_value=0, max_value=25, value=5, step=1)
bedrooms = st.number_input('Number of Bedrooms', min_value=0, max_value=10, value=3, step=1)
population = st.number_input('Area Population', min_value=0, max_value=100000, value=50000, step=1000)
st.markdown('---')
submitted = st.form_submit_button('Predict')
data_inf = {
'Income': income,
'Age': age,
'Rooms': rooms,
'Bedrooms': bedrooms,
'Population': population
}
data_inf = pd.DataFrame([data_inf])
st.dataframe(data_inf)
if submitted:
# Feature Preprocessing
X_inf = preprocessor.transform(data_inf)
# Predict using Linear regression
y_pred_inf = model.predict(X_inf)
st.write('# House Price : ', str(int(y_pred_inf)))
if __name__ == '__main__':
run()