MultiOutputClassifier : 다중 분류 알고리즘
- 하나의 데이터를 여러 속성으로 분류하고 싶을 때 사용
from sklearn.datasets import make_classification
from sklearn.multioutput import MultiOutputClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.utils import shuffle
import numpy as np
X, y_11 = make_classification(n_samples=10, n_features=20, n_informative=14, n_classes=3, random_state=1)
y_2 = shuffle(y1, random_state=1)
y_3 = shuffle(y1, random_state=2)
Y = np.vstack((y_1, y_2, y_3)).T
n_samples, n_features = X.shape # 10,20
n_outputs = Y.shape[1] # 3
n_classes = 3
forest = RandomForestClassifier(random_state=1)
multi_target_forest = MultiOutputClassifier(forest, n_jobs=-1)
multi_target_forest.fit(X, Y).predict(X)
[ 설명 ]
1. make_classification() : 가상 데이터 생성
make_classification(n_samples=10, n_features=20, n_informative=14, n_classes=3, random_state=1)
가. n_samples : 표본 데이터 수
나. n_features : 독립변수 수
다. n_informative : 독립변수 중 종속변수와 상관 관계가 있는 성분의 수
라. n_classes : 종속변수 클래스 수
마. random_state : 난수 생성, 같은 학습 데이터(테스트 데이터) 생성
2. np.vstack() : 행으로 쌓는 것
3. MultiOutputClassifier(forest, n_jobs=-1)
가. MultiOutputClassifier : 다중 분류 알고리즘
나. n_jobs : CPU 코어 수, CPU를 얼마나 쓸건지를 결정, -1이면 다 쓰는 것
'PYTHON > machine_learning' 카테고리의 다른 글
| Precision, Recall, F1 Score (0) | 2022.11.02 |
|---|---|
| 경사하강법을 이용한 행렬 분해 (0) | 2022.02.09 |
| 행렬 전치 (0) | 2022.02.08 |
| 코사인 유사도 (0) | 2022.02.08 |
| 가중평균 (0) | 2022.02.08 |