热线电话:13121318867

登录
2019-01-14 阅读量: 669
python如何进行主成分分析

第1步:导入库

# importing required libraries

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

第2步:导入数据集

导入数据集并将数据集分发到X和y组件以进行数据分析。

# importing or loading the dataset

dataset = pd.read_csv('wines.csv')

# distributing the dataset into two components X and Y

X = dataset.iloc[:, 0:13].values

y = dataset.iloc[:, 13].values

第3步:将数据集拆分为Training集和测试集

# Splitting the X and Y into the

# Training set and Testing set

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

第4步:特征缩放

在培训和测试集上进行预处理部分,例如拟合标准比例。

# performing preprocessing part

from sklearn.preprocessing import StandardScaler

sc = StandardScaler()

X_train = sc.fit_transform(X_train)

X_test = sc.transform(X_test)

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子