File size: 2,551 Bytes
6bce4ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
76
77
78
import streamlit as st
import pandas as pd
import pickle

def app():
    st.header('Model Prediction')
    st.write("""
    Created by Maria Melisa Gunawan

    Airline Passenger Satisfaction Prediction
    """)

    @st.cache_data
    def fetch_data():
        # Ganti path file CSV sesuai dengan lokasi file Anda
        df = pd.read_csv('airline_passenger_satisfaction.csv')
        return df

    df = fetch_data()

    st.header('User Input Features')

    def user_input():
        online_boarding = st.slider("Online Boarding", 0, 5, 3)
        type_of_travel = st.slider("Type of Travel", 0, 1)
        inflight_entertainment = st.slider("Inflight Entertainment", 0, 5, 3)
        customer_class = st.slider("Customer Class", 0, 1, 2)
        seat_comfort = st.slider("Seat Comfort", 0, 5, 3)
        onboard_service = st.slider("Onboard Service", 0, 5, 3)
        leg_room_service = st.slider("Leg Room Service", 0, 5, 3)
        cleanliness = st.slider("Cleanliness", 0, 5, 3)
        inflight_wifi_service = st.slider("Inflight Wifi Service", 0, 5, 3)
        baggage_handling = st.slider("Baggage Handling", 0, 5, 3)
        inflight_service = st.slider("Inflight Service", 0, 5, 3)
        flight_distance = st.number_input("Flight Distance", min_value=0)
        checkin_service = st.slider("Checkin Service", 0, 5, 3)

        data = {
            'online_boarding': [online_boarding],
            'type_of_travel': [type_of_travel],
            'inflight_entertainment': [inflight_entertainment],
            'customer_class' : [customer_class],
            'seat_comfort': [seat_comfort],
            'onboard_service': [onboard_service],
            'leg_room_service': [leg_room_service],
            'cleanliness': [cleanliness],
            'inflight_wifi_service': [inflight_wifi_service],
            'baggage_handling': [baggage_handling],
            'inflight_service': [inflight_service],
            'flight_distance': [flight_distance],
            'checkin_service': [checkin_service]
        }
        features = pd.DataFrame(data)
        return features

    input_df = user_input()

    st.subheader('User Input')
    st.write(input_df)

    # Load trained model
    filename = 'best_model.pkl'
    loaded_model = pickle.load(open(filename, 'rb'))

    # Predict
    prediction = loaded_model.predict(input_df)

    if prediction == 1:
        result = 'Satisfied'
    else:
        result = 'Dissatisfied'

    st.write('Predicted Passenger Satisfaction:')
    st.write(result)

if __name__ == '__main__':
    app()