nilanjanadevc commited on
Commit
475e39d
·
verified ·
1 Parent(s): 9798a6c

Update Streamlit app

Browse files
Files changed (1) hide show
  1. app.py +30 -31
app.py CHANGED
@@ -40,41 +40,40 @@ 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
 
40
  """Apply feature engineering to match training pipeline exactly"""
41
  df_enhanced = df.copy()
42
 
43
+ # STEP 1: Rename columns to match training 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
+ # STEP 2: Get sensor columns (all columns except 'Engine Condition')
58
+ sensor_columns = [col for col in df_enhanced.columns if col != 'Engine Condition']
 
 
59
 
60
+ # STEP 3: 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
+ # STEP 4: Add squared features for EACH sensor column
72
+ for col in sensor_columns:
73
+ if col in df_enhanced.columns:
74
+ df_enhanced[f'{col}_Squared'] = df_enhanced[col] ** 2
75
 
76
+ return df_enhanced
77
 
78
  # ============================================
79
  # MAIN APP