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

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:

主站蜘蛛池模板: 临猗县| 铜陵市| 周至县| 浦县| 那曲县| 米林县| 遵义县| 都匀市| 京山县| 津南区| 常熟市| 顺义区| 慈利县| 米泉市| 屏边| 彰化市| 武胜县| 德令哈市| 广东省| 吴江市| 夹江县| 饶河县| 霍城县| 英德市| 尚志市| 奉化市| 江口县| 清徐县| 江西省| 五台县| 锦州市| 甘肃省| 正镶白旗| 房产| 大余县| 河间市| 宜良县| 乌兰察布市| 遂川县| 江达县| 汪清县|