Kaggle competition: Categorical Feature Encoding Challenge
store.isna().sum()<filter>
%%time
train_df = pd.read_csv('/kaggle/input/cat-in-the-dat/train.csv', index_col='id')
 sample_submission_df = pd.read_csv('/kaggle/input/cat-in-the-dat/sample_submission.csv')
 test_df = pd.read_csv('/kaggle/input/cat-in-the-dat/test.csv', index_col='id' )
store1=train[train['Store']==1]<filter>
train_df = shuffle(train_df, random_state=random_state)
 train_Y = train_df['target'].copy()
train_X = train_df.drop('target', axis=1 ).copy()
store1[store1['Sales']==0]<data_type_conversions>
def get_pipline(estimator):
return Pipeline(steps=[ 
('preproc', ColumnTransformer([ 
('bin_0_2', 'passthrough', ['bin_0', 'bin_1', 'bin_2']), 
('bin_3_4', FunctionTransformer(func=lambda X: X.replace({'F': 0, 'T': 1, 'N': 0, 'Y': 1}), validate=False), [
'bin_3', 'bin_4'] 
), 
('nom_0_4', OneHotEncoder(sparse=True, handle_unknown='ignore'), [
'nom_0', 'nom_1', 'nom_2', 'nom_3', 'nom_4', 'nom_5', 'nom_6', 'nom_7', 'nom_8', 'nom_9'] 
), 
('ord', Pipeline(steps=[ 
('replace', ColumnTransformer([ 
('encoder', OrdinalEncoder(categories=[
['Novice', 'Contributor', 'Expert', 'Master', 'Grandmaster'],
['Freezing', 'Cold', 'Warm', 'Hot', 'Boiling Hot', 'Lava Hot'],
np.sort(train_df['ord_3'].unique()),
np.sort(train_df['ord_4'].unique()),
np.sort(train_df['ord_5'].unique()),
]), ['ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']),
], remainder='passthrough')) , 
('mm_scaler', MinMaxScaler())
 ]), ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5', 'day', 'month'])
 ])) , 
('est', estimator)
 ])
 xgb_pipline = get_pipline(XGBClassifier(objective='binary:logistic', n_estimators=1100, max_depth=6, gamma=5))
logit_pipline = get_pipline(LogisticRegression(solver='lbfgs', max_iter=225, C=0.12, random_state=random_state))
pipline = VotingClassifier([('xgb', xgb_pipline),('logit', logit_pipline)], voting='soft', n_jobs=-1 )
test_store1=test[test['Store']==1]
test_store1['Date']=pd.to_datetime(test_store1['Date'],format='%Y-%m-%d' )<count_values>
params = {'est__solver': ['lbfgs'], 'est__C': [0.11, 0.12, 0.13], 'est__max_iter': [225, 250, 275]}
gs_cv = GridSearchCV(logit_pipline, params, scoring='roc_auc', cv=cv, n_jobs=-1, return_train_score=True, verbose=1)
test_store1['Open'].value_counts()<filter>
cv_scores = cross_validate(
 pipline, train_X, train_Y, scoring='roc_auc', cv=cv, n_jobs=-1,
return_train_score=True, return_estimator=True, verbose=1
)
store[store['Store']==1].T<filter>
%%time
scores = np.array([est.predict_proba(test_df)for est in cv_scores['estimator']])
 mean_scores = scores.mean(axis=0)[:, 0]
submit_df = pd.DataFrame({ 'id': test_df.index, 'target': mean_scores })
 submit_df.to_csv('submission.csv', index=False )