监督学习算法2.3.1-二分类、回归算法、威斯康辛乳腺癌、波士顿房价

import mglearn 
import matplotlib.pyplot as plt

x,y = mglearn.datasets.make_forge()

mglearn.discrete_scatter(x[:,0],x[:,1],y)
plt.legend(['Class 0','Class 1'],loc = 4)
plt.xlabel('first feature')
plt.ylabel('second feature')
print('x.shape:{}'.format(x.shape))
plt.show()
 
x.shape:(26, 2)

在这里插入图片描述

x,y = mglearn.datasets.make_wave(n_samples=40)
plt.plot(x,y,'o')
plt.ylim(-3,3)
plt.xlabel('feature')
plt.ylabel('target')
plt.show()

在这里插入图片描述
总程序

import mglearn 
import matplotlib.pyplot as plt
import numpy as np

x,y = mglearn.datasets.make_forge()

mglearn.discrete_scatter(x[:,0],x[:,1],y)
plt.legend(['Class 0','Class 1'],loc = 4)
plt.xlabel('first feature')
plt.ylabel('second feature')
print('x.shape:{}'.format(x.shape))
plt.show()
 
x,y = mglearn.datasets.make_wave(n_samples=40)
plt.plot(x,y,'o')
plt.ylim(-3,3)
plt.xlabel('feature')
plt.ylabel('target')
plt.show()

from sklearn.datasets import load_breast_cancer
cancer = load_breast_cancer()
print("cancer.keys():\n{}".format(cancer.keys()))
print('shape of cancer data:\n{}'.format(cancer.data.shape))
print('sample counts per class:\n{}'.format({n : v for n,v in zip(cancer.target_names,np.bincount(cancer.target))}))
print('feature names:\n{}'.format(cancer.feature_names))

from sklearn.datasets import load_boston
boston = load_boston()
print('data shape:\n{}'.format(boston.data.shape))

x,y = mglearn.datasets.load_extended_boston()
print('x.shape:{}'.format(x.shape))

x.shape:(26, 2)
cancer.keys():
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names'])
shape of cancer data:
(569, 30)
sample counts per class:
{'malignant': 212, 'benign': 357}
feature 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']
data shape:
(506, 13)
x.shape:(506, 104)

发布了65 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/heroybc/article/details/102711180
今日推荐