Search code examples
pythonsecurityclassificationrandom-forestxgboost

How can I handle overfitting of a model?


I'm using XGBoost model to predict attacks, But I get 100% accuracy, I tried Random Forest as well, and same, I get 100%. How can I handle this ovrefitting problem ? The steps I followed are: Data cleaning Data splitting Feature scaling Feature selection I even tried to change this order, but still get the same thing. Do you have any idea how to handle this? Thanks


Solution

  • Thank you for your clarification, I solved the problem by tuning the hyperparameters eta and max_depth.

    param = {
        'eta': 0.1, 
        'max_depth': 1,  
        'objective': 'multi:softprob',  
        'num_class': 3} 
    
    steps = 20  # The number of training iterations
    model = xgb.train(param, D_train, steps)
    preds = model.predict(D_test)