How to know if there is a way to improve this model and also how should I know if I reached a particular models limit

I’m new in data science so when I do models I’m not sure if I reached the end and also I don’t know how else can I improve the model. This here is random forest classifier for which I used RandomizeSearchCV for parameters and eventually got 73% which was the highest. Also I used class_weight to balance out the classes, I scaled everything and cleaned the data as you will see. I’m not sure if this is THE BEST way to do this and also I don’t know if 73% is good enough when making models and also if I reached a limit with Random Forest Classifier.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
import pandas as pd
import numpy as np
from sklearn.compose import ColumnTransformer
from sklearn.model_selection import RandomizedSearchCV, train_test_split
from sklearn.preprocessing import OneHotEncoder, StandardScaler, LabelEncoder, MinMaxScaler, MaxAbsScaler, RobustScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, accuracy_score, confusion_matrix
from imblearn.over_sampling import SMOTE
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
df = pd.read_csv('pokemon_data.csv')
duplicates = df.duplicated()
if duplicates.any():
print(df[duplicates], "DUPLICATE")
else:
print("NO DUPLICATES")
class_dist = df['type1'].value_counts()
print(class_dist)
df.replace('—', np.nan, inplace=True)
numerical_cols = df.select_dtypes(include=np.number).columns
df[numerical_cols] = df[numerical_cols].fillna(df[numerical_cols].median())
# Now we fill missing data for categorical columns
categorical_cols = df.select_dtypes(include='object').columns
df[categorical_cols] = df[categorical_cols].fillna('Unknown')
preprocessor = ColumnTransformer(
transformers=[
('num', StandardScaler(), ['dexnum']),
('cat', OneHotEncoder(handle_unknown='ignore'), ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2'])
])
features = ['species', 'ability1', 'ability2', 'egg_group1',
'egg_group2']
X = df[features] # variables we use to predict
y_type1 = df['type1'] # what we predict
y_type2 = df['type2'] # what we predict
preprocessor = ColumnTransformer(
transformers=[
('num', StandardScaler(), []),
('cat', OneHotEncoder(handle_unknown='ignore'), ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2'])
])
# Train_test_split is used to split the dataset into two subsets, a training and testing set
X_train, X_test, y_type1_train, y_type1_test = train_test_split(X, y_type1, test_size=0.4, random_state=42)
X_train = preprocessor.fit_transform(X_train)
X_test = preprocessor.transform(X_test)
param_dist = {
'n_estimators': [9000],
'max_depth': [1000],
'min_samples_split': [2],
'min_samples_leaf': [1],
'max_features': ['log2'],
'bootstrap': [False]
}
rf_type1 = RandomForestClassifier(class_weight='balanced', random_state=42)
random_search = RandomizedSearchCV(estimator=rf_type1, param_distributions=param_dist, n_iter=50, cv=5, verbose=2, random_state=42, n_jobs=-1)
random_search.fit(X_train, y_type1_train)
# Get the best parameters
print("Best parameters found: ", random_search.best_params_)
print("Best accuracy: ", random_search.best_score_)
# Re-train the model with the best parameters
best_rf = random_search.best_estimator_
y_type1_pred_best = best_rf.predict(X_test)
# Evaluate the model
print("Type1 Classification Report with Best Parameters:")
print(classification_report(y_type1_test, y_type1_pred_best))
print("Type1 Accuracy with Best Parameters:", accuracy_score(y_type1_test, y_type1_pred_best))
</code>
<code>from matplotlib import pyplot as plt from matplotlib.colors import ListedColormap import pandas as pd import numpy as np from sklearn.compose import ColumnTransformer from sklearn.model_selection import RandomizedSearchCV, train_test_split from sklearn.preprocessing import OneHotEncoder, StandardScaler, LabelEncoder, MinMaxScaler, MaxAbsScaler, RobustScaler from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import classification_report, accuracy_score, confusion_matrix from imblearn.over_sampling import SMOTE pd.set_option('display.max_rows', None) pd.set_option('display.max_columns', None) df = pd.read_csv('pokemon_data.csv') duplicates = df.duplicated() if duplicates.any(): print(df[duplicates], "DUPLICATE") else: print("NO DUPLICATES") class_dist = df['type1'].value_counts() print(class_dist) df.replace('—', np.nan, inplace=True) numerical_cols = df.select_dtypes(include=np.number).columns df[numerical_cols] = df[numerical_cols].fillna(df[numerical_cols].median()) # Now we fill missing data for categorical columns categorical_cols = df.select_dtypes(include='object').columns df[categorical_cols] = df[categorical_cols].fillna('Unknown') preprocessor = ColumnTransformer( transformers=[ ('num', StandardScaler(), ['dexnum']), ('cat', OneHotEncoder(handle_unknown='ignore'), ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2']) ]) features = ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2'] X = df[features] # variables we use to predict y_type1 = df['type1'] # what we predict y_type2 = df['type2'] # what we predict preprocessor = ColumnTransformer( transformers=[ ('num', StandardScaler(), []), ('cat', OneHotEncoder(handle_unknown='ignore'), ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2']) ]) # Train_test_split is used to split the dataset into two subsets, a training and testing set X_train, X_test, y_type1_train, y_type1_test = train_test_split(X, y_type1, test_size=0.4, random_state=42) X_train = preprocessor.fit_transform(X_train) X_test = preprocessor.transform(X_test) param_dist = { 'n_estimators': [9000], 'max_depth': [1000], 'min_samples_split': [2], 'min_samples_leaf': [1], 'max_features': ['log2'], 'bootstrap': [False] } rf_type1 = RandomForestClassifier(class_weight='balanced', random_state=42) random_search = RandomizedSearchCV(estimator=rf_type1, param_distributions=param_dist, n_iter=50, cv=5, verbose=2, random_state=42, n_jobs=-1) random_search.fit(X_train, y_type1_train) # Get the best parameters print("Best parameters found: ", random_search.best_params_) print("Best accuracy: ", random_search.best_score_) # Re-train the model with the best parameters best_rf = random_search.best_estimator_ y_type1_pred_best = best_rf.predict(X_test) # Evaluate the model print("Type1 Classification Report with Best Parameters:") print(classification_report(y_type1_test, y_type1_pred_best)) print("Type1 Accuracy with Best Parameters:", accuracy_score(y_type1_test, y_type1_pred_best)) </code>
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
import pandas as pd
import numpy as np
from sklearn.compose import ColumnTransformer
from sklearn.model_selection import RandomizedSearchCV, train_test_split
from sklearn.preprocessing import OneHotEncoder, StandardScaler, LabelEncoder, MinMaxScaler, MaxAbsScaler, RobustScaler
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report, accuracy_score, confusion_matrix
from imblearn.over_sampling import SMOTE

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
df = pd.read_csv('pokemon_data.csv')

duplicates = df.duplicated()
if duplicates.any():
    print(df[duplicates], "DUPLICATE")
else:
    print("NO DUPLICATES")
    
class_dist = df['type1'].value_counts()
print(class_dist)

df.replace('—', np.nan, inplace=True)
numerical_cols = df.select_dtypes(include=np.number).columns
df[numerical_cols] = df[numerical_cols].fillna(df[numerical_cols].median())
# Now we fill missing data for categorical columns
categorical_cols = df.select_dtypes(include='object').columns
df[categorical_cols] = df[categorical_cols].fillna('Unknown')


preprocessor = ColumnTransformer(
    transformers=[
        ('num', StandardScaler(), ['dexnum']),
        ('cat', OneHotEncoder(handle_unknown='ignore'), ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2'])
    ])

features = ['species', 'ability1', 'ability2', 'egg_group1',
            'egg_group2']

X = df[features] # variables we use to predict 
y_type1 = df['type1'] # what we predict
y_type2 = df['type2'] # what we predict

preprocessor = ColumnTransformer(
    transformers=[
        ('num', StandardScaler(), []),
        ('cat', OneHotEncoder(handle_unknown='ignore'), ['species', 'ability1', 'ability2', 'egg_group1', 'egg_group2'])
    ])

# Train_test_split is used to split the dataset into two subsets, a training and testing set
X_train, X_test, y_type1_train, y_type1_test = train_test_split(X, y_type1, test_size=0.4, random_state=42)

X_train = preprocessor.fit_transform(X_train)
X_test = preprocessor.transform(X_test)

param_dist = {
    'n_estimators': [9000],
    'max_depth': [1000],
    'min_samples_split': [2],
    'min_samples_leaf': [1],
    'max_features': ['log2'],
    'bootstrap': [False]
}

rf_type1 = RandomForestClassifier(class_weight='balanced', random_state=42)
random_search = RandomizedSearchCV(estimator=rf_type1, param_distributions=param_dist, n_iter=50, cv=5, verbose=2, random_state=42, n_jobs=-1)
random_search.fit(X_train, y_type1_train)

# Get the best parameters
print("Best parameters found: ", random_search.best_params_)
print("Best accuracy: ", random_search.best_score_)

# Re-train the model with the best parameters
best_rf = random_search.best_estimator_
y_type1_pred_best = best_rf.predict(X_test)

# Evaluate the model
print("Type1 Classification Report with Best Parameters:")
print(classification_report(y_type1_test, y_type1_pred_best))
print("Type1 Accuracy with Best Parameters:", accuracy_score(y_type1_test, y_type1_pred_best))




Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật