Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- .gitattributes +1 -0
- data.csv +3 -0
- final.py +223 -0
- requirements (1).txt +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
data.csv filter=lfs diff=lfs merge=lfs -text
|
data.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:263d34a56e5bcc2ef097dca34f8255968b4f3137bedd7040f65608857255db09
|
| 3 |
+
size 14799315
|
final.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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LogisticRegression
|
| 8 |
+
from sklearn.model_selection import train_test_split
|
| 9 |
+
from sklearn.metrics import accuracy_score
|
| 10 |
+
|
| 11 |
+
warnings.filterwarnings("ignore")
|
| 12 |
+
|
| 13 |
+
# Load the dataset
|
| 14 |
+
df = pd.read_csv(r"C:\Users\91879\Downloads\data.csv")
|
| 15 |
+
df.fillna(df.mean(), inplace=True)
|
| 16 |
+
|
| 17 |
+
# Create Tabs
|
| 18 |
+
tab1, tab2, tab3 = st.tabs(["π Project Overview", "π EDA", "π Fault Prediction"])
|
| 19 |
+
|
| 20 |
+
# ----------------------------- TAB 1 ---------------------------------
|
| 21 |
+
with tab1:
|
| 22 |
+
st.header("π Brake System Fault Detection")
|
| 23 |
+
st.markdown("### π§© Business Problem")
|
| 24 |
+
|
| 25 |
+
st.markdown("""
|
| 26 |
+
In the automotive industry, ensuring the safety and reliability of braking systems is **mission-critical**. Traditional brake inspections are typically **manual and reactive**, often identifying problems **only after they occur** or during scheduled maintenance.
|
| 27 |
+
|
| 28 |
+
However, undetected faults in braking systems can lead to:
|
| 29 |
+
- **Brake failure during operation**
|
| 30 |
+
- **Reduced vehicle control**
|
| 31 |
+
- **Increased risk of accidents**
|
| 32 |
+
- **Expensive emergency repairs**
|
| 33 |
+
|
| 34 |
+
Manufacturers and fleet managers need a **real-time fault detection system** using **sensor data** to:
|
| 35 |
+
- Monitor brake system health continuously
|
| 36 |
+
- **Predict faults proactively**
|
| 37 |
+
- **Minimize vehicle downtime**
|
| 38 |
+
- Enhance **safety, reliability, and cost-efficiency**
|
| 39 |
+
""")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
feature_desc = {
|
| 43 |
+
'Brake_Pressure': "Pressure applied to the brake pedal.",
|
| 44 |
+
'Pad_Wear_Level': "Indicates the wear level of brake pads.",
|
| 45 |
+
'ABS_Status': "1 if Anti-lock Braking System is active, else 0.",
|
| 46 |
+
'Wheel_Speed_FL': "Speed of the front-left wheel.",
|
| 47 |
+
'Wheel_Speed_FR': "Speed of the front-right wheel.",
|
| 48 |
+
'Wheel_Speed_RL': "Speed of the rear-left wheel.",
|
| 49 |
+
'Wheel_Speed_RR': "Speed of the rear-right wheel.",
|
| 50 |
+
'Fluid_Temperature': "Temperature of the brake fluid.",
|
| 51 |
+
'Pedal_Position': "How far the brake pedal is pressed."
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
selected = st.selectbox("Select a feature to understand:", list(feature_desc.keys()))
|
| 55 |
+
st.info(f"π **{selected}**: {feature_desc[selected]}")
|
| 56 |
+
|
| 57 |
+
# π― Goal
|
| 58 |
+
st.markdown("### π― Goal")
|
| 59 |
+
st.markdown("""
|
| 60 |
+
Build a data-driven model that detects braking system faults using sensor data such as brake pressure, wheel speeds, fluid temperature, and pedal position.
|
| 61 |
+
""")
|
| 62 |
+
|
| 63 |
+
# πΌ Business Objective
|
| 64 |
+
st.markdown("### π Business Objective")
|
| 65 |
+
st.markdown("""
|
| 66 |
+
- Detect faults early to reduce vehicle failure risks.
|
| 67 |
+
- Analyze sensor behavior during fault vs non-fault conditions.
|
| 68 |
+
- Support preventive maintenance using historical data patterns.
|
| 69 |
+
""")
|
| 70 |
+
|
| 71 |
+
st.markdown("### π Data Understanding")
|
| 72 |
+
st.markdown("""
|
| 73 |
+
The dataset contains **real-time sensor readings** collected from a vehicle's braking system to detect faults.
|
| 74 |
+
|
| 75 |
+
#### π’ Numerical Features:
|
| 76 |
+
- **Brake_Pressure**
|
| 77 |
+
- **Pad_Wear_Level**
|
| 78 |
+
- **Wheel_Speed_FL**, **Wheel_Speed_FR**, **Wheel_Speed_RL**, **Wheel_Speed_RR**
|
| 79 |
+
- **Fluid_Temperature**
|
| 80 |
+
- **Pedal_Position**
|
| 81 |
+
|
| 82 |
+
#### π Categorical Feature:
|
| 83 |
+
- **ABS_Status**: `1` = Active, `0` = Inactive
|
| 84 |
+
|
| 85 |
+
#### π― Target Variable:
|
| 86 |
+
- **Fault**: `1` = Fault Detected, `0` = No Fault
|
| 87 |
+
""")
|
| 88 |
+
|
| 89 |
+
# ----------------------------- TAB 2 ---------------------------------
|
| 90 |
+
with tab2:
|
| 91 |
+
st.title("π Exploratory Data Analysis")
|
| 92 |
+
|
| 93 |
+
st.subheader("π View Dataset Preview")
|
| 94 |
+
if st.button("π Show Dataset Head"):
|
| 95 |
+
st.dataframe(df.head())
|
| 96 |
+
|
| 97 |
+
st.subheader("β οΈ Fault Distribution")
|
| 98 |
+
fault_counts = df['Fault'].value_counts()
|
| 99 |
+
st.bar_chart(fault_counts)
|
| 100 |
+
st.write(df['Fault'].value_counts(normalize=True) * 100)
|
| 101 |
+
|
| 102 |
+
st.subheader("π Correlation Heatmap")
|
| 103 |
+
corr = df.corr()
|
| 104 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
| 105 |
+
sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm", ax=ax)
|
| 106 |
+
st.pyplot(fig)
|
| 107 |
+
|
| 108 |
+
st.markdown("### π Feature Distributions by Fault")
|
| 109 |
+
features = ['Brake_Pressure', 'Pad_Wear_Level', 'Wheel_Speed_FL', 'Wheel_Speed_FR',
|
| 110 |
+
'Wheel_Speed_RL', 'Wheel_Speed_RR', 'Fluid_Temperature', 'Pedal_Position']
|
| 111 |
+
|
| 112 |
+
for feature in features:
|
| 113 |
+
st.markdown(f"#### π {feature}")
|
| 114 |
+
fig, ax = plt.subplots()
|
| 115 |
+
sns.kdeplot(data=df, x=feature, hue="Fault", fill=True, common_norm=False, alpha=0.4, ax=ax)
|
| 116 |
+
st.pyplot(fig)
|
| 117 |
+
|
| 118 |
+
st.markdown("### π¦ Boxplots to Compare Fault vs Normal")
|
| 119 |
+
for feature in features:
|
| 120 |
+
st.markdown(f"#### π¦ {feature} vs Fault")
|
| 121 |
+
fig, ax = plt.subplots()
|
| 122 |
+
sns.boxplot(data=df, x='Fault', y=feature, palette="Set2", ax=ax)
|
| 123 |
+
st.pyplot(fig)
|
| 124 |
+
|
| 125 |
+
st.markdown("### π Scatterplots: Detect Patterns or Anomalies")
|
| 126 |
+
st.markdown("These help you check combinations of features with color-coded fault info.")
|
| 127 |
+
|
| 128 |
+
fig, ax = plt.subplots()
|
| 129 |
+
sns.scatterplot(data=df, x="Brake_Pressure", y="Pad_Wear_Level", hue="Fault", palette="Set1", ax=ax)
|
| 130 |
+
ax.set_title("Brake Pressure vs Pad Wear Level")
|
| 131 |
+
st.pyplot(fig)
|
| 132 |
+
|
| 133 |
+
fig, ax = plt.subplots()
|
| 134 |
+
sns.scatterplot(data=df, x="Pedal_Position", y="Fluid_Temperature", hue="Fault", palette="Set2", ax=ax)
|
| 135 |
+
ax.set_title("Pedal Position vs Fluid Temperature")
|
| 136 |
+
st.pyplot(fig)
|
| 137 |
+
|
| 138 |
+
# ----------------------------- TAB 3 ---------------------------------
|
| 139 |
+
with tab3:
|
| 140 |
+
st.markdown(
|
| 141 |
+
"""
|
| 142 |
+
<style>
|
| 143 |
+
.stApp {
|
| 144 |
+
background-color: #e3f2fd;
|
| 145 |
+
padding: 12px;
|
| 146 |
+
}
|
| 147 |
+
</style>
|
| 148 |
+
""",
|
| 149 |
+
unsafe_allow_html=True
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
st.markdown("## π Vehicle Brake System Fault Detection")
|
| 153 |
+
st.markdown("#### Enter Brake Sensor Values to Predict Any System Fault")
|
| 154 |
+
|
| 155 |
+
# Prepare data
|
| 156 |
+
X = df.drop("Fault", axis=1)
|
| 157 |
+
y = df["Fault"]
|
| 158 |
+
|
| 159 |
+
# UI for user input
|
| 160 |
+
Brake_Pressure = st.slider("π¨ Brake Pressure (psi)", 50.0, 500.0, step=0.1)
|
| 161 |
+
Pad_Wear_Level = st.slider("π Pad Wear Level (%)", 0.0, 100.0, step=0.1)
|
| 162 |
+
ABS_Status = st.slider("π ABS Status (0 = Off, 1 = On)", 0, 1, step=1)
|
| 163 |
+
Wheel_Speed_FL = st.slider("βοΈ Wheel Speed FL (km/h)", 0.0, 400.0, step=0.1)
|
| 164 |
+
Wheel_Speed_FR = st.slider("βοΈ Wheel Speed FR (km/h)", 0.0, 400.0, step=0.1)
|
| 165 |
+
Wheel_Speed_RL = st.slider("βοΈ Wheel Speed RL (km/h)", 0.0, 300.0, step=0.1)
|
| 166 |
+
Wheel_Speed_RR = st.slider("βοΈ Wheel Speed RR (km/h)", 0.0, 300.0, step=0.1)
|
| 167 |
+
Fluid_Temperature = st.slider("π‘οΈ Fluid Temperature (Β°C)", -20.0, 150.0, step=0.1)
|
| 168 |
+
Pedal_Position = st.slider("π¦Ά Pedal Position (%)", 0.0, 100.0, step=0.1)
|
| 169 |
+
|
| 170 |
+
# Train model
|
| 171 |
+
x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=29)
|
| 172 |
+
model = LogisticRegression()
|
| 173 |
+
model.fit(x_train, y_train)
|
| 174 |
+
|
| 175 |
+
user_input = pd.DataFrame([[Brake_Pressure, Pad_Wear_Level, ABS_Status, Wheel_Speed_FL,
|
| 176 |
+
Wheel_Speed_FR, Wheel_Speed_RL, Wheel_Speed_RR,
|
| 177 |
+
Fluid_Temperature, Pedal_Position]],
|
| 178 |
+
columns=X.columns)
|
| 179 |
+
|
| 180 |
+
if st.button("π Predict Brake Fault"):
|
| 181 |
+
y_pred = model.predict(user_input)
|
| 182 |
+
prob = model.predict_proba(user_input)[0][1]
|
| 183 |
+
|
| 184 |
+
if y_pred[0] == 1:
|
| 185 |
+
st.error(f"π¨ Fault Detected in Brake System! (Confidence: {prob:.2%})")
|
| 186 |
+
issues = []
|
| 187 |
+
|
| 188 |
+
if Brake_Pressure < 60 or Brake_Pressure > 130:
|
| 189 |
+
issues.append("π΄ Abnormal Brake Pressure")
|
| 190 |
+
|
| 191 |
+
if Pad_Wear_Level >= 80:
|
| 192 |
+
issues.append("π Brake Pads Critically Worn")
|
| 193 |
+
elif Pad_Wear_Level >= 60:
|
| 194 |
+
issues.append("π‘ Brake Pads Heavily Worn")
|
| 195 |
+
|
| 196 |
+
if ABS_Status == 0:
|
| 197 |
+
issues.append("π΅ ABS System Not Active")
|
| 198 |
+
|
| 199 |
+
if Wheel_Speed_FL < 0 or Wheel_Speed_FL > 130:
|
| 200 |
+
issues.append("π΄ Front Left Wheel Speed Abnormal")
|
| 201 |
+
if Wheel_Speed_FR < 0 or Wheel_Speed_FR > 130:
|
| 202 |
+
issues.append("π΄ Front Right Wheel Speed Abnormal")
|
| 203 |
+
if Wheel_Speed_RL < 0 or Wheel_Speed_RL > 130:
|
| 204 |
+
issues.append("π΄ Rear Left Wheel Speed Abnormal")
|
| 205 |
+
if Wheel_Speed_RR < 0 or Wheel_Speed_RR > 130:
|
| 206 |
+
issues.append("π΄ Rear Right Wheel Speed Abnormal")
|
| 207 |
+
|
| 208 |
+
if Fluid_Temperature < -20 or Fluid_Temperature > 120:
|
| 209 |
+
issues.append("π₯ Abnormal Brake Fluid Temperature")
|
| 210 |
+
|
| 211 |
+
if 20 < Pedal_Position < 60:
|
| 212 |
+
issues.append("π‘ Moderate Brake Pedal Pressed")
|
| 213 |
+
if 60 <= Pedal_Position <= 100:
|
| 214 |
+
issues.append("π Brake Pedal Fully Pressed")
|
| 215 |
+
if Pedal_Position <= 20:
|
| 216 |
+
issues.append("π Low Brake Pedal Engagement")
|
| 217 |
+
|
| 218 |
+
for issue in issues:
|
| 219 |
+
st.markdown(f"- {issue}")
|
| 220 |
+
|
| 221 |
+
else:
|
| 222 |
+
st.success(f"β
No Fault Detected. (Confidence: {1 - prob:.2%})")
|
| 223 |
+
st.info("π Your vehicle's brake system appears healthy.")
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
scikit-learn
|