1. 程式人生 > 其它 >sklearn.datasets

sklearn.datasets

sklearn.datasets.load_iris()

引數:

  • return_X_y ; bool, default=False :If True, returns(data,target)instead of a Bunch object. See below for more information about thedataandtargetobject.
  • as_frame ;bool, default=False:If True, the data is a pandas DataFrame including columns with appropriate dtypes (numeric). The target is a pandas DataFrame or Series depending on the number of target columns. Ifreturn_X_y
    is True, then (data,target) will be pandas DataFrames or Series as described below.

返回:

  • data{ndarray, dataframe} of shape (150, 4)

The data matrix. Ifas_frame=True,datawill be a pandas DataFrame.

  • target: {ndarray, Series} of shape (150,)

The classification target. Ifas_frame=True,targetwill be a pandas Series.

  • feature_names: list

The names of the dataset columns.

  • target_names: list

The names of target classes.

  • frame: DataFrame of shape (150, 5)

Only present whenas_frame=True. DataFrame withdataandtarget.

New in version 0.23.

  • DESCR: str

The full description of the dataset.

  • filename: str

The path to the location of the data.

  • (data, target)tuple ifreturn_X_yis True

例子:

from sklearn import  datasets

iris_data = datasets.load_iris()
print(iris_data.data) #返回樣本資料
print(iris_data.data.shape) #返回樣本資料形狀
print(iris_data.target) #返回樣本資料的label
print(iris_data.target.shape) #返回樣本資料lable形狀
print(iris_data.target[[0,50,149]]) #返回樣本資料 x_0,x_50 ,x_149 的label
print(iris_data.target_names) #返回lable 名稱
print(iris_data.target_names[0:4])
print(iris_data.target_names[[0,1,2]])
print(iris_data.feature_names) #返回特徵名稱
print(iris_data.feature_names[0:2]) #返回特徵名稱
print(iris_data.DESCR) #資料描述
print(iris_data.filename) #返回資料存放位置
X ,y = datasets.load_iris(return_X_y=True) 
print(X.shape)
print(y.shape)
iris_data = datasets.load_iris(as_frame=True)
print(type(iris_data))

因上求緣,果上努力~~~~ 作者:cute_Learner,轉載請註明原文連結:https://www.cnblogs.com/BlairGrowing/p/15852435.html