File size: 3,826 Bytes
d4d9252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import streamlit as st
import joblib
import numpy as np
import pandas as pd

# Set page configuration
st.set_page_config(
    page_title="Engine Predictive Maintenance",
    page_icon="⚙️",
    layout="wide"
)

# Load the trained model
@st.cache_resource
def load_model():
    model = joblib.load('best_xgboost_model.pkl')
    return model

model = load_model()

# Title and description
st.title("⚙️ Engine Predictive Maintenance System")
st.markdown("""

This application predicts whether an engine is **Normal** or **Faulty** based on sensor readings.

Enter the sensor values below to get a prediction.

""")

# Create two columns for better layout
col1, col2 = st.columns(2)

with col1:
    st.subheader("📊 Input Sensor Readings")

    # Input fields for the 6 features
    engine_rpm = st.number_input(
        "Engine RPM",
        min_value=0.0,
        max_value=10000.0,
        value=2000.0,
        step=100.0,
        help="Engine Revolutions Per Minute"
    )

    lub_oil_pressure = st.number_input(
        "Lub Oil Pressure (psi)",
        min_value=0.0,
        max_value=200.0,
        value=50.0,
        step=1.0,
        help="Lubricating Oil Pressure"
    )

    fuel_pressure = st.number_input(
        "Fuel Pressure (psi)",
        min_value=0.0,
        max_value=200.0,
        value=50.0,
        step=1.0,
        help="Fuel Pressure"
    )

with col2:
    st.subheader("🌡️ Temperature & Pressure")

    coolant_pressure = st.number_input(
        "Coolant Pressure (psi)",
        min_value=0.0,
        max_value=200.0,
        value=50.0,
        step=1.0,
        help="Coolant Pressure"
    )

    lub_oil_temp = st.number_input(
        "Lub Oil Temperature (°C)",
        min_value=0.0,
        max_value=200.0,
        value=80.0,
        step=1.0,
        help="Lubricating Oil Temperature"
    )

    coolant_temp = st.number_input(
        "Coolant Temperature (°C)",
        min_value=0.0,
        max_value=150.0,
        value=70.0,
        step=1.0,
        help="Coolant Temperature"
    )

# Predict button
if st.button("🔍 Predict Engine Condition", type="primary"):
    # Create input array with the correct feature order
    input_data = np.array([[
        engine_rpm,
        lub_oil_pressure,
        fuel_pressure,
        coolant_pressure,
        lub_oil_temp,
        coolant_temp
    ]])

    # Make prediction
    prediction = model.predict(input_data)[0]
    prediction_proba = model.predict_proba(input_data)[0]

    # Display results
    st.markdown("---")
    st.subheader("Prediction Result")

    if prediction == 0:
        st.success("**Engine Status: NORMAL**")
        st.metric("Confidence", f"{prediction_proba[0]*100:.2f}%")
        st.info("The engine is operating within normal parameters. Continue regular maintenance schedule.")
    else:
        st.error("**Engine Status: FAULTY**")
        st.metric("Confidence", f"{prediction_proba[1]*100:.2f}%")
        st.warning("The engine shows signs of potential failure. Immediate inspection recommended!")

    # Show probability distribution
    st.markdown("### Prediction Probabilities")
    prob_df = pd.DataFrame({
        'Condition': ['Normal', 'Faulty'],
        'Probability': [prediction_proba[0], prediction_proba[1]]
    })
    st.bar_chart(prob_df.set_index('Condition'))

# Add footer with information
st.markdown("---")
st.markdown("""

**Model Information:**

- Algorithm: XGBoost Classifier

- F1-Score: 0.7630

- Recall: 87.01%

- Training Dataset: 19,535 engine records



**Features Used:**

1. Engine RPM

2. Lubricating Oil Pressure

3. Fuel Pressure

4. Coolant Pressure

5. Lubricating Oil Temperature

6. Coolant Temperature

""")