<jupyter_start><jupyter_text>Modeling- Random Forest- Logistic Regression- XGBoost  1. Random Forest- Precision/Recall/F1: 0.88/0.88/0.88<jupyter_code>from sklearn.ensemble import RandomForestClassifier

rf = RandomForestClassifier(random_state=random_state)
model = rf.fit(X_train, y_train)
pred = model.predict(X_test)
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
print(confusion_matrix(y_test, pred))
print(classification_report(y_test, pred))
rf.estimator_params
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold

cv = KFold(5)
cv_scores = cross_val_score(model, X_train, y_train, cv=cv)

print('Cross Val Scores: ', cv_scores)
print('Avg Score of CV: {:.3f}'.format(cv_scores.mean()))
import operator

importance_dict = {}
for imp, col in zip(rf.feature_importances_, X_train.columns):
    importance_dict[col] = imp

sorted_imp = sorted(importance_dict.items(), key=lambda x: x[1])

cols = [item[0] for item in sorted_imp]
imps = [item[1] for item in sorted_imp]
# plt.figure(figsize=(10, 7))

# sns.barplot(x=imps, y=cols, palette='OrRd_r')
# plt.title('Feature Importances')
# plt.show()
# N = float(len(cols))
# c = ['hsl('+str(h)+',80%'+',60%)' for h in np.linspace(0, 360, N)]
colors = ['#ff0033', '#0066cc', '#00cc99', '#ff6600']
marker = []
for i in range(4):
    if colors[i] == '#00cc99':
        marker += [colors[i]] * 4
    else:
        marker += [colors[i]] * 3
marker = marker[::-1]

data = [go.Bar(
    x=imps,
    y=cols,
    orientation='h',
    marker=dict(
        color=marker
    ),
    opacity=0.9
)]

layout = go.Layout(
    title='Feature Importances of Random Forest',
    xaxis=dict(
        title='Importances'
    ), 
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig)<jupyter_output><empty_output><jupyter_text>Feature Importances- KDA/킬 관여율/death/assist/KDA 3 이상일 것- 1) Death 대비 Kill/Assist (3인분 이상)와 2) 얼마나 덜 죽고 3) 킬에 많이 관여하는 지<jupyter_code>test, test_label = PrepareData(test).prepare_data()
test_pred = model.predict(test)
print(confusion_matrix(test_label, test_pred))
print(classification_report(test_label, test_pred))<jupyter_output>precision    recall  f1-score   support

          0       0.86      0.88      0.87      1991
          1       0.89      0.88      0.89      2302

avg / total       0.88      0.88      0.88      4293<jupyter_text>2. Logistic Regression- Precision/Recall/F1: 0.90/0.90/0.90<jupyter_code>from sklearn.linear_model import LogisticRegression

lr = LogisticRegression(random_state=random_state)
model_lr = lr.fit(X_train, y_train)
cv_scores = cross_val_score(model_lr, X_train, y_train, cv=cv)

print('Cross Val Scores: ', cv_scores)
print('Avg Score of CV: {:.3f}'.format(cv_scores.mean()))
test_pred = model_lr.predict(test)
print(confusion_matrix(test_label, test_pred))
print(classification_report(test_label, test_pred))<jupyter_output>precision    recall  f1-score   support

          0       0.89      0.88      0.89      1991
          1       0.90      0.91      0.90      2302

avg / total       0.90      0.90      0.90      4293<jupyter_text>3. XGBoost- Precision/Recall/Fl: 0.90/0.90/0/90<jupyter_code>import xgboost as xgb

dtrain = xgb.DMatrix(X_train.values, label=y_train)
dtest = xgb.DMatrix(X_test.values, label=y_test)
num_boost_round = 200
params = {'objective': 'multi:softmax', 
          'eval_metric': 'mlogloss',
          'num_class': 2, 
          'max_delta_step': 3, 
          'eta': 0.2}

evals = [(dtrain, 'train'), (dtest, 'eval')]

bst = xgb.train(params=params,  
                dtrain=dtrain, 
                num_boost_round=num_boost_round, 
                evals=evals,
                early_stopping_rounds=10)
pred_xgb = bst.predict(dtest)
print(confusion_matrix(y_test, pred_xgb))
print(classification_report(y_test, pred_xgb))
dtest_data = xgb.DMatrix(test.values, label=test_label)
pred = bst.predict(dtest_data)
print(confusion_matrix(test_label, pred))
print(classification_report(test_label, pred))<jupyter_output>precision    recall  f1-score   support

          0       0.90      0.88      0.89      1991
          1       0.90      0.92      0.91      2302

avg / total       0.90      0.90      0.90      4293
{'fraction_non_alphanumeric': 0.1269167256428403, 'fraction_numerical': 0.050719509318235434, 'mean_word_length': 3.393782383419689, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '136938', 'license': 'MIT', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1610, 'n_words': 316, 'path': 'modeling.ipynb', 'repo_name': 'novdov/lol-result-prediction', 'size': '4239'}