詹惠儿

2019-01-04   阅读量: 512

数据分析师

主成分分析

扫码加入数据分析学习群

第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)

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 2 关注作者 收藏

评论(0)


暂无数据

推荐课程

推荐帖子