-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataset_exploration.py
53 lines (40 loc) · 1.7 KB
/
dataset_exploration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# load phishing dataset into dataframe
phishing = pd.read_csv("phishingDataset.csv")
df = phishing.drop(["id"], axis=1)
# split the dataset into features (X) and targets (y)
#X = phishing.drop(["id","Result"], axis=1)
#y = phishing.Result
#Getting info about our dataset; datatypes and such
phishing.info()
# defining phishing websites
P = phishing[phishing.Result == -1]
# non-phishing websites
NP = phishing[phishing.Result == 1]
pd.crosstab(phishing['Result'],
phishing['age_of_domain'],
colnames=["Age of Domain"],
rownames=["Result (-1=Phishing,1=Legitimate)"]
).plot.bar(stacked=False)
#Below code reused from: https://www.kaggle.com/code/nourajo/phishing-websites-ensembling-model
#For experimentation use only.
#Percentage of class values
plt.figure(figsize=(13, 6))
ax = sns.barplot(x=phishing['Result'], y=phishing['Result'], data=df, estimator=lambda x: len(x) / len(df) * 100, color = 'Blue')
ax.set(ylabel="Percent");
ax.set_title('The Percentage of Phishing Websites vs Legitimate Webites', size = 15);
plt.savefig('resultpercentageplot.png', dpi=300, bbox_inches='tight');
#Correlation between variables
plt.figure(figsize=(35, 25))
corr = df.corr()
mask = np.triu(np.ones_like(df.corr(), dtype=np.bool))
heatmap = sns.heatmap(corr, mask = mask, vmin=-1, vmax=1, annot=True, cmap = 'viridis')
heatmap.set_title('Correlation Heatmap', fontdict={'fontsize':20}, pad=12);
plt.savefig('heatmap.png', dpi=300, bbox_inches='tight')
#Prints out the count of -1, 0 and 1's in each feature
for column in df:
print(df[column].value_counts())