File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010MODEL_FILE = os .path .join (BASE_DIR , "isolation_forest_model.pkl" )
1111ENCODERS_FILE = os .path .join (BASE_DIR , "encoders.pkl" )
1212
13+
1314def train_model ():
1415 if not os .path .exists (DATA_FILE ):
1516 print (f"Data file { DATA_FILE } not found. Run log_generator.py first." )
@@ -29,9 +30,9 @@ def train_model():
2930 df ['event_encoded' ] = le_event .fit_transform (df ['event_type' ])
3031
3132 # Select features for Isolation Forest
32- # Using bytes_transferred and protocol_encoded as primary anomaly indicators
33+ # Use 'bytes' as column name to match the prediction endpoint in main.py
3334 features = df [['bytes_transferred' , 'protocol_encoded' ]].rename (
34- columns = {'bytes_transferred' : 'bytes' , 'protocol_encoded' : 'protocol_encoded' }
35+ columns = {'bytes_transferred' : 'bytes' }
3536 )
3637
3738 print ("Training Isolation Forest model..." )
@@ -59,5 +60,6 @@ def train_model():
5960 print ("Protocol classes:" , list (le_protocol .classes_ ))
6061 print ("Event classes:" , list (le_event .classes_ ))
6162
63+
6264if __name__ == "__main__" :
6365 train_model ()
You can’t perform that action at this time.
0 commit comments