image_output_1.png
from sklearn.ensemble import GradientBoostingClassifier

from sklearn.model_selection import GridSearchCV

from sklearn.model_selection import RandomizedSearchCV

from sklearn.model_selection import train_test_split

import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_data = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv')

train_data.isnull().sum().sum()

fig, ax = plt.subplots(5,5,figsize = (8,8))
for i in range(5):
    for j in range(5):
        ax[i][j].axis('off')
        ax[i][j].imshow(train_data.iloc[[i+(j*5)], 1:].to_numpy().astype(np.uint8).reshape(28, 28), cmap='gray')

plt.show()
#temp = train_data.iloc[:1, 1:].to_numpy().reshape(28,28)
#plt.imshow(temp, cmap='gray')

yX = train_data.copy()
y = yX.pop('label')
X = yX.copy()
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.9, random_state=42)
(X_train.shape, X_test.shape, y_train.shape, y_test.shape)

model = GradientBoostingClassifier()
params_dict = {'learning_rate': np.linspace(0.05, 0.3, 6), 'subsample': np.linspace(0.3, 1, 10), 'n_estimators': range(10, 40, 5), 'max_depth': range(2, 20, 2), 'min_samples_split': range(2, 20, 1)}
clf = RandomizedSearchCV(model, params_dict, scoring='accuracy', n_iter=15, verbose=2, cv=3)
search = clf.fit(X_train, y_train)
search.best_params_

learning_rate_params = {'learning_rate': np.linspace(0.08, 0.12, 5), 'subsample': [search.best_params_['subsample']], 'n_estimators': [search.best_params_['n_estimators']], 'max_depth': [search.best_params_['max_depth']], 'min_samples_split': [search.best_params_['min_samples_split']]}
lr_clf = GridSearchCV(model, learning_rate_params, scoring='accuracy', verbose=2, cv=2)
lr_search = lr_clf.fit(X_train, y_train)
lr_search.best_params_