Kaggle competition: Categorical Feature Encoding Challenge II
<SOS> metric: AUC Kaggle data source: categorical-feature-encoding-challenge-ii<compute_test_metric>
!pip install --no-warn-conflicts -U -q scikit-learn==0.22.1 autoimpute impyute fancyimpute
def rmsle(y_pred, y_actual):
return np.sqrt(np.square(np.log(y_pred + 1)- np.log(y_actual + 1)).mean() )<train_model>
sns.set_style('whitegrid')
 warnings.filterwarnings('ignore')
 warnings.simplefilter('ignore')
 pd.set_option('display.max_columns', 1000)
 pd.set_option('display.max_rows', 500)
 SEED = 2020
SPLITS = 25
start_time = time.time()
print('Building and training the modeland start time is:' , 
(time.strftime("%Hhrs:%Mm:%Ss", time.gmtime(( start_time)))))
 modelR = getModel(X_train_dict)
 print('Training the model...')
 modelR.fit(X_train_dict, y_train, n_epoch=5,
batch_size=256, snapshot_step= 1000,
show_metric=True,run_id='tflMP')
 end_time = time.time()
print('Completed building and training the model and time taken::', 
(time.strftime("%Hhrs:%Mm:%Ss",(time.gmtime(( end_time - start_time))))))<compute_train_metric>
def set_seed(seed=SEED):
random.seed(seed)
 np.random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 set_seed()
start_time = time.time()
print('Evaluating the model the modeland start time is:' , 
(time.strftime("%Hhrs:%Mm:%Ss", time.gmtime(( start_time)))))
 score = modelR.evaluate(X_val_dict, y_val, batch_size=256)
 print(' The validation data set accuracy is:', score)
 val_rmsle = 0
y_val_pred = modelR.predict(X_val_dict)
 val_rmsle = rmsle(y_val_pred, y_val)
 print(' The validation data set rmsle is(%f)'%(val_rmsle))
end_time = time.time()
print('Completed evaluation of the model and time taken::', 
(time.strftime("%Hhrs:%Mm:%Ss",(time.gmtime(( end_time - start_time))))))<save_to_csv>
base = pd.read_csv('/kaggle/input/cat-in-the-dat-ii/train.csv')
 baseTe = pd.read_csv('/kaggle/input/cat-in-the-dat-ii/test.csv')
 baseTe['target'] = -1
score = dict()
start_time = time.time()
print('Predicting and submitting results and start time is:' , 
(time.strftime("%Hhrs:%Mm:%Ss", time.gmtime(( start_time)))))
 y_pred = np.zeros(X_test_dict['name'].shape[0])
 y_pred = modelR.predict(X_test_dict)
 y_pred = np.expm1(y_pred)
 print(' preparing for submission...')
 pricePred = pd.DataFrame()
pricePred['test_id'] = test_id
pricePred['price'] = np.round(y_pred,2)
 pricePred.to_csv('Sample_sub.csv',index=False)
 print(' submitted...')
 end_time = time.time()
print('******Price recommended in ******:' , 
(time.strftime("%Hhrs:%Mm:%Ss", time.gmtime(( end_time - modeling_start_time)))) )<import_modules>
pd.DataFrame(base.isna().sum(axis=0)/len(base), columns=['missing percent'] ).sort_values('missing percent', ascending=False ).T
import pandas as pd
import operator
import matplotlib.pyplot as plt
import numpy as np
import nltk
import time 
<load_from_csv>
def null_analysis(df):

 null_cnt = df.isnull().sum()
null_cnt = null_cnt[null_cnt!=0]
null_percent = null_cnt / len(df)* 100
null_table = pd.concat([pd.DataFrame(null_cnt), pd.DataFrame(null_percent)], axis=1)
 null_table.columns = ['counts', 'percentage']
null_table.sort_values('counts', ascending=False, inplace=True)
 return null_table
df = pd.read_csv('.. /input/train.tsv', sep='\t')
 df_sub = pd.read_csv('.. /input/test.tsv', sep='\t')
 submission = pd.DataFrame()
submission['test_id'] = df_sub.test_id.copy()
y_target = list(df.price )<count_missing_values>
score = dict()
def null_percentage(column):
df_name = column.name
nans = np.count_nonzero(column.isnull().values)
 total = column.size
frac = nans / total
perc = int(frac * 100)
 print('%d%% or %d missing from %s column.' % 
(perc, nans, df_name))
def check_null(df, columns):
for col in columns:
null_percentage(df[col])
 check_null(df, df.columns)
<feature_engineering>
def SiavashMapping(df):
bin_3_mapping = {'T':1 , 'F':0}
bin_4_mapping = {'Y':1 , 'N':0}
nom_0_mapping = {'Red' : 0, 'Blue' : 1, 'Green' : 2}
nom_1_mapping = {'Trapezoid' : 0, 'Star' : 1, 'Circle': 2, 'Triangle' : 3, 'Polygon' : 4, 'Square': 5}
nom_2_mapping = {'Hamster' : 0 , 'Axolotl' : 1, 'Lion' : 2, 'Dog' : 3, 'Cat' : 4, 'Snake' : 5}
nom_3_mapping = {'Russia' : 0, 'Canada' : 1, 'Finland' : 2, 'Costa Rica' : 3, 'China' : 4, 'India' : 5}
nom_4_mapping = {'Bassoon' : 0, 'Theremin' : 1, 'Oboe' : 2, 'Piano' : 3}
nom_5_mapping = dict(zip(( df.nom_5.dropna().unique()), range(len(( df.nom_5.dropna().unique())))))
 nom_6_mapping = dict(zip(( df.nom_6.dropna().unique()), range(len(( df.nom_6.dropna().unique())))))
 nom_7_mapping = dict(zip(( df.nom_7.dropna().unique()), range(len(( df.nom_7.dropna().unique())))))
 nom_8_mapping = dict(zip(( df.nom_8.dropna().unique()), range(len(( df.nom_8.dropna().unique())))))
 nom_9_mapping = dict(zip(( df.nom_9.dropna().unique()), range(len(( df.nom_9.dropna().unique())))))
 ord_1_mapping = {'Novice' : 0, 'Contributor' : 1, 'Expert' : 2, 'Master': 3, 'Grandmaster': 4}
ord_2_mapping = { 'Freezing': 0, 'Cold': 1, 'Warm' : 2, 'Hot': 3, 'Boiling Hot' : 4, 'Lava Hot' : 5}
ord_3_mapping = {'a':0, 'b':1, 'c':2 ,'d':3 ,'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9, 'k':10, 'l':11, 'm':12, 'n':13, 'o':14}
ord_4_mapping = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 'I':8, 'J':9, 'K':10,'L':11,'M':12,
'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25}
sorted_ord_5 = sorted(df.ord_5.dropna().unique())
 ord_5_mapping = dict(zip(sorted_ord_5, range(len(sorted_ord_5))))
df['bin_3'] = df.loc[df.bin_3.notnull() , 'bin_3'].map(bin_3_mapping)
 df['bin_4'] = df.loc[df.bin_4.notnull() , 'bin_4'].map(bin_4_mapping)
 df['nom_0'] = df.loc[df.nom_0.notnull() , 'nom_0'].map(nom_0_mapping)
 df['nom_1'] = df.loc[df.nom_1.notnull() , 'nom_1'].map(nom_1_mapping)
 df['nom_2'] = df.loc[df.nom_2.notnull() , 'nom_2'].map(nom_2_mapping)
 df['nom_3'] = df.loc[df.nom_3.notnull() , 'nom_3'].map(nom_3_mapping)
 df['nom_4'] = df.loc[df.nom_4.notnull() , 'nom_4'].map(nom_4_mapping)
 df['nom_5'] = df.loc[df.nom_5.notnull() , 'nom_5'].map(nom_5_mapping)
 df['nom_6'] = df.loc[df.nom_6.notnull() , 'nom_6'].map(nom_6_mapping)
 df['nom_7'] = df.loc[df.nom_7.notnull() , 'nom_7'].map(nom_7_mapping)
 df['nom_8'] = df.loc[df.nom_8.notnull() , 'nom_8'].map(nom_8_mapping)
 df['nom_9'] = df.loc[df.nom_9.notnull() , 'nom_9'].map(nom_9_mapping)
 df['ord_1'] = df.loc[df.ord_1.notnull() , 'ord_1'].map(ord_1_mapping)
 df['ord_2'] = df.loc[df.ord_2.notnull() , 'ord_2'].map(ord_2_mapping)
 df['ord_3'] = df.loc[df.ord_3.notnull() , 'ord_3'].map(ord_3_mapping)
 df['ord_4'] = df.loc[df.ord_4.notnull() , 'ord_4'].map(ord_4_mapping)
 df['ord_5'] = df.loc[df.ord_5.notnull() , 'ord_5'].map(ord_5_mapping)
 return df
def merc_imputer(df_temp):
df_temp.brand_name = df_temp.brand_name.replace(np.nan, 'no_brand')
 df_temp.category_name = df_temp.category_name.replace(np.nan, 'uncategorized/uncategorized')
 df_temp.item_description = df_temp.item_description.replace(np.nan, 'No description yet')
 df_temp.item_description = df_temp.item_description.replace('No description yet', 'no_description')
 return df_temp
df = merc_imputer(df)
 df_sub = merc_imputer(df_sub )<train_model>
def AntMapping(df, ordinal):
ord_maps = {
'ord_0': {val: i for i, val in enumerate([1, 2, 3])},
'ord_1': {
val: i
for i, val in enumerate(
 ['Novice', 'Contributor', 'Expert', 'Master', 'Grandmaster'] 
)
 },
'ord_2': {
val: i
for i, val in enumerate(
 ['Freezing', 'Cold', 'Warm', 'Hot', 'Boiling Hot', 'Lava Hot'] 
)
 },
**{col: {val: i for i, val in enumerate(sorted(df[col].dropna().unique())) } for col in ['ord_3', 'ord_4', 'ord_5', 'day', 'month']},
}
ord_cols = pd.concat([df[col].map(ord_map ).fillna(max(ord_map.values())//2 ).astype('float32')for col, ord_map in ord_maps.items() ], axis=1)
 ord_cols /= ord_cols.max()
ord_sqr = 4*(ord_cols - 0.5)**2
ord_cols_sqr = [feat+'_sqr' for feat in ordinal]
df[ordinal] = ord_cols
df[ord_cols_sqr] = ord_sqr
return df
print('Training Data')
 check_null(df, df.columns)
 print('Submission Data')
 check_null(df_sub, df_sub.columns )<count_values>
def CountEncoding(df, cols, df_test=None):
for col in cols:
frequencies = df[col].value_counts().reset_index()
df_values = df[[col]].merge(frequencies, how='left', left_on=col, right_on='index' ).iloc[:,-1].values
df[col+'_counts'] = df_values
if df_test is not None:
df_test_values = df_test[[col]].merge(frequencies, how='left', left_on=col, right_on='index' ).fillna(1 ).iloc[:,-1].values
df_test[col+'_counts'] = df_test_values
count_cols = [col+'_counts' for col in cols]
if df_test is not None:
return df, df_test, count_cols
else:
return df, count_cols
df.shipping.value_counts()<count_values>
def YurgensenMapping(df):
def TLC(s):
s = str(s)
 return(((ord(s[0])) -64)*52+(( ord(s[1])) -64)-6)
 df['ord_0_ord_2'] = df['ord_0'].astype('str')+df['ord_2'].astype('str')
 df['ord_0'] = df['ord_0'].fillna(2.01)
 df.loc[df.ord_2=='Freezing', 'ord_2'] = 0
df.loc[df.ord_2=='Cold', 'ord_2'] = 1
df.loc[df.ord_2=='Warm', 'ord_2'] = 2
df.loc[df.ord_2=='Hot', 'ord_2'] = 3
df.loc[df.ord_2=='Boiling Hot', 'ord_2'] = 4
df.loc[df.ord_2=='Lava Hot', 'ord_2'] = 5
df['ord_2'] = df['ord_2'].fillna(2.37)
 df.loc[df.ord_1=='Novice', 'ord_1'] = 0
df.loc[df.ord_1=='Contributor', 'ord_1'] = 1
df.loc[df.ord_1=='Expert', 'ord_1'] = 2
df.loc[df.ord_1=='Master', 'ord_1'] = 3
df.loc[df.ord_1=='Grandmaster', 'ord_1'] = 4
df['ord_1'] = df['ord_1'].fillna(1.86)
 df['ord_5'] = df.loc[df.ord_5.notnull() , 'ord_5'].apply(lambda x: TLC(x))
df['ord_5'] = df['ord_5'].fillna('Zx' ).apply(lambda x: TLC(x))
df['ord_5'] = df['ord_5'].rank()
df['ord_3'] = df.loc[df.ord_3.notnull() , 'ord_3'].apply(lambda x: ord(str(x)) -96)
 df['ord_3'] = df['ord_3'].fillna(8.44)
 df['ord_4'] = df.loc[df.ord_4.notnull() , 'ord_4'].apply(lambda x: ord(str(x)) -64)
 df['ord_4'] = df['ord_4'].fillna(14.31)
 return df
print('$1 items: ' + str(df.price[df.price == 1].count()))
print('$2 items: ' + str(df.price[df.price == 2].count()))
print('$3 items: ' + str(df.price[df.price == 3].count()))<filter>
def RidgeClf(train, test, ordinal, ohe, scaler, seed, splits, drop_idx=None, dimreducer=None):
y_train = train['target'].values.copy()
train_length = train.shape[0]
test['target'] = -1
data = pd.concat([train, test], axis=0 ).reset_index(drop=True)
 X_ohe = pd.get_dummies(data[ohe],columns=ohe,drop_first=True,dummy_na=True,sparse=True, dtype='int8' ).sparse.to_coo()
if dimreducer is not None:
X_ohe = sp.sparse.csr_matrix(dimreducer.fit_transform(X_ohe))
gc.collect()
if ordinal is not None:
if scaler is not None:
X_ord = scaler.fit_transform(data[ordinal])
 else:
X_ord = data[ordianl].values
data_ = sp.sparse.hstack([X_ohe, X_ord] ).tocsr()
else:
data_ = sp.sparse.hstack([X_ohe] ).tocsr()
train = data_[:train_length]
test = data_[train_length:]
model = RidgeClassifier(alpha=152.5)
 skf = StratifiedKFold(n_splits=splits, shuffle=True, random_state=seed)
 oof = np.zeros(( train.shape[0],))
y_pred = np.zeros(( test.shape[0],))
for tr_ind, val_ind in skf.split(train, y_train):
if drop_idx is not None:
idx = list(set(tr_ind)-set(drop_idx))
X_tr, X_val = train[idx], train[val_ind]
y_tr, y_val = y_train[idx], y_train[val_ind]
else:
X_tr, X_val = train[tr_ind], train[val_ind]
y_tr, y_val = y_train[tr_ind], y_train[val_ind]
train_set = {'X':X_tr, 'y':y_tr}
val_set = {'X':X_val, 'y':y_val}
model.fit(train_set['X'], train_set['y'])
 oof[val_ind] = model.decision_function(val_set['X'])
 y_pred += model.decision_function(test)/ splits
oof_auc_score = roc_auc_score(y_train, oof)
 oof = rankdata(oof)/len(oof)
 y_pred = rankdata(y_pred)/len(y_pred)
 return oof, y_pred, oof_auc_score
print('Free items: %d, representing %.5f%% of all items.' % 
(df.price[df.price == 0].count() , 
(df.price[df.price == 0].count() / df.shape[0])) )<count_values>
def LogRegClf(train, test, ordinal, ohe, scaler, seed, splits, drop_idx=None, dimreducer=None):
params = {
'fit_intercept' : True,
'random_state': SEED,
'penalty' : 'l2',
'verbose' : 0,
'solver' : 'lbfgs',
'max_iter' : 1000,
'n_jobs' : 4,
'C' : 0.05,
}
y_train = train['target'].values.copy()
train_length = train.shape[0]
test['target'] = -1
data = pd.concat([train, test], axis=0 ).reset_index(drop=True)
 X_ohe = pd.get_dummies(data[ohe],columns=ohe,drop_first=True,dummy_na=True,sparse=True, dtype='int8' ).sparse.to_coo()
if dimreducer is not None:
X_ohe = sp.sparse.csr_matrix(dimreducer.fit_transform(X_ohe))
gc.collect()
if ordinal is not None:
if scaler is not None:
X_ord = scaler.fit_transform(data[ordinal])
 else:
X_ord = data[ordinal].values
data_ = sp.sparse.hstack([X_ohe, X_ord] ).tocsr()
else:
data_ = sp.sparse.hstack([X_ohe] ).tocsr()
train = data_[:train_length]
test = data_[train_length:]
model = LogisticRegression(**params)
 skf = StratifiedKFold(n_splits=splits, shuffle=True, random_state=seed)
 oof = np.zeros(( train.shape[0],))
y_pred = np.zeros(( test.shape[0],))
for tr_ind, val_ind in skf.split(train, y_train):
if drop_idx is not None:
idx = list(set(tr_ind)-set(drop_idx))
X_tr, X_val = train[idx], train[val_ind]
y_tr, y_val = y_train[idx], y_train[val_ind]
else:
X_tr, X_val = train[tr_ind], train[val_ind]
y_tr, y_val = y_train[tr_ind], y_train[val_ind]
train_set = {'X':X_tr, 'y':y_tr}
val_set = {'X':X_val, 'y':y_val}
model.fit(train_set['X'], train_set['y'])
 oof[val_ind] = model.predict_proba(val_set['X'])[:, 1]
y_pred += model.predict_proba(test)[:, 1] / splits
oof_auc_score = roc_auc_score(y_train, oof)
 oof = rankdata(oof)/len(oof)
 y_pred = rankdata(y_pred)/len(y_pred)
 return oof, y_pred, oof_auc_score
print('Free items where seller pays shipping: %d.' %
df.price[operator.and_(df.price == 0, df.shipping == 1)].count() )<count_values>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SimpleImputer(strategy='constant')
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof1, pred1, score['Constant'] = RidgeClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Constant Imputation : {score["Constant"]}' )
print('No description:', str(df.item_description[df.item_description == 'no_description'].count()))
print('Uncategorized:',str(df.category_name[df.category_name == 'uncategorized/uncategorized'].count()))<define_variables>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SimpleImputer(strategy='constant')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof2, pred2, score['Constant-OrdinalOnly'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Constant Imputation of ordinal columns: {score["Constant-OrdinalOnly"]}' )
print('The top 75%% of categories represent %.1f%% of the dataset, and the top 50%% represent %.1f%%.' % 
(( sum([count for count in cat_counts if count > 10])/ len(df)) *100, 
(sum([count for count in cat_counts if count > 76])/ len(df)) *100))<count_values>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SimpleImputer(strategy='constant')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof3, pred3, score['Constant-Ord4Only'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Constant Imputation of ord_4 column: {score["Constant-Ord4Only"]}' )
brand_counts = np.sort(df.brand_name.value_counts())
 print(str(len(brand_counts)) + ' brands total.')
 print(str(df.shape[0])+ ' records total.')
 print('Category frequency percentiles, marked by lines:
25%%: %d, 50%%: %d, 75%%: %d, 95%%: %d, 97.5%%: %d.' % 
(brand_counts[int(len(brand_counts)*0.25)],
brand_counts[int(len(brand_counts)*0.5)],
brand_counts[int(len(brand_counts)*0.75)],
brand_counts[int(len(brand_counts)*0.9)],
brand_counts[int(len(brand_counts)*0.95)]))
title = 'Brand Quantity ECDF Without Top 25 Outliers'
plt.figure(title, figsize=(30,10))
plt.title(title, fontsize=32)
 x = np.sort(df.brand_name.value_counts())
 x = x[0:-25]
y = np.arange(1, len(x)+ 1)/ len(x)
 plt.plot(x, y, marker='.', linestyle='none')
 plt.xticks(fontsize=24)
 plt.yticks(fontsize=26)
 plt.axvline(x=x[int(len(x)*0.25)], linewidth=1, color='b')
 plt.axvline(x=x[int(len(x)*0.5)], linewidth=1, color='b')
 plt.axvline(x=x[int(len(x)*0.75)], linewidth=1, color='b')
 plt.axvline(x=x[int(len(x)*0.95)], linewidth=1, color='b')
 plt.axvline(x=x[int(len(x)*0.975)], linewidth=1, color='b')
 plt.show()<define_variables>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = features
ordinal = None
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof4, pred4, score['CompleteOHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for No imputation just OHE: {score["CompleteOHE"]}' )
print('The top 75%% of categories represent %.1f%% of the dataset, and the top 50%% represent %.1f%%.' % 
(( sum([count for count in brand_counts if count > 1])/ len(df)) *100, 
(sum([count for count in brand_counts if count > 4])/ len(df)) *100))<filter>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = features
ordinal = None
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SimpleImputer(strategy='constant')
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof5, pred5, score['Constant-CompleteOHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Constant Imputation with complete OHE: {score["Constant-CompleteOHE"]}' )
print('%d items, or %.2f%%, are missing a brand name.' % 
(len(df[df.brand_name == 'no_brand']),
len(df[df.brand_name == 'no_brand'])/ len(df)) )<import_modules>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = features
ordinal = None
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='mode')
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof6, pred6, score['Mode-CompleteOHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Mode Imputation with complete OHE: {score["Mode-CompleteOHE"]}' )
nltk.data.path.append(r'D:\Python\Data Sets
ltk_data')
<feature_engineering>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='mean')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof7, pred7, score['Mean-OHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Mean Imputation with OHE on non-ordinal columns: {score["Mean-OHE"]}' )
cat_vec = CountVectorizer(stop_words=[stopwords, string.punctuation], max_features=int(len(cat_counts)*0.5))
cat_matrix = cat_vec.fit_transform(df.category_name)
 cat_matrix_sub = cat_vec.transform(df_sub.category_name )<define_variables>
train = base.copy()
test = baseTe.copy()
train = YurgensenMapping(train)
 test = YurgensenMapping(test)
 features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof8, pred8, score['Yurgensen'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Yurgensen ordinal-Mapping : {score["Yurgensen"]}' )
cat_tokens = list(zip(cat_vec.get_feature_names() , np.array(cat_matrix.sum(axis=0)).ravel()))<categorify>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe] + ['day', 'month']
train = AntMapping(train, ordinal)
 test = AntMapping(test , ordinal)
 scaler = None
oof9, pred9, score['Ant'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Max Imputation of ordinals with OHE on non-ordinal columns: {score["Ant"]}' )
brand_vec = CountVectorizer(stop_words=[stopwords, string.punctuation], max_features=int(len(brand_counts)*0.5))
brand_matrix = brand_vec.fit_transform(df.brand_name)
 brand_matrix_sub = brand_vec.transform(df_sub.brand_name )<define_variables>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe] + ['day', 'month']
train = AntMapping(train, ordinal)
 test = AntMapping(test , ordinal)
 train, test, count_cols = CountEncoding(train, ordinal, test)
 ordinal += count_cols
scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof10, pred10, score['Ant-CE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Max Imputation of ordinals with OHE on non-ordinal columns with CountEncoding of Ordinals: {score["Ant-CE"]}' )
brand_tokens = list(zip(brand_vec.get_feature_names() , np.array(brand_matrix.sum(axis=0)).ravel()))<feature_engineering>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SimpleImputer(strategy='median')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof11, pred11, score['median-OrdPartial'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for median Imputation of ord_0, ord_1 and ord_2 columns: {score["median-OrdPartial"]}' )
name_vec = TfidfVectorizer(min_df=15, stop_words=[stopwords, string.punctuation])
 name_matrix = name_vec.fit_transform(df.name)
 name_matrix_sub = name_vec.transform(df_sub.name )<define_variables>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='norm')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof12, pred12, score['Norm'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Norm Imputation of ordinals: {score["Norm"]}' )
print('Kept %d words.' % len(name_vec.get_feature_names()))<categorify>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='locf')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof13, pred13, score['LOCF'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for LOCF Imputation of ordinals: {score["LOCF"]}' )
desc_vec = TfidfVectorizer(max_features=100000,
stop_words=[stopwords, string.punctuation])
 desc_matrix = desc_vec.fit_transform(df.item_description)
 desc_matrix_sub= desc_vec.transform(df_sub.item_description )<categorify>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='default univariate')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof14, pred14, score['DefUnivariate'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Default Univariate Imputation: {score["DefUnivariate"]}' )
cond_matrix = sparse.csr_matrix(pd.get_dummies(df.item_condition_id, sparse=True, drop_first=True))
cond_matrix_sub = sparse.csr_matrix(pd.get_dummies(df_sub.item_condition_id, sparse=True, drop_first=True))<concatenate>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = features
ordinal = None
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='interpolate')
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof15, pred15, score['Interpolate-OHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'Average AUC score for Interpolate Imputation with OHE om all columns: {score["Interpolate-OHE"]}' )
ship_matrix = sparse.csr_matrix(df.shipping ).transpose()
ship_matrix_sub = sparse.csr_matrix(df_sub.shipping ).transpose()<concatenate>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = features
ordinal = None
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SoftImpute(max_iters=100, verbose=False)
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.fit_transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof16, pred16, score['SoftImpute-OHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for SoftImpute Imputation : {score["SoftImpute-OHE"]}' )
sparse_matrix = sparse.hstack([cat_matrix, brand_matrix, name_matrix, desc_matrix,
cond_matrix, ship_matrix])
 sparse_matrix_sub = sparse.hstack([cat_matrix_sub, brand_matrix_sub, name_matrix_sub,
desc_matrix_sub, cond_matrix_sub, ship_matrix_sub] )<train_model>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='least squares')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof17, pred17, score['LQ-PartialOHE'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for LQ Imputation with Partial OHE : {score["LQ-PartialOHE"]}' )
if sparse_matrix.shape[1] == sparse_matrix_sub.shape[1]:
print('Features check out.')
 else:
print("The number of features in training and test set don't match." )<drop_column>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = SingleImputer(strategy='stochastic')
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof18, pred18, score['stochastic'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for stochastic Imputation : {score["stochastic"]}' )
del(cat_matrix, brand_matrix, name_matrix, desc_matrix, cond_matrix, ship_matrix)
 del(cat_matrix_sub, brand_matrix_sub, name_matrix_sub, desc_matrix_sub, cond_matrix_sub, ship_matrix_sub)
 del(df, df_sub)
 gc.collect()<compute_test_metric>
train = base.copy()
test = baseTe.copy()
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = IterativeImputer(max_iter=500, initial_strategy='most_frequent', random_state=SEED)
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof19, pred19, score['Iterative'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Iterative Imputation : {score["Iterative"]}' )
def rmsle(pred, true):
assert len(pred)== len(true)
 return np.sqrt(np.mean(np.power(np.log1p(pred)-np.log1p(true), 2)) )<define_variables>
train = base.copy()
test = baseTe.copy()
drop_idx = base[(base.isna().sum(axis=1)>3)].index.values
drop_idx = [i for i in drop_idx]
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = IterativeImputer(max_iter=500, initial_strategy='most_frequent', random_state=SEED)
 train[features] = imp.fit_transform(train[features])
 test[features] = imp.transform(test[features])
 train[features] = train[features].astype(np.int16)
 test[features] = test[features].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof20, pred20, score['IterativeWithDrop'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=drop_idx)
 print(f'AUC score for Iterative Imputation With threshold Drop : {score["IterativeWithDrop"]}' )
y_target = np.log10(np.array(y_target)+ 1 )<split>
train = base.copy()
test = baseTe.copy()
drop_idx = base[(base.isna().sum(axis=1)>3)].index.values
drop_idx = [i for i in drop_idx]
features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = IterativeImputer(max_iter=500, initial_strategy='most_frequent', random_state=SEED, add_indicator=True)
 indicator_cols = [feat+'_ind' for feat in ordinal]
for col in indicator_cols:
train[col] = 0
test[col] = 0
train[col] = train[col].astype(np.uint8)
 test[col] = test[col].astype(np.uint8)
 train[ordinal+indicator_cols] = imp.fit_transform(train[ordinal])
 test[ordinal+indicator_cols] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
ohe += indicator_cols
oof21, pred21, score['IterativeWithIndicator'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=drop_idx)
 print(f'AUC score for Iterative Imputation With Indicator : {score["IterativeWithIndicator"]}' )
X_train, X_test, y_train, y_test = train_test_split(sparse_matrix, y_target, test_size = 0.1 )<train_model>
train = base.copy()
test = baseTe.copy()
train['nulls'] = train.isna().sum(axis=1)
 test['nulls'] = test.isna().sum(axis=1)
 features = [feat for feat in train.columns if feat not in ['target','id']]
ohe = [feat for feat in features if feat not in ['ord_0', 'ord_1', 'ord_2', 'ord_3', 'ord_4', 'ord_5', 'nulls']]
ordinal = [feat for feat in features if feat not in ohe]
train[features] = SiavashMapping(train[features])
 test[features] = SiavashMapping(test[features])
 imp = IterativeImputer(max_iter=500, initial_strategy='most_frequent', random_state=SEED)
 train[ordinal] = imp.fit_transform(train[ordinal])
 test[ordinal] = imp.transform(test[ordinal])
 train[ordinal] = train[ordinal].astype(np.int16)
 test[ordinal] = test[ordinal].astype(np.int16)
 scaler = RobustScaler(quantile_range=(10.0, 90.0))
oof22, pred22, score['IterativeWithSum'] = LogRegClf(train=train, test=test, ordinal=ordinal, ohe=ohe, scaler=scaler, seed=SEED, splits=SPLITS, drop_idx=None)
 print(f'AUC score for Iterative Imputation with sum of missing values: {score["IterativeWithSum"]}' )
start = time.time()
est_ridge = Ridge(solver='sag', alpha=5)
 est_ridge.fit(X_train, y_train)
 pred_ridge_5 = est_ridge.predict(X_test)
 print(rmsle(10 ** pred_ridge_5 - 1, 10 ** y_test - 1))
print_time(start )<save_to_csv>
scores = pd.DataFrame(score, index=['OOF-AUC'] ).T.sort_values(by='OOF-AUC', ascending=False )
pred_sub = est_ridge.predict(sparse_matrix_sub)
 ridge_submission = submission.copy()
ridge_submission['price'] = pd.DataFrame(10 ** pred_sub - 1)
 ridge_submission.to_csv('ridge_test_2.csv', index=False )<import_modules>
def StackModels() :
idx = baseTe.id.values
train_oofs = [oof1, oof2, oof3, oof4, oof5, oof6, oof7, oof8, oof9, oof10, oof11, oof12, oof13, oof14, oof15, oof16, oof17, oof18, oof19]
test_oofs = [pred1, pred2, pred3, pred4, pred5, pred6, pred7, pred8, pred9, pred10, pred11, pred12, pred13, pred14, pred15, pred16, pred17, pred18, pred19]
X_train = pd.concat([pd.DataFrame(file)for file in train_oofs], axis=1)
 X_test = pd.concat([pd.DataFrame(file)for file in test_oofs], axis=1)
 X_train.columns = ['y_' + str(i)for i in range(len(train_oofs)) ]
X_test.columns = ['y_' + str(i)for i in range(len(train_oofs)) ]
X_train = pd.concat([X_train, base[['target']]], axis=1)
 X_test = pd.concat([X_test, baseTe[['target']]], axis=1)
 for i,(oof, pred)in enumerate(zip(train_oofs, test_oofs)) :
train_oofs[i] = rankdata(oof)/len(oof)
 test_oofs[i] = rankdata(pred)/len(pred)
 for f in X_train.columns:
X_train[f] = X_train[f].astype('float32')
 X_test[f] = X_test[f].astype('float32')
 features = np.array([f for f in X_train.columns if f not in ['target']])
 target = ['target']
oof_pred_final = np.zeros(( len(base),))
y_pred_final = np.zeros(( len(baseTe),))
skf = StratifiedKFold(n_splits=SPLITS, shuffle=True, random_state=SEED)
 model = RidgeClassifier()
selector = RFECV(model, step=1, cv = skf, scoring='roc_auc', verbose=0, n_jobs=4)
 selector.fit(X_train[features], X_train[target])
 selected_features = [i for i, y in enumerate(selector.ranking_)if y == 1]
selected_features = features[selected_features]
for fold,(tr_ind, val_ind)in enumerate(skf.split(X_train, X_train[target])) :
x_tr, x_val = X_train[selected_features].iloc[tr_ind], X_train[selected_features].iloc[val_ind]
y_tr, y_val = X_train[target].iloc[tr_ind], X_train[target].iloc[val_ind]
train_set = {'X':x_tr, 'y':y_tr}
val_set = {'X':x_val, 'y':y_val}
model = RidgeClassifier()
model.fit(train_set['X'],train_set['y'])
 fold_pred = model.decision_function(val_set['X'])
 oof_pred_final[val_ind] = fold_pred
y_pred_final += model.decision_function(X_test[selected_features])/(SPLITS)
 oof_auc_score = roc_auc_score(base[target], oof_pred_final)
 print(f'OOF Stack ROC-AUC Score is: {oof_auc_score:.7f}')
 y_pred_final = rankdata(y_pred_final)/len(y_pred_final)
 np.save('oof_pred_final.npy',oof_pred_final)
 np.save('y_pred_final.npy', y_pred_final)
 print('*'* 36)
 print(' OOF files saved!')
 print('*'* 36)
 submission = pd.DataFrame.from_dict({
'id': idx,
'target': y_pred_final
})
 submission.to_csv('submission.csv', index=False)
 print('*'* 36)
 print(' Submission file saved!')
 print('*'* 36)
 return