Question: Do this on Pycharm: You need to create a AI - model to perform the intrusion detection. The source code of decision tree - based
Do this on Pycharm:
You need to create a AImodel to perform the intrusion detection. The source code of decision treebased AI models and the datasets training and testing are provided in the attachments.
Python code:
import numpy as np
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.preprocessing import Normalizer
from sklearn.metrics import accuracyscore
# read the training data set and the test data set.
traindata pdreadcsvkddtraincsv headerNone
testdata pdreadcsvkddtestcsv headerNone
# Normalize the training data set
X traindata.iloc::
scaler NormalizerfitX
Xtrain scaler.transformX
Xtrain nparrayXtrain
ytrain nparraytraindata.iloc:
# Normal the test data set
T testdata.iloc::
scaler NormalizerfitT
Xtest scaler.transformT
Xtest nparrayXtest #Xtest
ytest nparraytestdata.iloc:
# Create a decision tree model.
model DecisionTreeClassifier
# Train the decision tree model
model.fitXtrain, ytrain
# make predictions
ypred model.predictXtest
# Calculate the prediction accuracy
accuracy accuracyscoreytest, ypred
# Print out the prediction accuracy
printaccuracy: faccuracy
# print out the feature values of the th sample.
printXtest :
printThe true lable Normal: or Intrusion:: ytest
printThe predicted lable Normal: or Intrusion:: ypred
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
