Kaggle competition: Categorical Feature Encoding Challenge
<SOS> metric: AUC Kaggle data source: categorical-feature-encoding-challenge<categorify>
!pip install the1owl
df['Assortment']=df['Assortment'].map({'a':0,'b':1,'c':2} )<data_type_conversions>
warnings.filterwarnings('ignore')
 PATH = '/kaggle/input/cat-in-the-dat/'
df['Assortment']=df['Assortment'].astype(int )<count_values>
train = pd.read_csv(f'{PATH}train.csv')
 test = pd.read_csv(f'{PATH}test.csv' )
df['PromoInterval'].value_counts()<categorify>
%%time
target = train['target']
train_id = train['id']
test_id = test['id']
train.drop(['target', 'id', 'bin_0'], axis=1, inplace=True)
 test.drop(['id','bin_0'], axis=1, inplace=True)
 print(train.shape)
 print(test.shape )
df['PromoInterval']=df['PromoInterval'].map({'Jan,Apr,Jul,Oct':0,'Feb,May,Aug,Nov':1,'Mar,Jun,Sept,Dec':2} )<data_type_conversions>
%%time
traintest = pd.concat([train, test])
 dummies = pd.get_dummies(traintest, columns=traintest.columns, drop_first=True, sparse=True)
 train_ohe = dummies.iloc[:train.shape[0], :]
test_ohe = dummies.iloc[train.shape[0]:, :]
print(train_ohe.shape)
 print(test_ohe.shape )
df['PromoInterval']=df['PromoInterval'].astype(int )<drop_column>
%%time
train_ohe = train_ohe.sparse.to_coo().tocsr()
test_ohe = test_ohe.sparse.to_coo().tocsr()
df=df.drop('Date',1 )<prepare_x_and_y>
print('
print('StratifiedKFold training...')
 folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=10)
 model = LogisticRegression(solver='lbfgs', max_iter=200, C=0.095)
 score = []
for fold_,(trn_idx, val_idx)in enumerate(folds.split(train_ohe, target, groups=target)) :
print('Fold:',fold_+1)
 tr_x, tr_y = train_ohe[trn_idx,:], target[trn_idx]
vl_x, v_y = train_ohe[val_idx,:], target[val_idx]
%time model.fit(tr_x, tr_y)
 y_pred = model.predict(vl_x)
 score.append(roc_auc_score(v_y, y_pred))
print(f'AUC score : {roc_auc_score(v_y, y_pred)}')
 print('Average AUC score', np.mean(score))
print('
y=np.log1p(df['Sales'] )<drop_column>
%time model.fit(train_ohe, target )
X=df.drop(['Sales','Customers'],1 )<split>
pred_test = model.predict_proba(test_ohe)[:,0]
X_train,X_val,y_train,y_val=train_test_split(X,y,random_state=1,test_size=0.2 )<train_model>
sub = pd.read_csv(f'{PATH}sample_submission.csv')
 sub['target'] = pred_test
sub.to_csv('log_reg_0.1.csv', index=None, header=True )
dt=DecisionTreeRegressor(max_depth=11,random_state=1 ).fit(X_train,y_train )<predict_on_test>
sub = simple.Blend(['.. /input/why-not-logistic-regression/submission.csv', 'log_reg_0.1.csv'], 'id', 'target', 'blend01.csv' )
y_pred_val=dt.predict(X_val )<compute_test_metric>
sub = simple.Blend(['.. /input/entity-embeddings-to-handle-categories/submission.csv', 'blend01.csv'], 'id', 'target', 'blend02.csv' )
<compute_test_metric><EOS> 
sub = simple.Blend(['.. /input/r-glmnet/submission_glmnet.csv', 'blend02.csv'], 'id', 'target', 'blend03.csv' )