33 lines
694 B
Python
33 lines
694 B
Python
"""Standalone training script — trains IsolationForest and saves model.pkl.
|
|
|
|
Usage:
|
|
cd agent
|
|
python train.py
|
|
"""
|
|
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Allow running from project root or agent/ directory
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from model import AnomalyDetector
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s [%(levelname)s] %(message)s",
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
"""Entry point: load data, train, save."""
|
|
detector = AnomalyDetector()
|
|
X = detector._load_dataset()
|
|
detector.train(X)
|
|
print(f"Done. Model saved to data/model.pkl ({X.shape[0]} training samples)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|