Kaggle competition: Tabular Playground Series - Jan 2021
IMSIZE =(224, 240, 260, 300, 380, 456, 528, 600, 512)
 load_dir = f"/kaggle/input/{COMPETITION_NAME}/"
sub_df = pd.read_csv(load_dir + 'sample_submission.csv')
 test_paths = load_dir + "test/" + sub_df['StudyInstanceUID'] + '.jpg'
label_cols = sub_df.columns[1:]
test_decoder = build_decoder(with_labels=False, target_size=(IMSIZE[-2], IMSIZE[-2]))
dtest = build_dataset(
 test_paths, bsize=BATCH_SIZE, repeat=False,
shuffle=False, augment=False, cache=False,
decode_fn=test_decoder
)<choose_model_class>
%%time
train = pd.read_csv(".. /input/tabular-playground-series-jan-2021/train.csv")
 test = pd.read_csv(".. /input/tabular-playground-series-jan-2021/test.csv")
 df=pd.concat([train,test],0 ).reset_index(drop=True)
 df.sort_values(by=['id'],inplace=True)
 df
def create_model(w, input_shape=[IMSIZE[-2], IMSIZE[-2],3], classes=11):
base_model = efn.EfficientNetB7(include_top=False,
weights=None,
input_shape=input_shape)
 inputs = tf.keras.Input(shape=input_shape)
 x = base_model(inputs)
 x = tf.keras.layers.GlobalAveragePooling2D()(x)
 x = tf.keras.layers.Dense(classes )(x)
 outputs = tf.keras.layers.Activation('sigmoid', dtype='float32' )(x)
 model = tf.keras.Model(inputs, outputs)
 model.load_weights(w)
 return model<save_to_csv>
cols=df.drop(['id','target'],1 ).columns
df['mean']=df[cols].mean(axis=1)
 df['min']=df[cols].min(axis=1)
 df['max']=df[cols].max(axis=1)
 df['std']=df[cols].std(axis=1)
 df['kurt']=df[cols].kurt(axis=1)
 df['mad']=df[cols].mad(axis=1)
 df['median']=df[cols].median(axis=1)
 df['skew']=df[cols].skew(axis=1)
 df['sum']=df[cols].sum(axis=1)
 df['sem']=df[cols].sem(axis=1)
 df['idxmin']=df[cols].idxmin(axis=1 ).str.replace("cont","" ).astype(int)
 df['idxmax']=df[cols].idxmax(axis=1 ).str.replace("cont","" ).astype(int)
 df
sub_df[label_cols] = model.predict(dtest, verbose=1)
 sub_df.to_csv('submission.csv', index=False)
 sub_df.head()<install_modules>
for c1 in cols:
print(c1)
 for c2 in cols:
if c1<c2:
df[f'{c1}MOINS{c2}']=df[f'{c1}']-df[f'{c2}']
df[f'{c1}PLUS{c2}']=df[f'{c1}']+df[f'{c2}']
df[f'{c1}FOIS{c2}']=df[f'{c1}']*df[f'{c2}']
df[f'{c1}DIV{c2}']=df[f'{c1}']/df[f'{c2}']
!pip install.. /input/keras-efficientnet-whl/Keras_Applications-1.0.8-py3-none-any.whl
!pip install.. /input/keras-efficientnet-whl/efficientnet-1.1.1-py3-none-any.whl<set_options>
target='target'
train=df[df['target'].notnull() ]
test=df[~(df['target'].notnull())]
print(train.shape,test.shape)
 y = train[target].copy()
X = train.drop([target,'id'],1)
 features=X.columns
FOLDS=13
SEED=2021
oof=np.zeros(y.shape[0])
 preds=np.zeros(test.shape[0])
 skf = KFold(n_splits=FOLDS, shuffle=True, random_state=SEED)
 for fold,(idxT,idxV)in enumerate(skf.split(X)) :
print("FOLD",fold)
 X_train,y_train=X.loc[idxT,features],y[idxT]
X_test,y_test=X.loc[idxV,features],y[idxV]
fit_params={"early_stopping_rounds":300,
"eval_metric" : ['rmse'],
"eval_set" : [(X_test,y_test)],
'eval_names': ['valid'],
'verbose': 100,
'feature_name': 'auto',
'categorical_feature': 'auto'
}
evals_result = {}
clf = lgb.LGBMRegressor(num_leaves= 255, max_depth=-1,
seed=42,
objective="regression",
silent=True,
verbose=1,
num_threads=-1,
n_estimators=100000,
colsample_bytree=0.7,
subsample=0.8,
learning_rate=0.01)
 START=time.time()
clf.fit(X_train, y_train, **fit_params)
 oof[idxV]=clf.predict(X_test)
 preds+=clf.predict(test[features])/FOLDS
print("RMSE",mean_squared_error(y_test,oof[idxV]))
END=time.time()
print("time to train ",round(END-START,1),"secondes")
 feat_imp = pd.Series(clf.feature_importances_, index=X_train.columns)
 feat_imp=pd.DataFrame(feat_imp ).reset_index()
feat_imp.columns=['id','importance']
feat_imp.sort_values('importance',ascending=False,inplace=True)
 joblib.dump(clf, f'{fold}.pkl')
 print(feat_imp[:50])
 print("RMSE Global",mean_squared_error(y, oof))
<load_from_csv><EOS> 
sample_submission=pd.read_csv(".. /input/tabular-playground-series-jan-2021/sample_submission.csv")
 sample_submission['target'] = preds
sample_submission.to_csv('submission.csv', index=False )