sklearn之load_breast_cancer数据集

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.decomposition import PCA
cancer = load_breast_cancer()
#print('breast_cancer数据集的长度为:',len(cancer))
#print('breast_cancer数据集的类型为:',type(cancer))
#print(cancer)
cancer_data = cancer['data']
cancer_target = cancer['target']
cancer_names = cancer['feature_names']
cancer_desc = cancer['DESCR']
#分为训练集与测试集
cancer_data_train,cancer_data_test = train_test_split(cancer_data,test_size=0.2,random_state=42)#训练集
cancer_target_train,cancer_target_test = train_test_split(cancer_target,test_size=0.2,random_state=42)#测试集
#使用sklearn转换器进行数据预处理//离差标准化
Scaler = MinMaxScaler().fit(cancer_data_train)#生成规则
cancer_trainScaler = Scaler.transform(cancer_data_train)
cancer_testScaler = Scaler.transform(cancer_data_test)#此处测试集使用了训练集规则,会有数据结果超过[0,1].
#pca降维
pca_model = PCA(n_components=10).fit(cancer_trainScaler)
cancer_trainPCA = pca_model.transform(cancer_trainScaler)
cancer_testPCA = pca_model.transform(cancer_testScaler)
#print(cancer_trainPCA)

你可能感兴趣的:(sklearn)