Voting ensemble method to detect cyber attacks

In the voting ensemble method, every model gets to make a prediction about the results of the model, and the decision on the model result is made on the majority votes or predictions made. There is another advanced level of the voting the ensemble method known as weighted voting. Here certain predictor models have more weights associated with their votes and thus get to make more privileged predictions:

  1. We start by importing the respective libraries:
import pandas
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.ensemble import VotingClassifier
  1. We detect a cyber attack via a voting mechanism where we use algorithms like SCV, decision tree, and logistic regression. We finally use the voting classifier to choose the best of the three. Next we create the sub-models and pass them through the DDoS dataset as follows:
voters = []
log_reg = LogisticRegression() # the logistic regression model
voters.append(('logistic', model1))
desc_tree = DecisionTreeClassifier() # the decision tree classifier model
voters.append(('cart', model2))
cup_vec_mac = SVC() # the support vector machine model
voters.append(('svm', model3))
  1. For the final voting, the voting classifier is invoked as follows:
# create the ensemble model
ensemble = VotingClassifier(voters)
  1. The final model is chosen by performing a k-fold cross validation:
results = model_selection.cross_val_score(ensemble, X, Y, cv=kfold)
print(results.mean())
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset