官术网_书友最值得收藏!

How to do it...

In this section, we'll walk through a recipe showing how to use PCA on data:

  1. 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()
  1. Standardize the dataset, as is necessary before applying PCA:
from sklearn.preprocessing import StandardScaler

X_standardized = StandardScaler().fit_transform(X)
  1. Instantiate a PCA instance and use it to reduce the dimensionality of our data:
pca = PCA()
pca.fit_transform(X_standardized)
  1. Assess the effectiveness of your dimensionality reduction:
print(pca.explained_variance_ratio_)

The following screenshot shows the output:

主站蜘蛛池模板: 塔城市| 福州市| 霍城县| 平安县| 盐池县| 海安县| 孟连| 岳阳市| 泽库县| 建阳市| 蕉岭县| 慈利县| 浪卡子县| 松阳县| 新兴县| 类乌齐县| 军事| 三亚市| 巴中市| 轮台县| 陆丰市| 济南市| 溧水县| 庄河市| 西和县| 龙泉市| 伊金霍洛旗| 桃江县| 麻江县| 若尔盖县| 图木舒克市| 安阳市| 华阴市| 永登县| 灵武市| 永春县| 裕民县| 哈巴河县| 阿克苏市| 和龙市| 乡城县|