<jupyter_start><jupyter_text>CATEGORY BOOSTING ( CATBOOST )<jupyter_code>import numpy as np 
import pandas as pd 
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.metrics import mean_squared_error, r2_score
import matplotlib.pyplot as plt
from sklearn import model_selection
df = pd.read_csv("verisetleri\Hitters.csv")
df = df.dropna()
dms = pd.get_dummies(df[['League', 'Division', 'NewLeague']])
y = df["Salary"]
X_ = df.drop(['Salary', 'League', 'Division', 'NewLeague'], axis=1).astype('float64')
X = pd.concat([X_, dms[['League_N', 'Division_W', 'NewLeague_N']]], axis=1)
X_train, X_test, y_train, y_test =  train_test_split(X, y, test_size=0.25, random_state=42)
!pip install catboost
from catboost import CatBoostRegressor
catb_model = CatBoostRegressor().fit(X_train, y_train)
y_pred = catb_model.predict(X_test)
np.sqrt(mean_squared_error(y_test, y_pred))
## MODEL TUNNING
# iterations --> Ağaç sayısı, fit edilecek olan model sayısısdır.
# catboost kişisel bilgisayarda uygulamaya çalışırken en fazla işlemleri uzun süren algoritma olacak. Bu sebeple mümkün olduğu kadar az yazmak gerekir. Parametleri bir kaç tane arttırınca işlemler yaklaşık 45 dakika filan sürmektedir.
catb_params = {"iterations" : [200, 500, 1000], "learning_rate" : [0.01, 0.1], "depth" : [3, 6, 8]}
catb_model = CatBoostRegressor()
catb_cv_model = GridSearchCV(catb_model, catb_params, cv=5, n_jobs=-1, verbose=2).fit(X_train, y_train)
catb_cv_model.best_params_
catb_tuned = CatBoostRegressor(depth=3, iterations=200, learning_rate=0.1).fit(X_train, y_train)
y_pred = catb_tuned.predict(X_test)
np.sqrt(mean_squared_error(y_test, y_pred))
# Önceki algoritmalara göre en iyi sonucu buldu.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12002308136180034, 'fraction_numerical': 0.022504327755337564, 'mean_word_length': 7.29665071770335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, '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': '507176', 'license': 'CC0-1.0', 'n_tokens_mistral': 762, 'n_tokens_neox': 701, 'n_words': 152, 'path': '8 3 9 Category Boosting - CATBOOST Regresyon.ipynb', 'repo_name': 'celalaksu/Veri-Bilimi-renme-Notlar-m', 'size': '1733'}