<jupyter_start><jupyter_text>VotingClassifier - [ BaggingClassifier, RandomForestClassifier, XGBClassifier ]<jupyter_code>import pandas as pd
from xgboost import XGBClassifier, XGBRegressor
from sklearn.preprocessing import LabelEncoder
from sklearn.model_selection import train_test_split
from sklearn.metrics import f1_score
from sklearn.ensemble import BaggingClassifier, RandomForestClassifier, VotingClassifier
from sklearn.multiclass import OneVsOneClassifier,OneVsRestClassifier
from sklearn.svm import LinearSVC, SVC
from sklearn.linear_model import LinearRegression, LogisticRegression, RidgeClassifier
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
from sklearn.neighbors import KNeighborsClassifier
from imblearn.ensemble import BalancedBaggingClassifier, BalancedRandomForestClassifier
training_data = pd.read_csv('train.csv')
print(training_data.shape)
training_data.columns<jupyter_output>(6500, 10)<jupyter_text>Dropping columns -- [ 'ID','Team_Value','Playing_Style','Won_Championship','Previous_SB_Wins' ]<jupyter_code>y = training_data.Won_Championship
training_data = training_data.drop(columns=['Won_Championship','ID','Team_Value','Playing_Style','Previous_SB_Wins'],axis=1)

le_Number_Of_Injured_Players = LabelEncoder()
training_data['Number_Of_Injured_Players'] = le_Number_Of_Injured_Players.fit_transform(training_data['Number_Of_Injured_Players'])

le_Coach_Experience_Level = LabelEncoder()
training_data['Coach_Experience_Level'] = le_Coach_Experience_Level.fit_transform(training_data['Coach_Experience_Level'])
training_data.head()
x_train,x_test, y_train, y_test = train_test_split(training_data,y,test_size=0.2)
bags = BalancedBaggingClassifier(n_estimators=100,oob_score=True,bootstrap_features=True,replacement=True)
bags.fit(x_train,y_train)
#bags.fit(training_data,y)
prediction = bags.predict(x_test)
acc = 100 * (f1_score(y_test,prediction,average='binary'))
acc
bal_rfc = BalancedRandomForestClassifier(class_weight='balanced_subsample',criterion='entropy')
bal_rfc.fit(x_train,y_train)
#bal_rfc.fit(training_data,y)
prediction = bal_rfc.predict(x_test)
acc = 100 * (f1_score(y_test,prediction,average='binary'))
acc
xgb = XGBClassifier(n_estimators=500,learning_rate=0.1,max_depth=10,reg_lambda=0.1,importance_type='total_gain')
xgb.fit(x_train,y_train)
#xgb.fit(training_data,y)
prediction = xgb.predict(x_test)
acc = 100 * (f1_score(y_test,prediction,average='binary'))
acc
bag = BalancedBaggingClassifier(n_estimators=100,oob_score=True,bootstrap_features=True,replacement=True)
xgb = XGBClassifier(n_estimators=500,learning_rate=0.1,max_depth=10,reg_lambda=0.1,importance_type='total_gain')
bal_rfc = BalancedRandomForestClassifier(class_weight='balanced_subsample',criterion='entropy')

voting = VotingClassifier(estimators=[
        ('bag', bag), ('rfc', bal_rfc), ('xgb', xgb)], voting='hard')
voting.fit(training_data, y)
prediction = voting.predict(x_test)
acc = 100 * (f1_score(y_test,prediction,average='binary'))
acc
cols = training_data.columns
test_data = pd.read_csv('test.csv')
event_id = test_data['ID']

print(test_data.shape)
test_data = test_data.drop(columns=['ID','Team_Value','Playing_Style','Previous_SB_Wins'],axis=1)

test_data['Number_Of_Injured_Players'] = le_Number_Of_Injured_Players.fit_transform(test_data['Number_Of_Injured_Players'])

test_data['Coach_Experience_Level'] = le_Coach_Experience_Level.fit_transform(test_data['Coach_Experience_Level'])


predictions = voting.predict(test_data)
result_df = pd.DataFrame({'ID':event_id,'Won_Championship':predictions})
result_df.to_csv('Prediction.csv',index=False)<jupyter_output>(3500, 9)
{'fraction_non_alphanumeric': 0.11471801925722146, 'fraction_numerical': 0.015405777166437413, 'mean_word_length': 12.984615384615385, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '7634', 'license': 'MIT', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1282, 'n_words': 156, 'path': 'BIG_GAME - Hackerearth/6. VotingClassifier.ipynb', 'repo_name': 'phileinSophos/ML-DL_Problems', 'size': '3635'}