Kaggle competition: Santander Customer Transaction Prediction
t = df_submission.loc[df_submission.maxPlace > 1]
gap = 1.0 /(t.maxPlace.values - 1)
 fixed_perc = np.around(t.winPlacePerc.values / gap)* gap
df_submission.loc[df_submission.maxPlace > 1, 'winPlacePerc'] = fixed_perc<feature_engineering>
import lightgbm as lgb
from sklearn.model_selection import StratifiedKFold, cross_val_score
df_submission.loc[(df_submission.maxPlace > 1)&(df_submission.numGroups == 1), 'winPlacePerc'] = 0
assert df_submission['winPlacePerc'].isnull().sum() == 0<save_to_csv>
train = pd.read_csv('.. /input/train.csv' ).set_index('ID_code')
 print(train.shape)
 train.head()
df_submission[['Id', 'winPlacePerc']].to_csv('pytorch_adjusted.csv', index=False )<concatenate>
test = pd.read_csv('.. /input/test.csv' ).set_index('ID_code')
 print(test.shape)
 test.head()
def toTapleList(list1,list2):
return list(itertools.product(list1,list2))<load_from_csv>
RS = 2019
%%time
train = pd.read_csv('.. /input/train_V2.csv')
 train = reduce_mem_usage(train)
 test = pd.read_csv('.. /input/test_V2.csv')
 test = reduce_mem_usage(test)
 print(train.shape, test.shape )<count_missing_values>
X_train,y_train = train.iloc[:,1:],train.iloc[:,0]
null_cnt = train.isnull().sum().sort_values()
print('null count:', null_cnt[null_cnt > 0])
 train.dropna(inplace=True )<concatenate>
skf = StratifiedKFold(n_splits=5,random_state=RS,shuffle=True, )
all_data = train.append(test, sort=False ).reset_index(drop=True)
 del train, test
gc.collect()<data_type_conversions>
model = lgb.LGBMClassifier(boosting_type='gbdt', num_leaves=4, learning_rate=0.05, n_estimators=4500,
objective='binary',min_child_samples=2, subsample=.9, colsample_bytree=.05,
reg_alpha=0.0, reg_lambda=0.0, seed=RS,importance_type='gain',)
 out = cross_val_score(model, X=X_train, y=y_train, scoring='roc_auc', cv=skf.split(X_train,y_train), verbose=1,)
 print(out.mean() ,out.std() ,out.mean() -out.std())
def fillInf(df, val):
numcols = df.select_dtypes(include='number' ).columns
cols = numcols[numcols != 'winPlacePerc']
df[df == np.Inf] = np.NaN
df[df == np.NINF] = np.NaN
for c in cols: df[c].fillna(val, inplace=True )<feature_engineering>
model.fit(X_train,y_train)
 pred_test = model.predict_proba(test)[:,1]
sub = pd.DataFrame({'ID_code':test.index,'target':pred_test})
 sub.to_csv('my_lgb_sub.csv',index=False)
 sub.head()