集成学习笔记 06 图像数据集实战
开源学习地址:datawhale
为了巩固之前的知识点,今天主要结合sklearn的乳腺癌数据集,进行一次实战
1.认识数据集
from sklearn.datasets import load_breast_cancer
cancers = load_breast_cancer()
X = cancers.data #获取特征值
Y = cancers.target #获取标签
print(X.shape) #查看特征形状
print(Y.shape) #查看标签形状
(569, 30)
(569,)
print(cancers.DESCR) #查看数据集描述
print(cancers.feature_names) # 特征名
print(cancers.target_names) # 标签类别名
['mean radius' 'mean texture' 'mean perimeter' 'mean area'
'mean smoothness' 'mean compactness' 'mean concavity'
'mean concave points' 'mean symmetry' 'mean fractal dimension'
'radius error' 'texture error' 'perimeter error' 'area error'
'smoothness error' 'compactness error' 'concavity error'
'concave points error' 'symmetry error' 'fractal dimension error'
'worst radius' 'worst texture' 'worst perimeter' 'worst area'
'worst smoothness' 'worst compactness' 'worst concavity'
'worst concave points' 'worst symmetry' 'worst fractal dimension']
['malignant' 'benign']
2.基于SVM的乳腺癌数据分类
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.3)
from sklearn.svm import SVC
model_linear = SVC(C=1.0, kernel='linear') # 线性核
model_linear.fit(x_train, y_train)
train_score = model_linear.score(x_train, y_train)
test_score = model_linear.score(x_test, y_test)
print('train_score:{0}; test_score:{1}'.format(train_score, test_score))
train_score:0.9673366834170855; test_score:0.9766081871345029