1. 程式人生 > >sklearn學習-3-樣本資料集

sklearn學習-3-樣本資料集

# -*- coding: utf-8 -*-
"""
Created on Mon Jul  2 16:02:56 2018

@author: GY
"""

#監督學習
#----------------------------------------------------------------------------------------------------------------------#
import mglearn
import matplotlib.pyplot as plt
from sklearn.datasets import load_breast_cancer
import numpy as np


#---------------------------------------------------------------------------------------------------------------
#二分類資料集
#資料,標籤
X,y=mglearn.datasets.make_forge()
mglearn.discrete_scatter(X[:,0],X[:,1],y)#第一個特徵-x,第二個特徵-y
plt.legend(["Class 0","Class 1"],loc=4)
plt.xlabel('Frist feature')
plt.ylabel('Second feature')
print(X.shape)



#-------------------------------------------------------------------------------------------------------------
#迴歸資料集
X,y=mglearn.datasets.make_wave(n_samples=40)
plt.plot(X,y,'o')
plt.ylim(-3,3)
plt.xlabel('Feature')
plt.ylabel('Target')



#---------------------------------------------------------------------------------------------------------------------
#真實資料集
cancer=load_breast_cancer()
        #cancer.keys()
            #dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names'])
        #cancer.data.shape
            #(569, 30)
            
#建立特徵的分類,dict
{n:v for n,v in zip(cancer.target_names,np.bincount(cancer.target)) }