3.6 KiB
3.6 KiB
In [ ]:
# Start by importing the necessary libraries and reading in the dataset
from sklearn.decomposition import PCA
import pandas as pd
data = pd.read_csv("file_pe_headers.csv", sep=",")
X = data.drop(["Name", "Malware"], axis=1).to_numpy()In [ ]:
#Standardize the dataset as it is neccessary before applying PCA
from sklearn.preprocessing import StandardScaler
X_standardized = StandardScaler().fit_transform(X)
print(X_standardized.shape)In [ ]:
# Instantiate a PCA instance use it to reduce the dimensionality of our data
pca = PCA()
pca.fit_transform(X_standardized)In [ ]:
# Assess the effectiveness of your dimensionality reduction
print(pca.explained_variance_ratio_)In [ ]:
sum(pca.explained_variance_ratio_[0:50])In [ ]:
pca_reduce = PCA(n_components=25)
pca_reduce.fit_transform(X_standardized)In [ ]:
X_pca = pca_reduce.transform(X_standardized)
print(X_pca.shape)In [ ]:
In [ ]: