Skip to content
This repository was archived by the owner on Apr 12, 2025. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions iids/analyzer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@

# Create your views here.
#loading our trained model
print("Keras model loading.......")
print(" Model loading.......")
model = load_model('attack_labe.hdf5') #after training #TODO
print("Model loaded!!")

def request():
return HttpResponse("<h1>Intelligent Intrusion Detection System</h1>")
return HttpResponse("The predicted attacked label is {}".format(label)) #label will be imported after finishing dvevelopment of analyzer



#class Ml_Algo and functions

class Random_Forest_Classifier():
def __init__(self):
default_path = "//"
self.model = load_model("")

def preprocessing(self, input_data):
df = pd.read_csv('input_data')
df.columns =["duration","protocol_type","service","flag","src_bytes", "dst_bytes","land","wrong_fragment","urgent","hot","num_failed_logins",
"logged_in","num_compromised","root_shell","su_attempted","num_root","num_file_creations","num_shells","num_access_files","num_outbound_cmds",
"is_host_login","is_guest_login","count","srv_count","serror_rate","srv_serror_rate","rerror_rate","srv_rerror_rate","same_srv_rate",
"diff_srv_rate","srv_diff_host_rate","dst_host_count","dst_host_srv_count","dst_host_same_srv_rate","dst_host_diff_srv_rate","dst_host_same_src_port_rate",
"dst_host_srv_diff_host_rate","dst_host_serror_rate","dst_host_srv_serror_rate","dst_host_rerror_rate","dst_host_srv_rerror_rate","label"]
le = LabelEncoder()
df['protocol_type'] = le.fit_transform(df['protocol_type'])
df['service']= le.fit_transform(df['service'])
df['flag'] = le.fit_transform(df['flag'])

return input_data

def prediction(self):
try:
input_data = self.preprocessing(input_data)
prediction = self.predict(input_data)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here, we will make changes once we decide a prpoer format of input data

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of having 'self.predict(input_data)'?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it doesn't have any significance at the moment as we haven't created the input serializers. So, I will remove and then create a separate app for prediction.

except Exception as e:
return {"status": "Error", "message": str(e)}

return prediction