기본 콘텐츠로 건너뛰기

라벨이 혼동행렬인 게시물 표시

[matplotlib]quiver()함수

[ML] 다중 클래스의 분류: SGDClassifier와 RandomForest

다중 클래스의 분류: SGDClassifier와 RandomForest 다중 클래스를 가진 인공 데이터셋에 대한 분류모델은 SGDClassifier() 를 적용합니다. 다중 클래스에 대한 분류 모델을 생성하는 알고리즘은 세가지로 구분할 수 있습니다. 다중 클래스를 직접적으로 조정하는 것으로 Random Forest Classifier 또는 naive Bayesn Classifier 를 적용합니다. 다른 두 가지는 Support vector machine classifier 또는 l inear classifier 와 같이 이진 분류 알고리즘을 적용합니다. 이진분류를 적용하기 위한 전략으로 one-versus-all(OvA, one-versus-the-rest) 와 one-versus-one(OvO) 를 사용합니다. OvA: [0, 1, 2, ..., 9] 에서, 0 검출기, 1 검출기 등을 생성하고 각 샘플에서 생성되는 결정함수로부터 클래스를 결정합니다. OvO: 0-1 구분하는 검출기, 0-2구분하는 검출기 등을 생성하므로 N개의 클래스가 존재한다면 $\frac{N(N-1)}{2}$의 검출기를 생성합니다. 대부분의 이진 분류 알고리즘의 경우 OvA가 선호됩니다. sklearn에서는 다중 클래스의 데이터에 이진분류 알고리즘을 이용할 경우 자동적으로 OvA가 실행됩니다. 그러나 support vector machine은 OvO가 실행됩니다. import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") make_classification() ...

[ML] 이진 분류 추정기의 평가

이진분류기의 평가 이진 분류를 위해 로지스틱 모델을 사용합니다. 모델 생성을 위해 사용한 데이터셋은 pima-indians-diabetes.csv로서 Kaggle 에서 가져올 수 있습니다. 이 파일은 .csv 형식이므로 pandas.read_csv("경로")를 통해 호출할 수 있습니다. import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score, precision_score, recall_score, roc_auc_score from sklearn.metrics import f1_score, confusion_matrix, precision_recall_curve, roc_curve from sklearn.preprocessing import StandardScaler, Binarizer from sklearn.linear_model import LogisticRegression data = pd.read_csv('pima-indians-diabetes.csv') data.head(3) preg plas pres skin test mass pedi age class 0 6 148 72 35 0 33.6 0.627 50 1 1 1 85 66 29 0 26.6...