<jupyter_start><jupyter_text><jupyter_code>!pip install pycaret
import pycaret as pc
import pandas as pd
from pycaret.classification import *
from pycaret.utils import enable_colab

def load_data():
  df = pd.read_csv(
      'https://archive.ics.uci.edu/ml/machine-learning-databases/chess/king-rook-vs-king-pawn/kr-vs-kp.data',
      names=[
             "bkblk","bknwy","bkon8","bkona","bkspr","bkxbq","bkxcr","bkxwp","blxwp","bxqsq","cntxt","dsopp","dwipd",
             "hdchk","katri","mulch","qxmsq","r2ar8","reskd","reskr","rimmx","rkxwp","rxmsq","simpl","skach","skewr",
             "skrxp","spcop","stlmt","thrsk","wkcti","wkna8","wknck","wkovl","wkpos","wtoeg","result"
         ]) 
  return df

dataset_orig = load_data()
print(dataset_orig.head())
dataset = dataset_orig
data = dataset.sample(frac=0.9, random_state=786)
data_unseen = dataset.drop(data.index)

data.reset_index(drop=True, inplace=True)
data_unseen.reset_index(drop=True, inplace=True)

print('Data for Modeling: ' + str(data.shape))
print('Unseen Data For Predictions: ' + str(data_unseen.shape))
win = dataset[dataset['result'] == 'won']
nowin = dataset[dataset['result'] != 'won']
print(f'Number of entries with "win" class: {len(win)}')
print(f'Number of entries with "nowin" class: {len(nowin)}')
exp_mclf101 = setup(data = data, target = 'result', session_id=123) 
best = compare_models()

dt = create_model('dt')
lightgbm = create_model('lightgbm')
et = create_model('et')
rf = create_model('rf')
tuned_dt = tune_model(dt, n_iter=40, choose_better=True)
plot_model(tuned_dt, plot = 'confusion_matrix')
tuned_lightgbm = tune_model(lightgbm, n_iter=40, choose_better=True)
plot_model(tuned_lightgbm, plot = 'confusion_matrix')
tuned_et= tune_model(et, n_iter=40, choose_better=True)
plot_model(tuned_et, plot = 'confusion_matrix')
tuned_rf = tune_model(rf, n_iter=40, choose_better=True)
plot_model(tuned_rf, plot = 'confusion_matrix')
predict_model(tuned_dt);
predict_model(tuned_lightgbm);
predict_model(tuned_et);
predict_model(tuned_rf);
final_dt = finalize_model(tuned_dt)
unseen_predictions = predict_model(final_dt, data=data_unseen)
unseen_predictions.head()
tmp = unseen_predictions[unseen_predictions['Score'] == 1]
print(f"Percentage of entries with a score of 1: {len(tmp)/len(data_unseen) * 100:.0f}%")<jupyter_output>Percentage of entries with a score of 1: 100%
{'fraction_non_alphanumeric': 0.1635593220338983, 'fraction_numerical': 0.013983050847457627, 'mean_word_length': 7.2264808362369335, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '327099', 'license': 'MIT', 'n_tokens_mistral': 942, 'n_tokens_neox': 890, 'n_words': 147, 'path': 'AI_Report.ipynb', 'repo_name': 'dan032/ai-report', 'size': '2360'}