Kaggle competition: Santander Customer Transaction Prediction
<SOS> metric: AUC Kaggle data source: santander-customer-transaction-prediction<data_type_conversions>
!pip install target_encoding
combined_data["MasVnrType"] = combined_data["MasVnrType"].fillna("None")
 combined_data["MasVnrArea"] = combined_data["MasVnrArea"].fillna(0)
 combined_data["BsmtQual"] = combined_data["BsmtQual"].fillna("No Basement")
 combined_data["BsmtCond"] = combined_data["BsmtCond"].fillna("No Basement")
 combined_data["BsmtExposure"] = combined_data["BsmtExposure"].fillna("No Basement")
 combined_data["BsmtFinType1"] = combined_data["BsmtFinType1"].fillna("No Basement")
 combined_data["BsmtFinSF1"] = combined_data["BsmtFinSF1"].fillna(0)
 combined_data["BsmtFinType2"] = combined_data["BsmtFinType2"].fillna("No Basement")
 combined_data["BsmtUnfSF"] = combined_data["BsmtUnfSF"].fillna(0)
 combined_data["BsmtFullBath"] = combined_data["BsmtFullBath"].fillna(0)
 combined_data["FireplaceQu"] = combined_data["FireplaceQu"].fillna("No Fireplace")
 combined_data["GarageFinish"] = combined_data["GarageFinish"].fillna("No Garage")
 combined_data["GarageArea"] = combined_data["GarageArea"].fillna(0)
 combined_data["GarageQual"] = combined_data["GarageQual"].fillna("No Garage")
 combined_data["GarageCond"] = combined_data["GarageCond"].fillna("No Garage")
 combined_data["GarageYrBlt"] = combined_data["GarageYrBlt"].fillna(combined_data["YearBuilt"])
 combined_data["GarageCars"] = combined_data["GarageCars"].fillna(0)
 combined_data["TotalBsmtSF"] = combined_data["TotalBsmtSF"].fillna(0 )<drop_column>
X, y = load_breast_cancer(return_X_y=True)
 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
 enc = TargetEncoder()
new_X_train = enc.transform_train(X=X_train, y=y_train)
 new_X_test = enc.transform_test(X_test)
 rf = RandomForestClassifier(n_estimators=100, random_state=42)
 rf.fit(X_train, y_train)
 pred = rf.predict_proba(X_test)[:,1]
print('without target encoding', roc_auc_score(y_test, pred))
rf.fit(new_X_train, y_train)
 pred = rf.predict_proba(new_X_test)[:,1]
print('with target encoding', roc_auc_score(y_test, pred))
enc = TargetEncoderClassifier()
enc.fit(X_train, y_train)
 pred = enc.predict_proba(X_test)[:,1]
print('target encoding classifier', roc_auc_score(y_test, pred))
for col in low_correlation:
del combined_data[col]<drop_column>
train=pd.read_csv(".. /input/train.csv" ).drop("ID_code",axis=1)
 test=pd.read_csv(".. /input/test.csv" ).drop("ID_code",axis=1)
 X = train.drop('target', axis=1)
 y = train.target
sample_submission = pd.read_csv('.. /input/sample_submission.csv')
 cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42 )
for col in null_columns:
del combined_data[col]<sort_values>
enc = TargetEncoderClassifier(alpha=100, max_unique=25, used_features=170)
 score = cross_val_score(enc, X, y, scoring='roc_auc', cv=cv)
 print(score.mean() , score.std() )
high_correlation = correlation_matrix_train.abs().unstack().sort_values(kind="quicksort", ascending=False)
 high_correlation[correlation_matrix_train.shape[0]:].where(lambda x : x >= 0.75 ).dropna() 
<categorify>
enc = TargetEncoderClassifier(alpha=100, max_unique=25, used_features=170)
 enc.fit(X, y)
 pred = enc.predict_proba(test)[:,1]
combined_data = pd.get_dummies(combined_data, columns=catagorical_variables, prefix=catagorical_variables, drop_first=True )<split>
sample_submission['target'] = pred
sample_submission.to_csv('submission.csv', index=False )