4.1 KiB
4.1 KiB
In [ ]:
#!pip install plotlyIn [ ]:
# Start by importing and plotting the dataset
import pandas as pd
import plotly.express as pxIn [ ]:
df = pd.read_csv("file_pe_headers.csv", sep=",")
fig = px.scatter_3d(
df,
x="SuspiciousImportFunctions",
y="SectionsLength",
z="SuspiciousNameSection",
color="Malware",
)
fig.show()In [ ]:
# Extract the features and target labels
y = df["Malware"]
x = df.drop(["Name", "Malware"], axis=1).to_numpy()In [ ]:
# Now we will import scikit-learn's clustering module and fit a K-means model with 2 clusters to the data:
from sklearn.cluster import KMeans
estimator = KMeans(n_clusters=len(set(y)))
estimator.fit(x)In [ ]:
# Predict the cluster using our trained algorithm
y_pred = estimator.predict(x)
df["pred"] = y_pred
df["pred"] = df["pred"].astype("category")In [ ]:
# We will see how the algorithm did and plot the algorithm's clusters
fig = px.scatter_3d(
df,
x="SuspiciousImportFunctions",
y="SectionsLength",
z="SuspiciousNameSection",
color="pred",
)
fig.show()In [ ]:
from sklearn.metrics import classification_report , confusion_matrixIn [ ]:
print("Confusion Matrix:")
print(confusion_matrix(y , y_pred))In [ ]:
print("\nClassification Report:")
print(classification_report(y , y_pred))