Kaggle competition: Don't Get Kicked!
VotingPredictor = VotingClassifier(estimators=[('ExtC', ExtC_best),('GBC',GBC_best), 
('SVMC', SVMC_best),('random_forest', random_forest_best)], voting='soft', n_jobs=4)
 VotingPredictor = VotingPredictor.fit(X_train, Y_train)
 VotingPredictor_predictions = VotingPredictor.predict(test)
 test_Survived = pd.Series(VotingPredictor_predictions, name="Survived")
 test_Survived = pd.Series(VotingPredictor_predictions, name="Survived")
 Submission3 = pd.concat([PassengerId,test_Survived],axis=1)
 Submission3.head(15 )<save_to_csv>
train_data=pd.read_csv('/kaggle/input/DontGetKicked/training.csv')
 train_data.head()
Submission3.to_csv("StackingSubmission.csv", index=False)
 print("Completed." )<load_from_csv>
test_data=pd.read_csv('/kaggle/input/DontGetKicked/test.csv')
 test_data.head()
train_df = pd.read_csv("/kaggle/input/titanic/train.csv")
 print("*"*10, "Dataset information", "*"*10)
 print(train_df.info())
 print("*"*10, "First 5 test rows", "*"*10)
 print(train_df.head(5))<load_from_csv>
train_data.isnull().sum()
test_df = pd.read_csv("/kaggle/input/titanic/test.csv")
 print("*"*10, "Dataset information", "*"*10)
 print(test_df.info())
 print("*"*10, "Last 5 test rows", "*"*10)
 print(test_df.tail(5))<count_values>
test_data.isnull().sum()
train_df.Cabin.value_counts()<count_values>
train_data['IsBadBuy'].value_counts()
train_df.Cabin.value_counts() 
<count_missing_values>
train_data['Model'].value_counts()
train_df["Age"].isnull().sum()<data_type_conversions>
train_data.drop('Model',axis=1,inplace=True)
 test_data.drop('Model',axis=1,inplace=True )
data = [train_df, test_df]
for dataset in data:
mean = train_df["Age"].mean()
dataset['Age'] = dataset['Age'].fillna(mean)
 dataset["Age"] = train_df["Age"].astype(float)
 train_df["Age"].isnull().sum()<feature_engineering>
train_data['Trim'].value_counts()
<categorify>
train_data.drop('Trim',axis=1,inplace=True)
 test_data.drop('Trim',axis=1,inplace=True )
deck = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6, "G": 7, "U": 8}
data = [train_df, test_df]
for dataset in data:
dataset['Deck'] = dataset['Cabin'].fillna("U")
 dataset['Deck'] = dataset['Cabin'].astype(str ).str[0]
dataset['Deck'] = dataset['Deck'].str.capitalize()
dataset['Deck'] = dataset['Deck'].map(deck)
 dataset['Deck'] = dataset['Deck'].fillna(0)
 dataset['Deck'] = dataset['Deck'].astype(int)
 train_df['Deck'].value_counts()
train_df = train_df.drop(['Cabin'], axis=1)
 test_df.drop(['Cabin'], axis=1, inplace = True )<count_values>
train_data['SubModel'].value_counts()
print(train_df['Deck'].value_counts() )<count_values>
train_data.drop('SubModel',axis=1,inplace=True)
 test_data.drop('SubModel',axis=1,inplace=True )
train_df.Sex.value_counts()<categorify>
train_data['Color'].value_counts()
common_value = 'S'
data = [train_df, test_df]
for dataset in data:
dataset['Embarked'] = dataset['Embarked'].fillna(common_value)
 train_df.info()<categorify>
test_data['Color'].value_counts()
data = [train_df, test_df]
titles = {"Mr": 1, "Miss": 2, "Mrs": 3, "Master": 4, "Rare": 5}
for dataset in data:
dataset['Title'] = dataset['Name'].str.extract('([A-Za-z]+)\.')
 dataset['Title'] = dataset['Title'].replace(['Lady', 'Countess','Capt', 'Col','Don', 'Dr',\
'Major', 'Rev', 'Sir', 'Jonkheer', 'Dona', 'Mlle', 'Ms', 'Mme'], 'Rare')
 dataset['Title'] = dataset['Title'].map(titles)
 dataset['Title'] = dataset['Title'].fillna(0)
 print(train_df['Title'].value_counts())
 train_df = train_df.drop(['Name'], axis=1)
 test_df = test_df.drop(['Name'], axis=1)
 train_df['Title'].value_counts() 
<count_values>
train_data['Color'].fillna(value='Color_Unknown',inplace=True)
 test_data['Color'].fillna(value='Color_Unknown',inplace=True )
train_df['Ticket'].value_counts()
train_df = train_df.drop(['Ticket'], axis=1)
 test_df = test_df.drop(['Ticket'], axis=1)
<feature_engineering>
print("Number of null values in color column"+str(train_data['Color'].isnull().sum()))
print("Number of null values in color column"+str(test_data['Color'].isnull().sum()))
data = [train_df, test_df]
for dataset in data:
dataset.loc[ dataset['Age'] <= 11, 'Age'] = 0
dataset.loc[(dataset['Age'] > 11)&(dataset['Age'] <= 18), 'Age'] = 1
dataset.loc[(dataset['Age'] > 18)&(dataset['Age'] <= 22), 'Age'] = 2
dataset.loc[(dataset['Age'] > 22)&(dataset['Age'] <= 27), 'Age'] = 3
dataset.loc[(dataset['Age'] > 27)&(dataset['Age'] <= 33), 'Age'] = 4
dataset.loc[(dataset['Age'] > 33)&(dataset['Age'] <= 40), 'Age'] = 5
dataset.loc[(dataset['Age'] > 40)&(dataset['Age'] <= 66), 'Age'] = 6
dataset.loc[ dataset['Age'] > 66, 'Age'] = 6
train_df['Age'].value_counts()<feature_engineering>
train_data['Transmission'].value_counts()
data = [train_df, test_df]
for dataset in data:
dataset.loc[ dataset['Fare'] <= 7.91, 'Fare'] = 0
dataset.loc[(dataset['Fare'] > 7.91)&(dataset['Fare'] <= 14.454), 'Fare'] = 1
dataset.loc[(dataset['Fare'] > 14.454)&(dataset['Fare'] <= 31), 'Fare'] = 2
dataset.loc[(dataset['Fare'] > 31)&(dataset['Fare'] <= 99), 'Fare'] = 3
dataset.loc[(dataset['Fare'] > 99)&(dataset['Fare'] <= 250), 'Fare'] = 4
dataset.loc[ dataset['Fare'] > 250, 'Fare'] = 5
dataset['Fare'] = dataset['Fare'].astype(float)
 train_df['Fare'].value_counts() 
<data_type_conversions>
test_data['Transmission'].value_counts()
<drop_column>
train_data[train_data['Transmission']=='Manual']
train_df = train_df.drop(['PassengerId'], axis=1 )<prepare_x_and_y>
train_data['Transmission'].replace("Manual","MANUAL",inplace=True )
X_train = train_df.drop('Survived', axis=1)
 Y_train = train_df['Survived']
test_df.head(10 )<drop_column>
train_data['Transmission'].value_counts()
X_test = test_df.drop("PassengerId", axis=1 ).copy()
X_test.head(10 )<drop_column>
train_data['Transmission'].fillna(value='Transmission_Unk',inplace=True)
 test_data['Transmission'].fillna(value='Transmission_Unk',inplace=True )
<compute_train_metric>
train_data['WheelTypeID'].value_counts()
clf = LogisticRegression()
clf.fit(X_train, Y_train)
 Y_pred = clf.predict(X_test)
 scores = cross_val_score(clf, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores)
 print("Mean: ", scores.mean())
 print("Standard Deviation: ", scores.std())
<find_best_model_class>
train_data.drop('WheelTypeID',axis=1,inplace=True)
 test_data.drop('WheelTypeID',axis=1,inplace=True )
clf_svm = svm.SVC()
clf_svm.fit(X_train, Y_train)
 Y_pred_svm = clf_svm.predict(X_test)
 scores_svm = cross_val_score(clf_svm, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_svm.mean() )<choose_model_class>
train_data['WheelType'].value_counts()
clf_dt = tree.DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',
max_depth=None, max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=5, min_samples_split=25,
min_weight_fraction_leaf=0.0, presort='deprecated',
random_state=None, splitter='best')
 clf_dt.fit(X_train, Y_train)
 Y_pred_svm = clf_dt.predict(X_test)
 scores_dt = cross_val_score(clf_dt, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_dt.mean() )<find_best_model_class>
test_data['WheelType'].value_counts()
clf_rf = RandomForestClassifier(max_depth=2, random_state=0)
 clf_rf.fit(X_train, Y_train)
 Y_pred_rf = clf_rf.predict(X_test)
 scores_rf = cross_val_score(clf_rf, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_rf.mean() )<find_best_model_class>
train_data['WheelType'].fillna(value='WheelType_unk',inplace=True)
 test_data['WheelType'].fillna(value='WheelType_unk',inplace=True )
clf_gbc = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0, max_depth=1, random_state=0)
 clf_gbc.fit(X_train, Y_train)
 Y_pred_rf = clf_gbc.predict(X_test)
 scores_rf = cross_val_score(clf_gbc, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_rf.mean())
<find_best_model_class>
train_data['WheelType'].value_counts()
clf_bagging = BaggingClassifier()
clf_bagging.fit(X_train, Y_train)
 Y_pred_rf = clf_bagging.predict(X_test)
 scores_rf = cross_val_score(clf_bagging, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_rf.mean() )<find_best_model_class>
train_data['Nationality'].value_counts()
clf_gnb = GaussianNB()
clf_gnb.fit(X_train, Y_train)
 Y_pred_rf = clf_gnb.predict(X_test)
 scores_rf = cross_val_score(clf_gnb, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_rf.mean())
<compute_train_metric>
test_data['Nationality'].value_counts()
clf_xgb = XGBClassifier().fit(X_train, Y_train)
 Y_pred = clf_xgb.predict(X_test)
 clf_xgb.score(X_train, Y_train)
 scores_rf = cross_val_score(clf_xgb, X_train, Y_train, cv = 10, scoring = "accuracy")
 print("Scores: ",scores_rf.mean() )<choose_model_class>
train_data['Nationality'].fillna(value='Nationality_unk',inplace=True)
 test_data['Nationality'].fillna(value='Nationality_unk',inplace=True )
random_forest = RandomForestClassifier(bootstrap=True, ccp_alpha=0.0, class_weight=None,
criterion='gini', max_depth=None, max_features='auto',
max_leaf_nodes=None, max_samples=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=5, min_samples_split=16,
min_weight_fraction_leaf=0.0, n_estimators=700,
n_jobs=-1, oob_score=True, random_state=1, verbose=0,
warm_start=False)
 scores = cross_val_score(random_forest, X_train, Y_train, cv=10, scoring = "accuracy")
 print("Scores:", scores)
 print("Mean:", scores.mean())
 print("Standard Deviation:", scores.std())
<choose_model_class>
train_data['Size'].value_counts()
<train_on_grid>
test_data['Size'].value_counts()
<choose_model_class>
train_data['Size'].fillna(value='Size_unk',inplace=True)
 test_data['Size'].fillna(value='Size_unk',inplace=True )
<save_to_csv>
train_data['TopThreeAmericanName'].value_counts()
<set_options>
test_data['TopThreeAmericanName'].value_counts()
%matplotlib inline<load_from_csv>
train_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True)
 test_data['TopThreeAmericanName'].fillna(value='Top_unk',inplace=True )
train = pd.read_csv('.. /input/titanic/train.csv')
 test = pd.read_csv('.. /input/titanic/test.csv' )<drop_column>
train_data['PRIMEUNIT'].value_counts()
train = train.drop(['PassengerId','Name','SibSp','Parch'], axis = 1)
 test = test.drop(['Name','SibSp','Parch'], axis = 1 )<count_missing_values>
test_data['PRIMEUNIT'].value_counts()
print("TRAIN DATA:")
 train.isnull().sum()<count_missing_values>
train_data['PRIMEUNIT'].fillna(value='Prime_unk',inplace=True)
 test_data['PRIMEUNIT'].fillna(value='Prime_unk',inplace=True )
print("TEST DATA:")
 test.isnull().sum()<define_variables>
train_data['AUCGUART'].replace("AGREEN","GREEN",inplace=True)
 test_data['AUCGUART'].replace("ARED","RED",inplace=True )
numerical = ['Pclass','Age','Is_alone','Fare']
categorical = ['Sex','Ticket','Cabin', 'Embarked']<define_variables>
train_data['AUCGUART'].fillna(value='AUC_unk',inplace=True)
 test_data['AUCGUART'].fillna(value='AUC_unk',inplace=True )
features = numerical + categorical
target = ['Survived']
print('Features:', features, '
Target:', target )<categorify>
train_data.drop(['MMRAcquisitionAuctionAveragePrice', 'MMRAcquisitionAuctionCleanPrice' ,
'MMRAcquisitionRetailAveragePrice' , 'MMRAcquisitonRetailCleanPrice' ,
'MMRCurrentAuctionAveragePrice' , 'MMRCurrentAuctionCleanPrice' ,
'MMRCurrentRetailAveragePrice' , 'MMRCurrentRetailCleanPrice' ],
axis=1,inplace=True)
 test_data.drop(['MMRAcquisitionAuctionAveragePrice', 'MMRAcquisitionAuctionCleanPrice' ,
'MMRAcquisitionRetailAveragePrice' , 'MMRAcquisitonRetailCleanPrice' ,
'MMRCurrentAuctionAveragePrice' , 'MMRCurrentAuctionCleanPrice' ,
'MMRCurrentRetailAveragePrice' , 'MMRCurrentRetailCleanPrice' ],
axis=1,inplace=True )
numerical_transformer = Pipeline(
 steps=[('iterative', IterativeImputer(max_iter = 10, random_state=0)) , 
('scaler', StandardScaler())])
 categorical_transformer = Pipeline(
 steps=[('imputer', SimpleImputer(strategy='most_frequent')) , 
('onehot', OneHotEncoder(handle_unknown='ignore')) ])
 preprocessor = ColumnTransformer(
 transformers=[('num', numerical_transformer, numerical), 
('cat', categorical_transformer, categorical)] )<create_dataframe>
train_data.drop(['PurchDate'],axis=1,inplace=True)
 test_data.drop(['PurchDate'],axis=1,inplace=True )
observations = pd.DataFrame()
classifiers = ['Linear SVM', 'Radial SVM', 'LogisticRegression',
'RandomForestClassifier', 'AdaBoostClassifier',
'XGBoostClassifier', 'KNeighborsClassifier']
models = [svm.SVC(kernel='linear'),
svm.SVC(kernel='rbf'),
LogisticRegression() ,
RandomForestClassifier(n_estimators=200, random_state=0),
AdaBoostClassifier(random_state = 0),
xgb.XGBClassifier(n_estimators=100),
KNeighborsClassifier()
]
j = 0
for i in models:
model = i
cv = KFold(n_splits=5, random_state=0, shuffle=True)
 pipe = Pipeline(steps=[('preprocessor', preprocessor), 
('model', model)])
 observations[classifiers[j]] =(cross_val_score(pipe, train[features], np.ravel(train[target]), scoring='accuracy', cv=cv))
j = j+1<create_dataframe>
train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object'
mean = pd.DataFrame(observations.mean() , index= classifiers)
 observations = pd.concat([observations,mean.T])
 observations.index=['Fold 1','Fold 2','Fold 3','Fold 4','Fold 5','Mean']
observations.T.sort_values(by=['Mean'], ascending = False )<choose_model_class>
not_categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes!='object']
linear_svm = svm.SVC(kernel='linear', C=0.1,gamma=10, probability=True)
 pipe_linear = Pipeline(steps=[('preprocessor', preprocessor),('model', linear_svm)])
 rand = RandomForestClassifier(n_estimators=200, random_state=0)
 pipe_rand = Pipeline(steps=[('preprocessor', preprocessor),('model', rand)])
 log = LogisticRegression()
pipe_log = Pipeline(steps=[('preprocessor', preprocessor),('model', log)])
 ensemble_all = VotingClassifier(estimators=[('Linear_svm', pipe_linear), 
('Random Forest Classifier', pipe_rand), 
('Log', pipe_log)],
voting='soft', weights=[2,3,2] )<compute_test_metric>
for i in not_categorical:
maximum=np.max(train_data[i])
 train_data[i]=train_data[i]/maximum
maximum_test=np.max(test_data[i])
 test_data[i]=test_data[i]/maximum_test
cross_validation_score = cross_val_score(ensemble_all, train[features], np.ravel(train[target]), scoring='accuracy', cv=cv)
 print("K-Fold scores:", cross_validation_score,
"
Mean:", round(cross_validation_score.mean() , 3),
"
Max:", round(cross_validation_score.max() , 3))<choose_model_class>
categorical=train_data.drop(['RefId','IsBadBuy'],axis=1 ).columns[train_data.drop(['RefId','IsBadBuy'],axis=1 ).dtypes=='object']
model = RandomForestClassifier(n_estimators=200, random_state = 0)
 pipe = Pipeline(steps=[('preprocessor', preprocessor), 
('model', model)] )<compute_train_metric>
train_data[categorical[0]]
cross_validation_score_rand = cross_val_score(pipe, train[features], np.ravel(train[target]), scoring='accuracy', cv=cv)
 print("K-Fold scores:", cross_validation_score_rand,
"
Mean:", round(cross_validation_score_rand.mean() , 3),
"
Max:", round(cross_validation_score_rand.max() , 3))<feature_engineering>
pd.get_dummies(train_data[categorical[0]] )
traindf = pd.read_csv('.. /input/titanic/train.csv' ).set_index('PassengerId')
 testdf = pd.read_csv('.. /input/titanic/test.csv' ).set_index('PassengerId')
 df = pd.concat([traindf, testdf], axis=0, sort=False)
 df['Title'] = df.Name.str.split(',' ).str[1].str.split('.' ).str[0].str.strip()
df['IsWomanOrBoy'] =(( df.Title == 'Master')|(df.Sex == 'female'))
df['LastName'] = df.Name.str.split(',' ).str[0]
family = df.groupby(df.LastName ).Survived
df['WomanOrBoyCount'] = family.transform(lambda s: s[df.IsWomanOrBoy].fillna(0 ).count())
 df['WomanOrBoyCount'] = df.mask(df.IsWomanOrBoy, df.WomanOrBoyCount - 1, axis=0)
 df['FamilySurvivedCount'] = family.transform(lambda s: s[df.IsWomanOrBoy].fillna(0 ).sum())
 df['FamilySurvivedCount'] = df.mask(df.IsWomanOrBoy, df.FamilySurvivedCount - df.Survived.fillna(0), axis=0)
 df['WomanOrBoySurvived'] = df.FamilySurvivedCount / df.WomanOrBoyCount.replace(0, np.nan)
 df['Alone'] =(df.WomanOrBoyCount == 0)
 test_x = pd.concat([df.WomanOrBoySurvived.fillna(0), df.Alone, df.Sex.replace({'male': 0, 'female': 1})], axis=1 ).loc[testdf.index]
test_x['Survived'] =(((test_x.WomanOrBoySurvived <= 0.238)&(test_x.Sex > 0.5)&(test_x.Alone > 0.5)) | \ 
(( test_x.WomanOrBoySurvived > 0.238)& \
~(( test_x.WomanOrBoySurvived > 0.55)&(test_x.WomanOrBoySurvived <= 0.633))))
pd.DataFrame({'Survived': test_x['Survived'].astype(int)}, \
index=testdf.index ).reset_index().to_csv('survived.csv', index=False )<set_options>
for i in categorical:
dummies= pd.get_dummies(train_data[i])
 dummies.columns=str(i)+'_'+dummies.columns
train_data=pd.concat([train_data,dummies],axis=1)
 train_data.drop(i,inplace=True,axis=1)
 dummies=pd.get_dummies(test_data[i])
 dummies.columns=str(i)+'_'+dummies.columns
test_data=pd.concat([test_data,dummies],axis=1)
 test_data.drop(i,inplace=True,axis=1 )
rnd_state = 42
skfold = StratifiedKFold(n_splits=5 )<load_from_csv>
for i in train_data.drop('IsBadBuy',axis=1 ).columns:
if i not in test_data.columns:
test_data[i]=np.zeros(len(test_data))
train_data = pd.read_csv(".. /input/train.csv")
 test_data = pd.read_csv(".. /input/test.csv")
 train_data.head()<split>
for i in test_data.columns:
if i not in train_data.columns:
train_data[i]=np.zeros(len(train_data))
train_data["Age_categories"] = np.ceil(train_data["Age"]/1.5)
 train_data["Age_categories"].where(train_data["Age_categories"] <2, 2.0, inplace=True)
 train_data["Age_categories"].where(train_data["Age_categories"] >50, 50.0, inplace=True)
 split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state= rnd_state)
 for train_index, test_index in split.split(train_data, train_data["Age_categories"]):
strat_train_set = train_data.loc[train_index]
strat_test_set = train_data.loc[test_index]
for set_ in(strat_train_set, strat_test_set):
set_.drop("Age_categories", axis=1, inplace=True)
 strat_train_set_p = strat_train_set.drop("Survived", axis=1)
 survival_labels = strat_train_set["Survived"].copy()
strat_test_set_p = strat_test_set.drop("Survived", axis=1)
 validation_labels = strat_test_set["Survived"].copy()<feature_engineering>
test_data=test_data[train_data.drop("IsBadBuy",axis=1 ).columns]
def extract_title(dataset):
dataset['Title'] = dataset.Name.apply(lambda name: name.split(',')[1].split('.')[0].strip())
 normalized_titles = {
"Capt": "other",
"Col": "other",
"Major": "other",
"Jonkheer": "other",
"Don": "Mr",
"Sir" : "Mr",
"Dr": "other",
"Rev": "other",
"the Countess":"other",
"Dona": "Mrs",
"Mme": "Mrs",
"Mlle": "Miss",
"Ms": "Mrs",
"Mr" : "Mr",
"Mrs" : "Mrs",
"Miss" : "Miss",
"Master" : "Master",
"Lady" : "Mrs",
"NaN" : "other"
}
dataset.Title = dataset.Title.map(normalized_titles)
 return dataset<drop_column>
X=train_data.drop(['RefId','IsBadBuy'],axis=1)
 y=train_data['IsBadBuy']
def data_cleaner(dataset):
dataset = extract_title(dataset)
 return dataset<train_model>
X_train,X_test,y_train,y_test=train_test_split(X,y,random_state=42 )
class CombinedAttributesAdder(BaseEstimator, TransformerMixin):
def __init__(self, add_familySize = False):
self.add_familySize = add_familySize
def fit(self, X, y=None):
return self
def transform(self, X, y=None):
familySize = X[:, Sibsp_ix] + X[:, Parch_ix]
if self.add_familySize:
return np.c_[X, familySize]
else:
return np.c_[X]
Sibsp_ix, Parch_ix = 2, 3
numeric_features = ['Age','Fare', 'SibSp', 'Parch']
numeric_transformer = Pipeline(steps=[ 
('imputer', SimpleImputer(strategy='median')) , 
('attribs_adder', CombinedAttributesAdder(add_familySize = False)) , 
('scaler', StandardScaler())
 ])
 categorical_features = ['Title', 'Sex', 'Pclass', 'Embarked']
categorical_transformer = Pipeline(steps=[ 
('imputer', SimpleImputer(strategy='constant', fill_value='S')) , 
('onehot', OneHotEncoder(handle_unknown='ignore', sparse=False)) ])
 preprocessor = ColumnTransformer(
 transformers=[ 
('num', numeric_transformer, numeric_features), 
('cat', categorical_transformer, categorical_features)
 ] )<categorify>
from sklearn.neighbors import KNeighborsClassifier
train_set_prepared = preprocessor.fit_transform(data_cleaner(strat_train_set_p))
validation_set_prepared = preprocessor.fit_transform(data_cleaner(strat_test_set_p))<train_model>
from sklearn.neighbors import KNeighborsClassifier
log_clf = LogisticRegression(random_state=rnd_state, solver='lbfgs')
 log_clf.fit(train_set_prepared, survival_labels )<predict_on_test>
from sklearn.neighbors import KNeighborsClassifier
log_pred = log_clf.predict(validation_set_prepared ).astype(int )<compute_train_metric>
KNN=KNeighborsClassifier(n_neighbors=11)
 KNN.fit(X_train,y_train )
log_cross_scores = cross_val_score(log_clf, train_set_prepared, survival_labels, cv=skfold, scoring="accuracy")
 log_scores =(log_cross_scores.mean() + accuracy_score(log_pred, validation_labels)) /2
log_scores<train_model>
KNN.score(X_test,y_test )
sgd_clf = SGDClassifier(max_iter=60, penalty = None, eta0=0.1, random_state=rnd_state, tol =1e-3)
 sgd_clf.fit(train_set_prepared, survival_labels )<compute_train_metric>
predict=KNN.predict(test_data.drop('RefId',axis=1))
sgd_cross_scores = cross_val_score(sgd_clf, train_set_prepared, survival_labels, cv=skfold, scoring="accuracy")
 sgd_pred = sgd_clf.predict(validation_set_prepared ).astype(int)
 sgd_scores =(sgd_cross_scores.mean() + accuracy_score(sgd_pred, validation_labels)) /2
sgd_scores<train_on_grid>
Submission=pd.DataFrame(data=predict,columns=['IsBadBuy'])
 Submission.head()
svm_clf = SVC(gamma='auto')
 svm_clf.fit(train_set_prepared, survival_labels )<compute_train_metric>
Submission['RefId']=test_data['RefId']
Submission.set_index('RefId',inplace=True )
<train_on_grid><EOS> 
Submission.head()
Submission.to_csv('Submission.csv' )