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)