Update Streamlit app
Browse files
app.py
CHANGED
|
@@ -37,18 +37,43 @@ def load_model():
|
|
| 37 |
# FEATURE ENGINEERING FUNCTION
|
| 38 |
# ============================================
|
| 39 |
def engineer_features(df):
|
| 40 |
-
"""Apply
|
| 41 |
df_enhanced = df.copy()
|
| 42 |
-
|
| 43 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
return df_enhanced
|
| 53 |
|
| 54 |
# ============================================
|
|
|
|
| 37 |
# FEATURE ENGINEERING FUNCTION
|
| 38 |
# ============================================
|
| 39 |
def engineer_features(df):
|
| 40 |
+
"""Apply feature engineering to match training pipeline"""
|
| 41 |
df_enhanced = df.copy()
|
| 42 |
+
|
| 43 |
+
# First, rename columns to match training data convention
|
| 44 |
+
rename_mapping = {
|
| 45 |
+
"Lub oil pressure": "Lube Oil Pressure",
|
| 46 |
+
"lub oil temp": "Lube Oil Temperature",
|
| 47 |
+
"Coolant temp": "Coolant Temperature",
|
| 48 |
+
"Engine rpm": "Engine RPM",
|
| 49 |
+
"Fuel pressure": "Fuel Pressure",
|
| 50 |
+
"Coolant pressure": "Coolant Pressure"
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
for old_name, new_name in rename_mapping.items():
|
| 54 |
+
if old_name in df_enhanced.columns:
|
| 55 |
+
df_enhanced.rename(columns={old_name: new_name}, inplace=True)
|
| 56 |
+
|
| 57 |
+
# Create sensor interactions (matching training pipeline)
|
| 58 |
+
sensor_columns = [col for col in df_enhanced.columns]
|
| 59 |
+
|
| 60 |
+
# Add ratio features
|
| 61 |
+
if 'Lube Oil Pressure' in df_enhanced.columns and 'Coolant Pressure' in df_enhanced.columns:
|
| 62 |
+
df_enhanced['Oil_Coolant_Pressure_Ratio'] = (
|
| 63 |
+
df_enhanced['Lube Oil Pressure'] / (df_enhanced['Coolant Pressure'] + 1)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if 'Lube Oil Temperature' in df_enhanced.columns and 'Coolant Temperature' in df_enhanced.columns:
|
| 67 |
+
df_enhanced['Oil_Coolant_Temp_Diff'] = (
|
| 68 |
+
df_enhanced['Lube Oil Temperature'] - df_enhanced['Coolant Temperature']
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Add squared features for each sensor
|
| 72 |
+
for col in ['Lube Oil Pressure', 'Lube Oil Temperature', 'Coolant Pressure',
|
| 73 |
+
'Coolant Temperature', 'Engine RPM', 'Fuel Pressure']:
|
| 74 |
+
if col in df_enhanced.columns:
|
| 75 |
+
df_enhanced[f'{col}_Squared'] = df_enhanced[col] ** 2
|
| 76 |
+
|
| 77 |
return df_enhanced
|
| 78 |
|
| 79 |
# ============================================
|