2022.03.07 월

scikit-learn

붓꽃의 품종 분류

데이터 포인트 : 붓꽃 1개 → 기대 출력 : 꽃의 품종 (결과값 : 레이블)

from sklearn.datasets import load_iris
iris_dataset = load_iris()
# iris 객체 = bunch 클랙스 객체 (딕셔너리와 유사)
print("iris_dataset의 키:\\n",iris_dataset.keys())
# dataset의 간략한 설명
print(iris_dataset['DESCR'][:193] + "\\n...")
# 붓꽃 품종 이름 문자열 배열
print("타깃의 이름:",iris_dataset['target_names'])
# 각 특성 설명 문자열 리스트
print("특성의 이름:",iris_dataset['feature_names'])
# 데이터 타입
print("data type:",type(iris_dataset['data']))
# 데이터 크기
print("data size:",iris_dataset['data'].shape)
# 처음 다섯 행 샘플의 **특성값**
print("data의 처음 다섯행:", iris_dataset['data'][:5])
# target type
print("target type:",type(iris_dataset['target']))
# target size
print("target size:",iris_dataset['target'].shape)
# target (0은 s, 1은 ver, 2는 vi)
print("target:\\n",iris_dataset['target'])

# 결과
iris_dataset의 키:
 dict_keys(['data', 'target', 'frame', 'target_names', 'DESCR', 'feature_names', 'filename', 'data_module'])
.. _iris_dataset:

Iris plants dataset
--------------------

**Data Set Characteristics:**

    :Number of Instances: 150 (50 in each of three classes)
    :Number of Attributes: 4 numeric, pre
...
타깃의 이름: ['setosa' 'versicolor' 'virginica']
특성의 이름: ['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)']
data type: <class 'numpy.ndarray'>
data size: (150, 4)
data의 처음 다섯행: [[5.1 3.5 1.4 0.2]
 [4.9 3.  1.4 0.2]
 [4.7 3.2 1.3 0.2]
 [4.6 3.1 1.5 0.2]
 [5.  3.6 1.4 0.2]]
target type: <class 'numpy.ndarray'>
target size: (150,)
target:
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2
 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
 2 2]