Home Credit Default Risk Competition

Home Credit Default Risk Competition

  • 결측값을 대체하는 방법 - Imputer
# imputer for handling missing values
from sklearn.preprocessing import Imputer
imputer = Imputer(strategy = 'median') 
  • 다항회귀 만드는법 - PolynomialFeatures
from sklearn.preprocessing import PolynomialFeatures
                                  
# Create the polynomial object with specified degree
poly_transformer = PolynomialFeatures(degree = 3)
  • 원래 변수보다 taget변수와의 상관관계가 높은 다항식들이 존재한다.
EXT_SOURCE_2 EXT_SOURCE_3                -0.193939
EXT_SOURCE_1 EXT_SOURCE_2 EXT_SOURCE_3   -0.189605
EXT_SOURCE_2 EXT_SOURCE_3 DAYS_BIRTH     -0.181283
EXT_SOURCE_2^2 EXT_SOURCE_3              -0.176428
EXT_SOURCE_2 EXT_SOURCE_3^2              -0.172282
EXT_SOURCE_1 EXT_SOURCE_2                -0.166625
EXT_SOURCE_1 EXT_SOURCE_3                -0.164065
EXT_SOURCE_2                             -0.160295
EXT_SOURCE_2 DAYS_BIRTH                  -0.156873
EXT_SOURCE_1 EXT_SOURCE_2^2              -0.156867
Name: TARGET, dtype: float64
DAYS_BIRTH     -0.078239
DAYS_BIRTH^2   -0.076672
DAYS_BIRTH^3   -0.074273
TARGET          1.000000
1                    NaN
Name: TARGET, dtype: float64
  • LogisticRegression
    • Parameter C값을 조정해서 과소적합 혹은 과대적합을 해결할 수 있다.
    • C값이 크면 훈련을 복잡하게해서 약한규제를 하게하고 과대적합으로 이어질 수 있다.
    • C값이 작으면 훈련을 간단하게해서 강한규제를 하게하고 과소적합으로 이어질 수 있다.
from sklearn.linear_model import LogisticRegression

# Make the model with the specified regularization parameter
log_reg = LogisticRegression(C = 0.0001)

  • Bootstrap
      1. 30개의 표본 하나를 복원추출.
      1. n번 반복.
      1. n번 재표본추출한 값의 평균.
      1. K번을 반복해 총 K개의 평균을 구함
      1. K개를 사용하여 신뢰구간을 구합니다.
  • bootstrap sampling에서 어떤 데이터 포인트는 약 36.6%정도 누락될 확률이 존재
    • 100개의 표본중 표본 하나가 선택되지 않을 확률은 99/100
    • 뽑은 표본을 제외하지 않고 100번 반복할 때 한번도 선택되지 않을 확률: (0.99)^100 = 0.366
독립변수가 10개있고 데이터 100 있으면은 배깅은 독립변수는 10개를 사용하고 복원추출 여러개의 tree를 만들어서 배깅이고 
  • RandomForest
    • n_estimators 는 tree의 수
    • criterion는 gini or entropy
    • max_features 는 선택되는 최대 독립변수
    • verbose는 생산과정 출력
    • n_jobs는 적합성과 예측성을 위해 병렬로 실행할 작업 수
    • random_state는 난수 seed설정
    • n_jobs는 사용하는 cpu core의 수
      • n_jobs = -1이면 컴퓨터의 모든 코어를 사용
RandomForestClassifier(n_estimators=100, *, criterion='gini', max_depth=None, 
                       min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0,
                       max_features='auto', max_leaf_nodes=None, min_impurity_decrease=0.0,
                       min_impurity_split=None, bootstrap=True, oob_score=False, n_jobs=None,
                       random_state=None, verbose=0, warm_start=False, class_weight=None, 
                       ccp_alpha=0.0, max_samples=None)[source]
from sklearn.ensemble import RandomForestClassifier

# Make the random forest classifier
random_forest = RandomForestClassifier(n_estimators = 100, random_state = 50, verbose = 1, n_jobs = -1)
  • References
    • https://bkshin.tistory.com/entry/DATA-12
    • https://woolulu.tistory.com/28
    • https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html
    • https://www.kaggle.com/willkoehrsen/start-here-a-gentle-introduction#Feature-Engineering

Comments