본문 바로가기

투닥투닥

DACON 금융문자 분석 경진대회 도전2

1. 지난 이야기

단순 튜토리얼만 진행,,

DACON은 정확도로 랭킹을 매긴다.

정확도는 맞춘 개수/전체 개수

한 쪽으로 편향되게 예측해도 정확도가 높을 수 있다는 얘기다.

즉, 스미싱이 아니다라고 다 예측하면 정확도가 높아질 수 있다.

2. 모든 값을 0으로 입력

smishing = 모두 0

 

3. 모든 값 0의 점수

0.423인데 생각해보니 smishing 값은 0과 1이 아니라 0에서 1 사이의 실수이므로

all 0이나 all 1을 생각한 것은 바보같은 짓이었다.

흠 그러면 기본적인 Random Forest를 적용해보자.

4. Random Forest

https://github.com/corazzon/KaggleStruggle/blob/master/word2vec-nlp-tutorial/tutorial-part-1.ipynb

 

corazzon/KaggleStruggle

Kaggle Struggle. Contribute to corazzon/KaggleStruggle development by creating an account on GitHub.

github.com

위 github 코드를 참고하였다.

 

code

from sklearn.ensemble import RandomForestClassifier

# 랜덤포레스트 분류기를 사용
forest = RandomForestClassifier(n_estimators = 100, n_jobs = -1, random_state=2018)
forest

output

RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
                       max_depth=None, max_features='auto', max_leaf_nodes=None,
                       min_impurity_decrease=0.0, min_impurity_split=None,
                       min_samples_leaf=1, min_samples_split=2,
                       min_weight_fraction_leaf=0.0, n_estimators=100,
                       n_jobs=-1, oob_score=False, random_state=2018, verbose=0,
                       warm_start=False)

 

code

%time forest = forest.fit(vec_x_train, Y_train)

output

CPU times: user 31.8 s, sys: 118 ms, total: 31.9 s
Wall time: 8.48 s

 

code

from sklearn.model_selection import cross_val_score
%time score = np.mean(cross_val_score(\
    forest, vec_x_train, \
    Y_train, cv=10, scoring='roc_auc'))
score

output

CPU times: user 9.96 s, sys: 2.54 s, total: 12.5 s
Wall time: 2min 28s
0.9999898936170213

0.9999?!!

 

당장 제출해보자!!!

y_train_pred1=forest.predict_proba(vec_x_train)
y_train_pred1_one= [ i[1]  for i in y_train_pred1]

y_test_pred1=forest.predict_proba(vec_x_test)
y_test_pred1_one= [ i[1]  for i in y_test_pred1]
cd /content/drive/My Drive/14th data
submission['smishing'] = y_test_pred1_one

submission.to_csv("14th_baseline_version_random_forest.csv",index=False) #현재 결과물인 output2를 구글 드라이브에 submission_test라는 이름으로 저장


5. 파일 생김새

 

6. 등수확인

0.1점 올랐당!