해결된 질문
작성
·
39
0
df = pd.DataFrame({
'f1': [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],
'f2': [30, 28, 26, 24, 22, 20, 18, 16, 14, 12],
'target': ['A', 'A', 'A', 'B', 'B', 'A', 'A', 'A', 'A', 'B']
})
y_train = df.pop('target')
x_tr, x_val, y_tr, y_val = train_test_split(df, y_train, test_size=0.5, random_state=123)
print(x_tr.shape, x_val.shape, y_tr.shape, y_val.shape)
model_rfc = RandomForestClassifier(random_state=42)
model_rfc.fit(x_tr, y_tr)
y_proba_val_rfc = model_rfc.predict_proba(x_val)
print(y_proba_val_rfc)
roc = roc_auc_score(y_val, y_proba_val_rfc[:,1])
print(roc)
(5, 2) (5, 2) (5,) (5,)
[[0.29 0.71]
[0.92 0.08]
[0.7 0.3 ]
[0.74 0.26]
[0.45 0.55]]
1.0
-------------------------------------------------------------------------
df = pd.DataFrame({
'f1': [2, 3, 5, 7, 11, 13, 17, 19, 23, 29],
'f2': [30, 28, 26, 24, 22, 20, 18, 16, 14, 12],
'target': ['A', 'A', 'A', 'B', 'B', 'A', 'A', 'A', 'A', 'B']
})
target = df.pop('target')
X_train, X_val, y_train, y_val = train_test_split(df, target, test_size=0.5, random_state=0)
clf = RandomForestClassifier(random_state=42)
clf.fit(X_train, y_train)
y_pred = clf.predict_proba(X_val)[:,1]
print(y_pred) # 예측값
roc_auc_score(y_val, y_pred) # 정확도 평가
[0.68 0. 0.25 0. 0.26]
np.float64(0.25)
답변 1
0
random_state로 고민하지는 마시죠!!
랜덤적인 요소를 고정적으로 만든다 생각하고 특정 숫자로 고정하시면 됩니다.
컴피티션(대회) 같이 0.001이 중요한 경우 random_state 도 성능을 높이기 위한 도구로 사용하기도 하나
빅분기 시험은 그런 상황이 아닙니다 🙂 편안하게 아무 숫자로 사용해 주세요!