sklearn 10

Feature Importance

Feature Importance and Permutation Feature Importance reference : Feature selection : feature importance vs permutation importance Permutation feature importance(sklearn.org) The Mathematics of Decision Trees, Random Forest and Feature Importance in Scikit-learn and Spark 머신러닝의 해석 2편 - 1. 트리 기반 모델의 Feature Importance 속성 랜덤 포레스트에서의 변수 중요도(Variable Importance) 3가지 Feature Importance(변수 중요도) - 트리 기..

sklearn - classification_report()

sklearn.metrics.classification_report reference : scikit-learn.org, sklearn.metrics.classification_report, document scikit-learn.org,sklearn.metrics.f1_score, document stackoverflow, How to interpret classification report of scikit-learn?,LaSul Answered Accuracy(정확도), Recall(재현율), Precision(정밀도), 그리고 F1 Score, eunsukimme Document : sklearn.metrix.classification_report(y_true, y_pred, *, Labels=N..

ROC Curve

Precision and Recall in an anomaly detection situation reference : document : sklearn.metrics.plot_roc_curve Classification - ROC & AUC ROC Curve, devopedia Measuring Performance: AUC(AUROC) ROC 커브는 False Positive Rate(FPR)을 기준으로 True Positive Rate(TPR)의 변화도를 표현한다. 아래 첫번째 분포곡선에서 임계값(beta)이 이동함에 따라 TPR과 FPR이 변화한다는 것을 예상해볼 수 있다. 임계값이 우측으로 이동하면 FPR과 TPR 모두 줄어든다. 반대로 임계값이 좌측으로 이동하면 FPR과 TPR모두 커진다. 즉..

LGBM

LGBM(Light Gradient Boosting Machine) LightGBM's documentation LightGBM 주요 파라미터 정리 LightGBM이란? LGBM은 'Light'(==fast)하고 또 'Light'(==low memory)하다. 그만큼 또 예민하다는 단점이 있다. 예민하다는 것은 과적합(Overfitting)되기 쉽다는 것이며 1만 개 이하의 적은 데이터셋을 다루기에는 적합하지 않은 모델이다. LGBM을 사용할 때에는 과적합에 특히 유의해야 하며 아래의 하이퍼파라미터들을 통해 학습을 조절할 필요가 있다. max_depth Tree의 깊이가 깊을 수록 당연하게도 train set에 더 가까운 가중치를 학습하게 된다. 다른 모델을 사용할 때보다 현저하게 max_depth를 줄..

sklearn - GridSearchCV

GridSearchCV reference : sklearn.model_selection.GridSearchCV(scikit-learn.org) 모형최적화, 데이터사이언스스쿨 [Chapter 4. 분류] 랜덤포레스트(Random Forest) 머신러닝 모델의 하이퍼파라미터를 조정하는 일은 매우 까다롭다. 아주 미묘한 파라미터 값 변화가 모델의 성능을 좌우하고, 모델마다 다양한 파라미터들이 유기적으로 얽혀있기 때문이다. GridSearchCV를 통하면 다양한 하이퍼파라미터 값을 미리 입력하고, 최적의 값과 해당 값으로 표현된 모델 정확도를 돌려받을 수 있다. from sklearn.model_selection import GridSearchCV params = {'n_estimators' : [10, 100..

sklearn - GradientBoostingClassifier

GradientBoostingClassifier Gradient Boosting Model sklearn.ensemble.GradientBoostingClassifier 지도학습 - 그래디언트 부스팅 2.3.6 결정 트리의 앙상블, 텐서 플로우 블로그 GradientBoosting 모델은 RandomForest 모델과 달리 learning_rate를 통해 오차를 줄여나가는 학습 방식을 사용한다. RandomForest 모델은 말그대로 Random하게 Bagging, Tree를 생성한다. 하지만 GradientBoosting 모델은 Tree를 생성할 때마다 이전 Tree보다 오차를 줄이게 된다. 또한 개별 Tree의 깊이는 얕게 만들어내면서 오차가 줄어든 Tree를 계속해서 연결해나가는 구조다.(때문에, ..

K-Nearest Neighbor Algorithm

K-Nearest Neighbor Algorithm(최근접 이웃 알고리즘) Reference : K-NN 알고리즘(K-최근접이웃) 개념 파이썬 라이브러리를 활용한 머신러닝, 한빛미디어 Classification Regression 1. Classification (n = 1) 기존에 분포하는 값 중 가장 가까운 값의 label을 현재 Test값의 label로 지정한다. (n > 1) 기존에 분포하는 값 중 가장 가까운 순서대로 n개의 값을 찾고, 가장 많이 나오는 label을 현재 Test값의 label로 지정한다. ex. N = 3일 때, 탐색 방식 ex. N = 3일 때, 코드 예시 from sklearn.model_selection import train_test_split X, y = mglear..

sklearn - RFE

RFE (recursive feature elimination) Reference : Python 데이터 분석 실무 04-06.모델 성과 개선 (WikiDocs) Simple, yet, Powerful Bankrupt Prediction Model sklearn.feature_selection.RFE, scikit-learn.org RFE는 주요 Feature를 선별해내는 기법 중 하나로 이름(Recursive feature elimination) 그대로 '반복적으로 feature를 제거해나가는' 방식이다. 대표적인 머신러닝 라이브러리 sklearn에서는 feature_selection 모듈을 제공한다. RFE는 아래와 같이 해당 모듈에서 import 할 수 있다. from sklearn.feature_..

sklearn - RandomForestClassifier

Random Forest reference: Random Forest(랜덤 포레스트) 개념 정리 sklearn.ensemble.RandomForestClassifier Bagging(Bootstrap aggregating) 모집단(데이터셋)에서 부분집합 형태로 임의의 N개를 추출하여 트리 하나를 만든다. 추출한 N개는 다시 넣어서 모집단 원본을 만들고, 또 다시 임의의 N개 데이터를 추출하여 두 번째 트리를 만든다.(실제로 데이터를 다시 넣지는 않는다. 중복을 허용한다는 의미로 서술) max_features 파라미터를 통해 feature는 최대 몇개를 샘플링하여 트리를 구성할 지 정의할 수 있다. 전체 트리 결과값이 나오면 가장 분포가 많은 값이 RandomForestClassifier 모델의 최종 결과..

sklearn - confusion_matrix()

sklearn.metrics.confusion_matrix reference : sklearn.metrics.confusion_matrix, scikit-learn.org 분류 성능평가, 데이터사이언스스쿨 Document sklearn.metrics.confusion_matrix(y_true, y_pred, *, labels=None, sample_weight=None, normalize=None) 사용 예시 from sklearn.metrics import confusion_matrix y_true = [2, 0, 2, 2, 0, 1] y_pred = [0, 0, 2, 2, 0, 2] confusion_matrix(y_true, y_pred) array([[2, 0, 0], [0, 0, 1], [1, ..

1