Update Streamlit app
Browse files
app.py
CHANGED
|
@@ -37,44 +37,44 @@ def load_model():
|
|
| 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 |
-
#
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
# Create
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 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 |
# ============================================
|
| 80 |
# MAIN APP
|
|
|
|
| 37 |
# FEATURE ENGINEERING FUNCTION
|
| 38 |
# ============================================
|
| 39 |
def engineer_features(df):
|
| 40 |
+
"""Apply feature engineering to match training pipeline exactly"""
|
| 41 |
df_enhanced = df.copy()
|
| 42 |
|
| 43 |
+
# Ensure we have the correct raw features in the correct order
|
| 44 |
+
# Raw features from input (keeping original names as they come from user input)
|
| 45 |
+
required_features = [
|
| 46 |
+
'Engine rpm',
|
| 47 |
+
'Lub oil pressure',
|
| 48 |
+
'Fuel pressure',
|
| 49 |
+
'Coolant pressure',
|
| 50 |
+
'lub oil temp',
|
| 51 |
+
'Coolant temp'
|
| 52 |
+
]
|
| 53 |
|
| 54 |
+
# Verify all required features exist
|
| 55 |
+
for feature in required_features:
|
| 56 |
+
if feature not in df_enhanced.columns:
|
| 57 |
+
raise ValueError(f"Missing required feature: {feature}")
|
| 58 |
|
| 59 |
+
# Create engineered features (matching training pipeline)
|
| 60 |
+
df_enhanced['Lub_Stress_Index'] = df_enhanced['Lub oil pressure'] * df_enhanced['lub oil temp']
|
| 61 |
+
df_enhanced['Thermal_Efficiency'] = df_enhanced['Coolant pressure'] / (df_enhanced['Coolant temp'] + 1e-5)
|
| 62 |
+
df_enhanced['Power_Load_Index'] = df_enhanced['Engine rpm'] * df_enhanced['Fuel pressure']
|
| 63 |
|
| 64 |
+
# Return features in the EXACT order the model was trained with
|
| 65 |
+
feature_order = [
|
| 66 |
+
'Engine rpm',
|
| 67 |
+
'Lub oil pressure',
|
| 68 |
+
'Fuel pressure',
|
| 69 |
+
'Coolant pressure',
|
| 70 |
+
'lub oil temp',
|
| 71 |
+
'Coolant temp',
|
| 72 |
+
'Lub_Stress_Index',
|
| 73 |
+
'Thermal_Efficiency',
|
| 74 |
+
'Power_Load_Index'
|
| 75 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
return df_enhanced[feature_order]
|
| 78 |
|
| 79 |
# ============================================
|
| 80 |
# MAIN APP
|