「あやめ」の種類判別(その4)

iris(菖蒲:アヤメ)データセットの内容を詳細に確認する方法
 (その1)の
   行番号1~24:ハウスキーピング部分
   行番号68〜99:データ出力部分 を使用する

#
import pandas as pd
from sklearn import datasets      
iris_datasets =  datasets.load_iris()
iris = pd.DataFrame(iris_datasets.data,columns = iris_datasets.feature_names)
iris['target'] = iris_datasets.target
#
#
#
# データの先頭
print("***先頭****")
print(iris.head(7))
print("********")
#
# データの概要
print("***概要****")
print(iris.info())
print("********")
#
# データの要約統計量
print("***統計*****")
print(iris.describe())
print("********")
#
# データの形状
print("***形状*****")
print(iris.shape)
print("********")
#
# データ要素の取り出し
print("***要素*****")
print(iris.iloc[:10])
print("********")
#
# 条件に合う行の取得
print("***条件*****")
print(iris.query("target==1"))
print("********")
#
#

以下はサンプルコードと出力例

1.データの先頭行

# データの先頭行
print("***先頭****")
print(iris.head(7))
print("********")
***先頭****
   sepal length (cm)  sepal width (cm)  ...  petal width (cm)  target
0                5.1               3.5  ...               0.2       0
1                4.9               3.0  ...               0.2       0
2                4.7               3.2  ...               0.2       0
3                4.6               3.1  ...               0.2       0
4                5.0               3.6  ...               0.2       0
5                5.4               3.9  ...               0.4       0
6                4.6               3.4  ...               0.3       0

[7 rows x 5 columns]
********

 「7」を指定すると・・・可変値
   先頭から7件の内容を出力する
 
 項目について
   sepal length・・・がく(外側)の長さ
   sepal width・・・がく(外側)の幅
   petal length・・・花弁(内側)の長さ
   petal width・・・花弁(内側)の幅
   target・・・品種

品種(target)名称イメージ
setosa
セトーサ

ヒオウギアヤメ
versicolor
ヴァーシカラー

ブルーフラッグ
virginica
ヴァージニカ

ヴァージニカ

2.データの概要

# データの概要
print("***概要****")
print(iris.info())
print("********")
***概要****
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150 entries, 0 to 149
Data columns (total 5 columns):
 #   Column             Non-Null Count  Dtype  
---  ------             --------------  -----  
 0   sepal length (cm)  150 non-null    float64
 1   sepal width (cm)   150 non-null    float64
 2   petal length (cm)  150 non-null    float64
 3   petal width (cm)   150 non-null    float64
 4   target             150 non-null    int64  
dtypes: float64(4), int64(1)
memory usage: 6.0 KB
None
********

 項目について
   RangeIndex・・・行数(例:150件)
   Data columns・・・列数(例:5カラム)
   列名、列の型、データタイプ等を表す

3.データの要約統計量

# データの要約統計量
print("***統計*****")
print(iris.describe())
print("********")
***統計*****
       sepal length (cm)  sepal width (cm)  ...  petal width (cm)      target
count         150.000000        150.000000  ...        150.000000  150.000000
mean            5.843333          3.057333  ...          1.199333    1.000000
std             0.828066          0.435866  ...          0.762238    0.819232
min             4.300000          2.000000  ...          0.100000    0.000000
25%             5.100000          2.800000  ...          0.300000    0.000000
50%             5.800000          3.000000  ...          1.300000    1.000000
75%             6.400000          3.300000  ...          1.800000    2.000000
max             7.900000          4.400000  ...          2.500000    2.000000

[8 rows x 5 columns]
********

 項目について
   count・・・件数
   mean・・・平均値
   std・・・標準偏差
   min・・・最小値
   25%・・・1/4分位点
   50%・・・中央値
   75%・・・3/4分位点
   max・・・最大値

4.データの形状

# データの形状
print("***形状*****")
print(iris.shape)
print("********")
***形状*****
(150, 5)
********

 項目の説明
   150行、5列のデータセット

5.データ要素の取り出し

# データ要素の取り出し
print("***要素*****")
print(iris.iloc[:10])
print("********")
***要素*****
   sepal length (cm)  sepal width (cm)  ...  petal width (cm)  target
0                5.1               3.5  ...               0.2       0
1                4.9               3.0  ...               0.2       0
2                4.7               3.2  ...               0.2       0
3                4.6               3.1  ...               0.2       0
4                5.0               3.6  ...               0.2       0
5                5.4               3.9  ...               0.4       0
6                4.6               3.4  ...               0.3       0
7                5.0               3.4  ...               0.2       0
8                4.4               2.9  ...               0.2       0
9                4.9               3.1  ...               0.1       0

[10 rows x 5 columns]
********

  配列(リスト)の値を取り出す
   開始位置、終了位置、増分を指定する

 項目の説明
   

6.条件に合う行の取得

# 条件に合う行の取得
print("***条件*****")
print(iris.query("target==1"))
print("********")
***条件*****
    sepal length (cm)  sepal width (cm)  ...  petal width (cm)  target
50                7.0               3.2  ...               1.4       1
51                6.4               3.2  ...               1.5       1
52                6.9               3.1  ...               1.5       1
53                5.5               2.3  ...               1.3       1
54                6.5               2.8  ...               1.5       1
55                5.7               2.8  ...               1.3       1
56                6.3               3.3  ...               1.6       1
57                4.9               2.4  ...               1.0       1
58                6.6               2.9  ...               1.3       1
59                5.2               2.7  ...               1.4       1
60                5.0               2.0  ...               1.0       1
61                5.9               3.0  ...               1.5       1
62                6.0               2.2  ...               1.0       1
63                6.1               2.9  ...               1.4       1
64                5.6               2.9  ...               1.3       1
65                6.7               3.1  ...               1.4       1
66                5.6               3.0  ...               1.5       1
67                5.8               2.7  ...               1.0       1
68                6.2               2.2  ...               1.5       1
69                5.6               2.5  ...               1.1       1
70                5.9               3.2  ...               1.8       1
71                6.1               2.8  ...               1.3       1
72                6.3               2.5  ...               1.5       1
73                6.1               2.8  ...               1.2       1
74                6.4               2.9  ...               1.3       1
75                6.6               3.0  ...               1.4       1
76                6.8               2.8  ...               1.4       1
77                6.7               3.0  ...               1.7       1
78                6.0               2.9  ...               1.5       1
79                5.7               2.6  ...               1.0       1
80                5.5               2.4  ...               1.1       1
81                5.5               2.4  ...               1.0       1
82                5.8               2.7  ...               1.2       1
83                6.0               2.7  ...               1.6       1
84                5.4               3.0  ...               1.5       1
85                6.0               3.4  ...               1.6       1
86                6.7               3.1  ...               1.5       1
87                6.3               2.3  ...               1.3       1
88                5.6               3.0  ...               1.3       1
89                5.5               2.5  ...               1.3       1
90                5.5               2.6  ...               1.2       1
91                6.1               3.0  ...               1.4       1
92                5.8               2.6  ...               1.2       1
93                5.0               2.3  ...               1.0       1
94                5.6               2.7  ...               1.3       1
95                5.7               3.0  ...               1.2       1
96                5.7               2.9  ...               1.3       1
97                6.2               2.9  ...               1.3       1
98                5.1               2.5  ...               1.1       1
99                5.7               2.8  ...               1.3       1

[50 rows x 5 columns]
********

 品種が「1(versicolor)」を取り出す(例)
   50件のデータが存在する