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 thedata
andtarget
object. -
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. If
return_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. If
as_frame=True
,data
will be a pandas DataFrame.
- target: {ndarray, Series} of shape (150,)
-
The classification target. If
as_frame=True
,target
will 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 when
as_frame=True
. DataFrame withdata
andtarget
.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 if
return_X_y
is 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))