<jupyter_start><jupyter_text>Podział<jupyter_code>df_blitz = df_sample[df_sample['Event_enc'] == 0]
df_bullet = df_sample[df_sample['Event_enc'] == 1]
df_classical = df_sample[df_sample['Event_enc'] == 2]
df_correspondence = df_sample[df_sample['Event_enc'] == 3]
df_blitz_features = df_blitz.drop('Result', axis = 1)
df_bullet_features = df_bullet.drop('Result', axis = 1)
df_classical_features = df_classical.drop('Result', axis = 1)
df_correspondence_features = df_correspondence.drop('Result', axis = 1)<jupyter_output><empty_output><jupyter_text>DT  BASIC<jupyter_code>decision_tree_classifier = DecisionTreeClassifier()
decision_tree_classifier.fit(X_train, y_train)
classifier_accuracy = decision_tree_classifier.score(X_test, y_test)

y_pred = decision_tree_classifier.predict(X_test)
print(decision_tree_classifier.score(X_test, y_test)*100)
print(classification_report(y_test, y_pred,digits = 5))

list(zip(X_train, decision_tree_classifier.feature_importances_*100))<jupyter_output>41.85826996028425
              precision    recall  f1-score   support

           1    0.40370   0.45298   0.42692     18716
           2    0.41823   0.41092   0.41454     18651
           3    0.43756   0.39192   0.41348     18782

    accuracy                        0.41858     56149
   macro avg    0.41983   0.41861   0.41831     56149
weighted avg    0.41985   0.41858   0.41831     56149<jupyter_text>BLITZ<jupyter_code>X_blitz = df_blitz_features.values
y_blitz = df_blitz['Result'].values

X_blitz_train, X_blitz_test, y_blitz_train, y_blitz_test = train_test_split(X_blitz, y_blitz, test_size=0.1, random_state = 42)
decision_tree_classifier = DecisionTreeClassifier()
decision_tree_classifier.fit(X_blitz_train, y_blitz_train)
classifier_accuracy = decision_tree_classifier.score(X_blitz_test, y_blitz_test)
y_blitz_pred = decision_tree_classifier.predict(X_blitz_test)
print(decision_tree_classifier.score(X_blitz_test, y_blitz_test)*100)
print(classification_report(y_blitz_test, y_blitz_pred,digits = 5))
list(zip(X_train, decision_tree_classifier.feature_importances_*100))<jupyter_output>41.0097192224622
              precision    recall  f1-score   support

           1    0.38457   0.43765   0.40940      8340
           2    0.40835   0.39698   0.40258      8406
           3    0.44114   0.39708   0.41795      9182

    accuracy                        0.41010     25928
   macro avg    0.41135   0.41057   0.40998     25928
weighted avg    0.41231   0.41010   0.41022     25928<jupyter_text>BULLET<jupyter_code>X_bullet = df_bullet_features.values
y_bullet = df_bullet['Result'].values

X_bullet_train, X_bullet_test, y_bullet_train, y_bullet_test = train_test_split(X_bullet, y_bullet, test_size=0.1, random_state = 42)
decision_tree_classifier = DecisionTreeClassifier()
decision_tree_classifier.fit(X_bullet_train, y_bullet_train)
classifier_accuracy = decision_tree_classifier.score(X_bullet_test, y_bullet_test)
y_bullet_pred = decision_tree_classifier.predict(X_bullet_test)
print(decision_tree_classifier.score(X_bullet_test, y_bullet_test)*100)
print(classification_report(y_bullet_test, y_bullet_pred,digits = 5))

list(zip(X_train, decision_tree_classifier.feature_importances_*100))<jupyter_output>46.87477208081103
              precision    recall  f1-score   support

           1    0.47053   0.52376   0.49572      5197
           2    0.49413   0.47366   0.48368      5240
           3    0.42129   0.37355   0.39599      3274

    accuracy                        0.46875     13711
   macro avg    0.46198   0.45699   0.45846     13711
weighted avg    0.46779   0.46875   0.46730     13711<jupyter_text>CLASSICAL<jupyter_code>X_classical = df_classical_features.values
y_classical = df_classical['Result'].values

X_classical_train, X_classical_test, y_classical_train, y_classical_test = train_test_split(X_classical, y_classical, test_size=0.1, random_state = 42)
decision_tree_classifier = DecisionTreeClassifier()
decision_tree_classifier.fit(X_classical_train, y_classical_train)
classifier_accuracy = decision_tree_classifier.score(X_classical_test, y_classical_test)
y_classical_pred = decision_tree_classifier.predict(X_classical_test)
print(decision_tree_classifier.score(X_classical_test, y_classical_test)*100)
print(classification_report(y_classical_test, y_classical_pred,digits = 5))
list(zip(X_train, decision_tree_classifier.feature_importances_*100))<jupyter_output>39.911417322834644
              precision    recall  f1-score   support

           1    0.35791   0.41791   0.38559      4879
           2    0.38179   0.37891   0.38034      5025
           3    0.45675   0.40066   0.42687      6352

    accuracy                        0.39911     16256
   macro avg    0.39882   0.39916   0.39760     16256
weighted avg    0.40391   0.39911   0.40010     16256<jupyter_text>CORRESPONDENCE<jupyter_code>X_correspondence = df_correspondence_features.values
y_correspondence = df_correspondence['Result'].values

X_correspondence_train, X_correspondence_test, y_correspondence_train, y_correspondence_test = train_test_split(X_correspondence, y_correspondence, test_size=0.1, random_state = 42)
decision_tree_classifier = DecisionTreeClassifier()
decision_tree_classifier.fit(X_correspondence_train, y_correspondence_train)
classifier_accuracy = decision_tree_classifier.score(X_correspondence_test, y_correspondence_test)
y_correspondence_pred = decision_tree_classifier.predict(X_correspondence_test)
print(decision_tree_classifier.score(X_correspondence_test, y_correspondence_test)*100)
print(classification_report(y_correspondence_test, y_correspondence_pred,digits = 5))
list(zip(X_train, decision_tree_classifier.feature_importances_*100))<jupyter_output>45.703125
              precision    recall  f1-score   support

           1    0.28125   0.32143   0.30000        56
           2    0.39706   0.40909   0.40299        66
           3    0.58065   0.53731   0.55814       134

    accuracy                        0.45703       256
   macro avg    0.41965   0.42261   0.42037       256
weighted avg    0.46782   0.45703   0.46167       256<jupyter_text>DT - STROJONY<jupyter_code>decision_tree_classifier = DecisionTreeClassifier(max_depth=6, max_features=5)
decision_tree_classifier.fit(X_train, y_train)
classifier_accuracy = decision_tree_classifier.score(X_test, y_test)

y_pred = decision_tree_classifier.predict(X_test)
print(decision_tree_classifier.score(X_test, y_test)*100)
print(classification_report(y_test, y_pred,digits = 5))

list(zip(X_train, decision_tree_classifier.feature_importances_*100))<jupyter_output>51.44348073874868
              precision    recall  f1-score   support

           1    0.59594   0.35793   0.44724     18716
           2    0.58504   0.41000   0.48213     18651
           3    0.45667   0.77409   0.57445     18782

    accuracy                        0.51443     56149
   macro avg    0.54588   0.51401   0.50127     56149
weighted avg    0.54573   0.51443   0.50138     56149<jupyter_text>RF<jupyter_code>from sklearn.model_selection import cross_val_score
from sklearn.metrics import classification_report
from sklearn.ensemble import RandomForestClassifier
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>BASIC<jupyter_code>rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_train, y_train)
classifier_accuracy = rf_classifier.score(X_test, y_test)

y_pred = rf_classifier.predict(X_test)
print(rf_classifier.score(X_test, y_test)*100)
print(classification_report(y_test, y_pred,digits = 5))

list(zip(X_train, rf_classifier.feature_importances_*100))<jupyter_output>44.36410265543464
              precision    recall  f1-score   support

           1    0.44111   0.41943   0.43000     18716
           2    0.44788   0.42711   0.43725     18651
           3    0.44216   0.48419   0.46222     18782

    accuracy                        0.44364     56149
   macro avg    0.44372   0.44357   0.44316     56149
weighted avg    0.44371   0.44364   0.44318     56149<jupyter_text>BLITZ<jupyter_code>rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_blitz_train, y_blitz_train)
classifier_accuracy = rf_classifier.score(X_blitz_test, y_blitz_test)
y_blitz_pred = rf_classifier.predict(X_blitz_test)
print(rf_classifier.score(X_blitz_test, y_blitz_test)*100)
print(classification_report(y_blitz_test, y_blitz_pred,digits = 5))
list(zip(X_train, rf_classifier.feature_importances_*100))<jupyter_output>43.9370564640543
              precision    recall  f1-score   support

           1    0.42055   0.39317   0.40640      8340
           2    0.44000   0.41744   0.42842      8406
           3    0.45333   0.50142   0.47616      9182

    accuracy                        0.43937     25928
   macro avg    0.43796   0.43734   0.43699     25928
weighted avg    0.43846   0.43937   0.43824     25928<jupyter_text>BULLET<jupyter_code>rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_bullet_train, y_bullet_train)
classifier_accuracy = rf_classifier.score(X_bullet_test, y_bullet_test)
y_bullet_pred = rf_classifier.predict(X_bullet_test)
print(rf_classifier.score(X_bullet_test, y_bullet_test)*100)
print(classification_report(y_bullet_test, y_bullet_pred,digits = 5))

list(zip(X_train, rf_classifier.feature_importances_*100))<jupyter_output>49.20866457588797
              precision    recall  f1-score   support

           1    0.50261   0.50087   0.50173      5197
           2    0.52212   0.50897   0.51546      5240
           3    0.43137   0.45113   0.44103      3274

    accuracy                        0.49209     13711
   macro avg    0.48537   0.48699   0.48607     13711
weighted avg    0.49305   0.49209   0.49248     13711<jupyter_text>CLASSICAL<jupyter_code>rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_classical_train, y_classical_train)
classifier_accuracy = rf_classifier.score(X_classical_test, y_classical_test)
y_classical_pred = rf_classifier.predict(X_classical_test)
print(rf_classifier.score(X_classical_test, y_classical_test)*100)
print(classification_report(y_classical_test, y_classical_pred,digits = 5))
list(zip(X_train, rf_classifier.feature_importances_*100))<jupyter_output>42.384350393700785
              precision    recall  f1-score   support

           1    0.39405   0.38307   0.38848      4879
           2    0.40556   0.37174   0.38791      5025
           3    0.45649   0.49638   0.47560      6352

    accuracy                        0.42384     16256
   macro avg    0.41870   0.41706   0.41733     16256
weighted avg    0.42201   0.42384   0.42235     16256<jupyter_text>CORRESPONDENCE<jupyter_code>rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_correspondence_train, y_correspondence_train)
classifier_accuracy = rf_classifier.score(X_correspondence_test, y_correspondence_test)
y_correspondence_pred = rf_classifier.predict(X_correspondence_test)
print(rf_classifier.score(X_correspondence_test, y_correspondence_test)*100)
print(classification_report(y_correspondence_test, y_correspondence_pred,digits = 5))
list(zip(X_train, rf_classifier.feature_importances_*100))<jupyter_output>48.828125
              precision    recall  f1-score   support

           1    0.33929   0.33929   0.33929        56
           2    0.43103   0.37879   0.40323        66
           3    0.57042   0.60448   0.58696       134

    accuracy                        0.48828       256
   macro avg    0.44691   0.44085   0.44316       256
weighted avg    0.48393   0.48828   0.48541       256<jupyter_text>RF - STROJONY<jupyter_code>rf_classifier = RandomForestClassifier(n_estimators=100, max_depth=6, min_samples_leaf=8, min_samples_split=15, n_jobs=-1, bootstrap=True)
rf_classifier.fit(X_train, y_train)
classifier_accuracy = rf_classifier.score(X_test, y_test)

y_pred = rf_classifier.predict(X_test)
print(rf_classifier.score(X_test, y_test)*100)
print(classification_report(y_test, y_pred,digits = 5))

list(zip(X_train, rf_classifier.feature_importances_*100))<jupyter_output>51.4114231776167
              precision    recall  f1-score   support

           1    0.60550   0.35510   0.44766     18716
           2    0.61613   0.35430   0.44989     18651
           3    0.45323   0.83127   0.58662     18782

    accuracy                        0.51411     56149
   macro avg    0.55829   0.51356   0.49473     56149
weighted avg    0.55810   0.51411   0.49489     56149<jupyter_text>D2<jupyter_code>df2 = pd.read_csv('../csv/d2_final.csv')
df2.head()
df2.drop(['Unnamed: 0','BlackElo','WhiteElo'], axis = 1, inplace = True)
df2.rename(columns={'Event': 'Event_enc', 'Termination': 'Termination_enc'}, inplace = True)
df2.head()
print(df2.shape)
feature_names = ['Event_enc', 'ECO_enc', 'Termination_enc', 'TimeControl_enc','EloDiff']
X2 = df2[feature_names].values
y2 = df2['Result'].values
print(X2.shape)
print(y2.shape)
decision_tree_classifier = DecisionTreeClassifier()

decision_tree_classifier.fit(X_train, y_train)

y_pred = decision_tree_classifier.predict(X2)
# print(decision_tree_classifier.score(y2, y_test))
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, decision_tree_classifier.feature_importances_*100))
decision_tree_classifier = DecisionTreeClassifier(criterion='entropy', max_depth=6, max_features=5)

decision_tree_classifier.fit(X_train, y_train)

y_pred = decision_tree_classifier.predict(X2)
# print(decision_tree_classifier.score(y2, y_test))
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, decision_tree_classifier.feature_importances_*100))
rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_train, y_train)

y_pred = rf_classifier.predict(X2)
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, rf_classifier.feature_importances_*100))
rf_classifier = RandomForestClassifier(n_estimators=100, max_depth=6, min_samples_leaf=8, min_samples_split=15, n_jobs=-1, bootstrap=True)
rf_classifier.fit(X_train, y_train)

y_pred = rf_classifier.predict(X2)
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, rf_classifier.feature_importances_*100))<jupyter_output>25.780712058001537
              precision    recall  f1-score   support

           1    0.64985   0.18599   0.28920     47170
           2    0.62187   0.19338   0.29502     42549
           3    0.11745   0.93604   0.20870      9037

    accuracy                        0.25781     98756
   macro avg    0.46306   0.43847   0.26431     98756
weighted avg    0.58908   0.25781   0.28434     98756<jupyter_text>DS2<jupyter_code>df2_sample = pd.read_csv('../csv/df2_sample.csv')
df2_sample.head()
df2_sample.drop(['BlackElo', 'WhiteElo'], axis = 1, inplace = True)
df2_sample.rename(columns={'Event': 'Event_enc', 'Termination': 'Termination_enc'}, inplace = True)
df2_sample.head()
print(df2_sample.shape)
feature_names = ['Event_enc', 'ECO_enc', 'Termination_enc', 'TimeControl_enc','EloDiff']
X2 = df2_sample[feature_names].values
y2 = df2_sample['Result'].values
print(X2.shape)
print(y2.shape)
decision_tree_classifier = DecisionTreeClassifier()

decision_tree_classifier.fit(X_train, y_train)

y_pred = decision_tree_classifier.predict(X2)
# print(decision_tree_classifier.score(y2, y_test))
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, decision_tree_classifier.feature_importances_*100))
decision_tree_classifier = DecisionTreeClassifier(criterion='entropy', max_depth=6, max_features=5)
decision_tree_classifier.fit(X_train, y_train)
y_pred = decision_tree_classifier.predict(X2)
# print(decision_tree_classifier.score(y2, y_test))
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, decision_tree_classifier.feature_importances_*100))
rf_classifier = RandomForestClassifier()
rf_classifier.fit(X_train, y_train)

y_pred = rf_classifier.predict(X2)
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, rf_classifier.feature_importances_*100))
rf_classifier = RandomForestClassifier(n_estimators=100, max_depth=6, min_samples_leaf=8, min_samples_split=15, n_jobs=-1, bootstrap=True)
rf_classifier.fit(X_train, y_train)

y_pred = rf_classifier.predict(X2)
print(accuracy_score(y2, y_pred)*100)
print(classification_report(y2, y_pred,digits = 5))

list(zip(X2, rf_classifier.feature_importances_*100))<jupyter_output>43.690752830954224
              precision    recall  f1-score   support

           1    0.56973   0.18037   0.27400      9037
           2    0.58755   0.19531   0.29317      9037
           3    0.39772   0.93504   0.55807      9037

    accuracy                        0.43691     27111
   macro avg    0.51833   0.43691   0.37508     27111
weighted avg    0.51833   0.43691   0.37508     27111
StarcoderdataJupyterStructuredCleanDedup