Kaggle competition: Costa Rican Household Poverty Level Prediction
df_all[df_all.Fare.isnull() ]<groupby>
df = pd.read_csv('/kaggle/input/costa-rican-household-poverty-prediction/train.csv')
 test = pd.read_csv('/kaggle/input/costa-rican-household-poverty-prediction/test.csv')
 df.shape, test.shape
fare_price = df_all.groupby(['Embarked', 'Pclass', 'Sex'] ).Fare.median()
print(fare_price)
 fare_price = fare_price['S'][3]['male']
fare_price<data_type_conversions>
heads = df.loc[df['parentesco1'] == 1].copy()
train_campos = df.loc[(df['Target'].notnull())&(df['parentesco1'] == 1), ['Target', 'idhogar']]
l_counts = train_campos['Target'].value_counts().sort_index()
l_counts
df_all.Fare = df_all.Fare.fillna(fare_price )<groupby>
all_equal = df.groupby('idhogar')['Target'].apply(lambda x: x.nunique() == 1)
 not_equal = all_equal[all_equal != True]
print('Encontramos {} Individuos na mesma familia no mesmo domícilio que possuem um nível de probreza diferente e precisamos corrigir.'.format(len(not_equal)) )
df_all['Deck'] = df_all['Cabin'].apply(lambda x: x[0] if pd.notnull(x)else 'M')
 df_all_decks = df_all.groupby(['Deck', 'Pclass'] ).count().drop(columns=['Survived', 'Sex', 'Age', 'SibSp', 'Parch',
'Fare', 'Embarked', 'Cabin', 'PassengerId', 'Ticket'] ).rename(columns={'Name': 'Count'} ).transpose()
df_all_decks<statistical_test>
for household in not_equal.index:
true_target = int(df[(df['idhogar'] == household)&(df['parentesco1'] == 1.0)]['Target'])
 df.loc[df['idhogar'] == household, 'Target'] = true_target
all_equal = df.groupby('idhogar')['Target'].apply(lambda x: x.nunique() == 1)
 not_equal = all_equal[all_equal != True]
print('Encontramos {} familias no mesmo domícilio que possuem um nível de probreza diferente.'.format(len(not_equal)) )
def get_pclass_dist(df):
deck_counts = {'A': {}, 'B': {}, 'C': {}, 'D': {}, 'E': {}, 'F': {}, 'G': {}, 'M': {}, 'T': {}}
decks = df.columns.levels[0]
for deck in decks:
for pclass in range(1, 4):
try:
count = df[deck][pclass][0]
deck_counts[deck][pclass] = count
except KeyError:
deck_counts[deck][pclass] = 0
df_decks = pd.DataFrame(deck_counts)
 deck_percentages = {}
for col in df_decks.columns:
deck_percentages[col] = [(count / df_decks[col].sum())* 100 for count in df_decks[col]]
return deck_counts, deck_percentages
all_deck_count, all_deck_per = get_pclass_dist(df_all_decks)
 all_deck_per<feature_engineering>
households_leader = df.groupby('idhogar')['parentesco1'].sum()
households_no_head = df.loc[df['idhogar'].isin(households_leader[households_leader == 0].index), :]
print('There are {} households without a head.'.format(households_no_head['idhogar'].nunique()))
idx = df_all[df_all['Deck'] == 'T'].index
df_all.loc[idx, 'Deck'] = 'A'<count_values>
households_no_head_equal = households_no_head.groupby('idhogar')['Target'].apply(lambda x: x.nunique() == 1)
 print('{} Households with no head have different labels.'.format(sum(households_no_head_equal == False)) )
df_all['Deck'] = df_all['Deck'].replace(['A', 'B', 'C'], 'ABC')
 df_all['Deck'] = df_all['Deck'].replace(['D', 'E'], 'DE')
 df_all['Deck'] = df_all['Deck'].replace(['F', 'G'], 'FG')
 df_all['Deck'].value_counts()<drop_column>
df_all = df.append(test)
 df_all.shape
df_all.drop(['Cabin'], inplace=True, axis=1 )<split>
df_all.drop('area2', axis = 1, inplace = True )
df_train.index[-1]
def divide_df(all_data,last_idx_train, first_idx_test, resp_col):
return all_data.loc[:last_idx_train], all_data.loc[last_idx_train:].drop([resp_col], axis = 1)
 df_train, df_test = divide_df(df_all, df_train.index[-1], df_test.index[0], 'Survived')
 df_train.name = 'Training Set'
df_test.name = 'Testing Set'
dfs = [df_train, df_test]
print_missing_val_count(dfs )<filter>
df_all['walls'] = np.argmax(np.array(df_all[['epared1', 'epared2', 'epared3']]),
axis = 1)
 df_all = df_all.drop(columns = ['epared1', 'epared2', 'epared3'])
corr = df_train_corr['Correlation Coefficient'] > 0.1
df_train_corr[corr]<filter>
df_all['walls'].value_counts()
corr = df_test_corr['Correlation Coefficient'] > 0.1
df_test_corr[corr]<feature_engineering>
df_all['Fare'] = pd.qcut(df_all['Fare'], 12 )<feature_engineering>
df_all['Age'] = pd.qcut(df_all['Age'], 10 )<categorify>
df_all['Ticket_Frequency'] = df_all.groupby('Ticket')['Ticket'].transform('count' )<feature_engineering>
df_all.isnull().sum().sort_values()
df_all['Title'] = df_all['Name'].str.split(', ', expand=True)[1].str.split('.', expand=True)[0]
df_all['Is_Married'] = 0
df_all['Is_Married'].loc[df_all['Title'] == 'Mrs'] = 1<string_transform>
df_all['edjefa'].value_counts()
def extract_surname(data):
families = []
for i in range(len(data)) :
name = data.iloc[i]
if '(' in name:
name_no_bracket = name.split('(')[0]
else:
name_no_bracket = name
family = name_no_bracket.split(',')[0]
title = name_no_bracket.split(',')[1].strip().split(' ')[0]
for c in string.punctuation:
family = family.replace(c, '' ).strip()
families.append(family)
 return families
df_all['Family'] = extract_surname(df_all['Name'])
 df_train = df_all.loc[:890]
df_test = df_all.loc[891:]
dfs = [df_train, df_test]<define_variables>
df_all['edjefe'].value_counts()
mean_survival_rate = np.mean(df_train['Survived'])
 train_family_survival_rate = []
train_family_survival_rate_NA = []
test_family_survival_rate = []
test_family_survival_rate_NA = []
for i in range(len(df_train)) :
if df_train['Family'][i] in family_rates:
train_family_survival_rate.append(family_rates[df_train['Family'][i]])
 train_family_survival_rate_NA.append(1)
 else:
train_family_survival_rate.append(mean_survival_rate)
 train_family_survival_rate_NA.append(0)
 for i in range(len(df_test)) :
if df_test['Family'].iloc[i] in family_rates:
test_family_survival_rate.append(family_rates[df_test['Family'].iloc[i]])
 test_family_survival_rate_NA.append(1)
 else:
test_family_survival_rate.append(mean_survival_rate)
 test_family_survival_rate_NA.append(0)
 df_train['Family_Survival_Rate'] = train_family_survival_rate
df_train['Family_Survival_Rate_NA'] = train_family_survival_rate_NA
df_test['Family_Survival_Rate'] = test_family_survival_rate
df_test['Family_Survival_Rate_NA'] = test_family_survival_rate_NA
train_ticket_survival_rate = []
train_ticket_survival_rate_NA = []
test_ticket_survival_rate = []
test_ticket_survival_rate_NA = []
for i in range(len(df_train)) :
if df_train['Ticket'][i] in ticket_rates:
train_ticket_survival_rate.append(ticket_rates[df_train['Ticket'][i]])
 train_ticket_survival_rate_NA.append(1)
 else:
train_ticket_survival_rate.append(mean_survival_rate)
 train_ticket_survival_rate_NA.append(0)
 for i in range(len(df_test)) :
if df_test['Ticket'].iloc[i] in ticket_rates:
test_ticket_survival_rate.append(ticket_rates[df_test['Ticket'].iloc[i]])
 test_ticket_survival_rate_NA.append(1)
 else:
test_ticket_survival_rate.append(mean_survival_rate)
 test_ticket_survival_rate_NA.append(0)
 df_train['Ticket_Survival_Rate'] = train_ticket_survival_rate
df_train['Ticket_Survival_Rate_NA'] = train_ticket_survival_rate_NA
df_test['Ticket_Survival_Rate'] = test_ticket_survival_rate
df_test['Ticket_Survival_Rate_NA'] = test_ticket_survival_rate_NA<feature_engineering>
mapeamento = {'yes': 1, 'no': 0}
df_all['edjefa'] = df_all['edjefa'].replace(mapeamento ).astype(int)
 df_all['edjefe'] = df_all['edjefe'].replace(mapeamento ).astype(int )
for df in [df_train, df_test]:
df['Survival_Rate'] =(df['Ticket_Survival_Rate'] + df['Family_Survival_Rate'])/ 2
df['Survival_Rate_NA'] =(df['Ticket_Survival_Rate_NA'] + df['Family_Survival_Rate_NA'])/ 2<categorify>
df_all['edjefe'].value_counts()
non_numeric_features = ['Embarked', 'Sex', 'Deck', 'Title', 'Family_Size_Grouped', 'Age', 'Fare']
for df in dfs:
for feature in non_numeric_features:
df[feature] = LabelEncoder().fit_transform(df[feature] )<categorify>
df_all['edjefa'].value_counts()
cat_features = ['Pclass', 'Sex', 'Deck', 'Embarked', 'Title', 'Family_Size_Grouped']
encoded_features = []
for df in dfs:
for feature in cat_features:
encoded_feat = OneHotEncoder().fit_transform(df[feature].values.reshape(-1, 1)).toarray()
n = df[feature].nunique()
cols = ['{}_{}'.format(feature, n)for n in range(1, n + 1)]
encoded_df = pd.DataFrame(encoded_feat, columns=cols)
 encoded_df.index = df.index
encoded_features.append(encoded_df)
 df_train = pd.concat([df_train, *encoded_features[:6]], axis=1)
 df_test = pd.concat([df_test, *encoded_features[6:]], axis=1 )<concatenate>
df_all['dependency'].value_counts().sort_values()
df_all = pd.concat([df_train, df_test], sort = True ).reset_index(drop = True)
 drop_cols = ['Deck', 'Embarked', 'Family', 'Family_Size', 'Family_Size_Grouped', 'Survived',
'Name', 'Parch', 'PassengerId', 'Pclass', 'Sex', 'SibSp', 'Ticket', 'Title',
'Ticket_Survival_Rate', 'Family_Survival_Rate', 'Ticket_Survival_Rate_NA', 'Family_Survival_Rate_NA']
df_all.drop(columns=drop_cols, inplace=True)
 df_all.head()<normalization>
df_all['dependency'] = df_all['dependency'].replace(mapeamento ).astype(float )
X_train = StandardScaler().fit_transform(df_train.drop(columns=drop_cols))
y_train = df_train['Survived'].values
X_test = StandardScaler().fit_transform(df_test.drop(columns=drop_cols))
print('X_train shape: {}'.format(X_train.shape))
print('y_train shape: {}'.format(y_train.shape))
print('X_test shape: {}'.format(X_test.shape))<choose_model_class>
df_all['dependency'].value_counts()
single_best_model = RandomForestClassifier(criterion='gini',
n_estimators=1100,
max_depth=5,
min_samples_split=4,
min_samples_leaf=5,
max_features='auto',
oob_score=True,
random_state=SEED,
n_jobs=-1,
verbose=1)
 leaderboard_model = RandomForestClassifier(criterion='gini',
n_estimators=1750,
max_depth=7,
min_samples_split=6,
min_samples_leaf=6,
max_features='auto',
oob_score=True,
random_state=SEED,
n_jobs=-1,
verbose=1 )<train_model>
df_all['dependency'].isnull().sum()
N = 5
oob = 0
probs = pd.DataFrame(np.zeros(( len(X_test), N * 2)) , columns=['Fold_{}_Prob_{}'.format(i, j)for i in range(1, N + 1)for j in range(2)])
 importances = pd.DataFrame(np.zeros(( X_train.shape[1], N)) , columns=['Fold_{}'.format(i)for i in range(1, N + 1)], index=df_all.columns)
 fprs, tprs, scores = [], [], []
skf = StratifiedKFold(n_splits=N, random_state=N, shuffle=True)
 for fold,(trn_idx, val_idx)in enumerate(skf.split(X_train, y_train), 1):
print('Fold {}
'.format(fold))
leaderboard_model.fit(X_train[trn_idx], y_train[trn_idx])
 trn_fpr, trn_tpr, trn_thresholds = roc_curve(y_train[trn_idx], leaderboard_model.predict_proba(X_train[trn_idx])[:, 1])
 trn_auc_score = auc(trn_fpr, trn_tpr)
 val_fpr, val_tpr, val_thresholds = roc_curve(y_train[val_idx], leaderboard_model.predict_proba(X_train[val_idx])[:, 1])
 val_auc_score = auc(val_fpr, val_tpr)
 scores.append(( trn_auc_score, val_auc_score))
fprs.append(val_fpr)
 tprs.append(val_tpr)
 probs.loc[:, 'Fold_{}_Prob_0'.format(fold)] = leaderboard_model.predict_proba(X_test)[:, 0]
probs.loc[:, 'Fold_{}_Prob_1'.format(fold)] = leaderboard_model.predict_proba(X_test)[:, 1]
importances.iloc[:, fold - 1] = leaderboard_model.feature_importances_
oob += leaderboard_model.oob_score_ / N
print('Fold {} OOB Score: {}
'.format(fold, leaderboard_model.oob_score_))
print('Average OOB Score: {}'.format(oob))<save_to_csv>
df_all.isnull().sum().sort_values()
class_survived = [col for col in probs.columns if col.endswith('Prob_1')]
probs['1'] = probs[class_survived].sum(axis=1)/ N
probs['0'] = probs.drop(columns=class_survived ).sum(axis=1)/ N
probs['pred'] = 0
pos = probs[probs['1'] >= 0.5].index
probs.loc[pos, 'pred'] = 1
y_pred = probs['pred'].astype(int)
 submission_df = pd.DataFrame(columns=['PassengerId', 'Survived'])
 submission_df['PassengerId'] = df_test['PassengerId']
submission_df['Survived'] = y_pred.values
submission_df.to_csv('submissions.csv', header=True, index=False)
 submission_df.head(10 )<set_options>
df_all['Target'].value_counts()
%matplotlib inline
warnings.filterwarnings('ignore')
<load_from_csv>
df_all[df_all['parentesco1'] == 1]['v2a1'].isnull().sum()
df_train = pd.read_csv('.. /input/titanic/train.csv')
 df_test = pd.read_csv('.. /input/titanic/test.csv')
 combined = [df_train,df_test]
print("Ok!" )<concatenate>
df_all['v2a1'].value_counts()
for dataset in combined:
missing_data = dataset.isnull().sum().sort_values(ascending=False)
 missing_percent =(dataset.isnull().sum() * 100 / dataset.shape[0] ).sort_values(ascending=False)
 df_missing = pd.concat([missing_data,missing_percent], axis = 1, keys = ['Ausentes','%'])
 print(df_missing)
 print('-'*50 )<feature_engineering>
df_all['v2a1'].isnull().sum()
for dataset in combined:
dataset['Cabin'][~dataset['Cabin'].isnull() ] = 1
dataset['Cabin'][dataset['Cabin'].isnull() ] = 0
print("Ok!" )<data_type_conversions>
df_all['v18q'].value_counts()
for dataset in combined:
media = dataset['Age'].mean()
dataset['Age'] = dataset['Age'].fillna(media)
 print("Ok!" )<define_variables>
df_all['v18q'].isnull().sum()
bebe = [0,5,0]
crianca = [6,13,1]
jovem = [14,18,2]
jovemAdulto =[19,25,3]
Adulto = [26,60,4]
Idoso = [61,85,5]
idades = [bebe,crianca,jovem,jovemAdulto,Adulto,Idoso]
for dataset in combined:
dataset['AgeClass'] = dataset['Age'].astype(int)
 for i in range(len(dataset['Age'])) :
for idade in idades:
if(dataset['Age'][i] >= idade[0] and dataset['Age'][i] <= idade[1]):
dataset['AgeClass'][i] = idade[2]
break
print("Ok!" )<data_type_conversions>
df_all['v18q1'].value_counts()
for dataset in combined:
dataset['Embarked'] = dataset['Embarked'].fillna('S')
 print("Ok!" )<data_type_conversions>
df_all['v18q1'].isnull().sum()
for dataset in combined:
dataset['Embarked'] = dataset['Embarked'].map({'Q': 0, 'S': 1, 'C': 2} ).astype(int)
 print('Ok!' )<data_type_conversions>
df_all['SQBmeaned'].fillna(-1, inplace=True)
 df_all['meaneduc'].fillna(-1, inplace=True)
 df_all['rez_esc'].fillna(-1, inplace=True )
for dataset in combined:
dataset['Fare'] = dataset['Fare'].fillna(dataset['Fare'].median())
 print('Ok!' )<categorify>
df_all.isnull().sum().sort_values()
muitoBaixo = [0,7.99,1]
baixo = [8,14.99,2]
medio = [15,31.99,3]
alto =[32,513,4]
fares = [muitoBaixo,baixo,medio,alto]
for dataset in combined:
dataset['FareClass'] = dataset['Fare'].astype(int)
 for i in range(len(dataset['Fare'])) :
for fare in fares:
if(dataset['Fare'][i] >= fare[0] and dataset['Fare'][i] <= fare[1]):
dataset['FareClass'][i] = fare[2]
break
print("Ok!" )<feature_engineering>
df_all['phone-pc'] = df_all['qmobilephone'] / df_all['tamviv']
df_all['tablets-pc'] = df_all['v18q1'] / df_all['tamviv']
df_all['rooms-pc'] = df_all['rooms'] / df_all['tamviv']
df_all['rent-pc'] = df_all['v2a1'] / df_all['tamviv']
for dataset in combined:
dataset['Title'] = dataset.Name.str.extract('([A-Za-z]+)\.',expand=False)
 print("Ok!" )<feature_engineering>
feats = [c for c in df_all.columns if c not in ['Id', 'idhogar', 'Target']]
for dataset in combined:
dataset['Title'] = dataset['Title'].replace(['Lady', 'Countess','Capt', 'Col',\
	'Don', 'Dr', 'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona'], 'Rare')
 dataset['Title'] = dataset['Title'].replace('Mlle', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Ms', 'Miss')
 dataset['Title'] = dataset['Title'].replace('Mme', 'Mrs')
 print("Ok!" )<categorify>
rf = RandomForestClassifier(n_jobs=-1, n_estimators=200, random_state=42 )
title_mapping = {"Mr": 1, "Miss": 2, "Mrs": 3, "Master": 4, "Rare": 5}
for dataset in combined:
dataset['Title'] = dataset['Title'].map(title_mapping)
 dataset['Title'] = dataset['Title'].fillna(0)
 print("Ok!" )<data_type_conversions>
rf.fit(train[feats], train['Target'])
for dataset in combined:
dataset['Sex'] = dataset['Sex'].map({'female': 0, 'male': 1} ).astype(int)
 print("Ok!" )<drop_column>
df_all['Target'].value_counts().sort_values()
drop_elements = ['Name', 'Ticket','PassengerId']
combined[0] = combined[0].drop(drop_elements,1)
 print("Ok!" )<drop_column>
test['Target'] = rf.predict(test[feats] ).astype(int )
drop_elements = ['Name', 'Ticket','PassengerId']
combined[1] = combined[1].drop(drop_elements,1)
 print("Ok!" )<drop_column>
test['Target'].value_counts(normalize=True )
drop_elements = ['Age', 'Fare']
combined[0] = combined[0].drop(drop_elements,1)
 combined[1] = combined[1].drop(drop_elements,1)
 print("Ok!" )<prepare_x_and_y>
abc = AdaBoostClassifier(n_estimators=200, learning_rate=1.0, random_state=42)
 abc.fit(train[feats], train['Target'])
 accuracy_score(test['Target'], abc.predict(test[feats]))
df_train = combined[0]
df_test = combined[1]
df_train['Cabin'] = df_train['Cabin'].astype(int)
 df_test['Cabin'] = df_test['Cabin'].astype(int)
 y_train = df_train['Survived']
x_train = df_train.drop('Survived',1)
 x_test = df_test
print("Ok!" )<compute_train_metric>
gbm = GradientBoostingClassifier(n_estimators=200, learning_rate=1.0, max_depth=1, random_state=42)
 gbm.fit(train[feats], train['Target'])
 accuracy_score(test['Target'], gbm.predict(test[feats]))
decisiontree = DecisionTreeClassifier()
scores = -1 * cross_val_score(decisiontree, x_train, y_train,
cv=5,
scoring='neg_mean_absolute_error')
 print("MAE:
", scores.mean() )<compute_train_metric>
test[['Id', 'Target']].to_csv('submission.csv', index=False )
randomforest = RandomForestClassifier()
scores = -1 * cross_val_score(randomforest, x_train, y_train,
cv=5,
scoring='neg_mean_absolute_error')
 print("MAE:
", scores.mean() )<compute_train_metric>
heads = train[train['parentesco1'] == 1]
gaussianNb = GaussianNB()
scores = -1 * cross_val_score(gaussianNb, x_train, y_train,
cv=5,
scoring='neg_mean_absolute_error')
 print("MAE:
", scores.mean() )<compute_train_metric>
heads['hsize-pc'] = heads['hhsize'] / heads['tamviv']
heads['phone-pc'] = heads['qmobilephone'] / heads['tamviv']
heads['tablets-pc'] = heads['v18q1'] / heads['tamviv']
heads['rooms-pc'] = heads['rooms'] / heads['tamviv']
heads['rent-pc'] = heads['v2a1'] / heads['tamviv']
linearDA = LinearDiscriminantAnalysis()
scores = -1 * cross_val_score(linearDA, x_train, y_train,
cv=5,
scoring='neg_mean_absolute_error')
 print("MAE:
", scores.mean() )<compute_train_metric>
rf2 = RandomForestClassifier(max_depth=None, random_state=42, n_jobs=4, n_estimators=700,
min_impurity_decrease=1e-3, min_samples_leaf=2,
verbose=0, class_weight='balanced' )
logreg = LogisticRegression()
scores = -1 * cross_val_score(logreg, x_train, y_train,
cv=5,
scoring='neg_mean_absolute_error')
 print("MAE:
", scores.mean() )<compute_train_metric>
rf2.fit(heads[feats], heads['Target'] )
svmsvc = svm.SVC()
scores = -1 * cross_val_score(svmsvc, x_train, y_train,
cv=5,
scoring='neg_mean_absolute_error')
 print("MAE:
", scores.mean() )<predict_on_test>
test['Target'] = rf2.predict(test[feats] ).astype(int )
clf = svm.SVC()
clf.fit(x_train, y_train)
 y_pred = clf.predict(x_test)
 y_pred = np.rint(y_pred)
 y_pred = abs(y_pred)
 print("Ok!" )<save_to_csv>
test['Target'].value_counts(normalize=True )
gender_submission = pd.read_csv('.. /input/titanic/gender_submission.csv')
 gender_submission['Survived'] = y_pred
gender_submission['Survived'] = gender_submission['Survived'].astype(int)
 gender_submission.to_csv('submission.csv', index=False)
 print("Ok!" )<import_modules>
abc = AdaBoostClassifier(n_estimators=200, learning_rate=1.0, random_state=42)
 abc.fit(heads[feats], heads['Target'])
 accuracy_score(test['Target'], abc.predict(test[feats]))
import numpy as np
import pandas as pd
from mlens.ensemble import SuperLearner
from xgboost import XGBClassifier
from lightgbm import LGBMClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, f1_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.linear_model import SGDClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.neural_network import MLPClassifier
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.linear_model import RidgeClassifier, Perceptron, PassiveAggressiveClassifier
import optuna
from optuna.samplers import TPESampler
import matplotlib.pyplot as plt
import plotly.express as px
import warnings
from sklearn.exceptions import ConvergenceWarning<set_options>
gbm = GradientBoostingClassifier(n_estimators=200, learning_rate=1.0, max_depth=1, random_state=42)
 gbm.fit(heads[feats], heads['Target'])
 accuracy_score(test['Target'], gbm.predict(test[feats]))
optuna.logging.set_verbosity(optuna.logging.WARNING)
 warnings.filterwarnings(action='ignore', category=ConvergenceWarning )<load_from_csv>
test[['Id', 'Target']].to_csv('submission.csv', index=False )
train = pd.read_csv('/kaggle/input/titanic/train.csv')
 test = pd.read_csv('/kaggle/input/titanic/test.csv' )<count_missing_values>
cm = confusion_matrix('Target', test['prediction'] )