image_output_11.png image_output_5.png image_output_7.png image_output_4.png image_output_8.png image_output_6.png image_output_12.png image_output_3.png image_output_2.png image_output_1.png image_output_10.png image_output_9.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.model_selection import RepeatedStratifiedKFold,train_test_split,cross_val_score,RandomizedSearchCV,GridSearchCV

import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

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

import seaborn as sns

df = pd.read_excel('/kaggle/input/pumpkin-seeds-dataset/Pumpkin_Seeds_Dataset.xlsx')

df.shape

df.duplicated().sum()

df.isna().sum()

numerical_cols = df.select_dtypes(include=np.number).columns.to_list()
numerical_cols[:4]

skewness_values = df[numerical_cols].skew().to_list()
skewness_values[:3]

for col, sk in zip(numerical_cols, skewness_values):
    if abs(sk) >= 0.4:
        df[col] = np.log1p(df[col])

skewness_values = df[numerical_cols].skew().to_list()
skewness_values[:3]

cm = df.corr()

df['Class'] = np.where(df['Class'] == 'Çerçevelik', 1, 0)

X = df[numerical_cols]
y = df['Class']

cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=1)
model_0 = RandomForestClassifier(n_jobs=-1)
model_0_result = cross_val_score(model_0, X, y, scoring='accuracy', cv=cv, n_jobs=-1).mean()
model_0_result

model_1 = RandomForestClassifier(n_jobs=-1)
grid = {'n_estimators': np.arange(250, 501, 50), 'max_depth': np.arange(5, 16, 1), 'min_impurity_decrease': np.logspace(-5, -1, 30), 'max_features': ['auto', 0.6, 0.7, 0.8, 0.9], 'max_samples': np.arange(0.5, 1, 0.1), 'min_samples_split': np.arange(5, 16, 1), 'min_samples_leaf': np.arange(2, 16, 1)}
cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=1)
rs_model_1 = RandomizedSearchCV(model_1, param_distributions=grid, cv=cv, n_iter=50, verbose=1, n_jobs=-1, scoring='accuracy')
rs_model_1.fit(X, y)