Kaggle competition: Give Me Some Credit
<SOS> metric: AUC Kaggle data source: give-me-some-credit<feature_engineering>
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score,roc_curve, auc
from sklearn.ensemble import RandomForestRegressor
from lightgbm import LGBMClassifier
for i in range(x_train.shape[1]):
x_test[:, i] =(x_test[:, i] - np.mean(x_train[:, i])) /np.std(x_train[:, i])
 x_train[:, i] =(x_train[:, i] - np.mean(x_train[:, i])) /np.std(x_train[:, i] )<train_on_grid>
train=pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-training.csv')
 train.info()
train = train[train['age']>0]

 train.loc[train['NumberOfTime30-59DaysPastDueNotWorse']>20, 'NumberOfTime30-59DaysPastDueNotWorse'] = 6
train.loc[train['NumberOfTimes90DaysLate']>20, 'NumberOfTimes90DaysLate'] = 2
train.loc[train['NumberOfTime60-89DaysPastDueNotWorse']>20, 'NumberOfTime60-89DaysPastDueNotWorse'] = 3
train.describe(percentiles=[.10,.20,.30,.40,.60,.70,.80,.90,.95,.99,.999] )
clf_nn = MLPClassifier(solver='lbfgs', random_state=1)
 params = {
'alpha': [1e-6],
'activation': ['tanh'],
'hidden_layer_sizes': [(10, 30, 5)]
}
gs_nn = GridSearchCV(clf_nn, param_grid=params, scoring='neg_log_loss', n_jobs=2, cv=2, verbose=2, refit=True)
 start = time.time()
gs_nn.fit(x_train, df.y.values)
 print('- Time: %.2f minutes' %(( time.time() - start)/60))
print('- Best score: %.4f' % gs_nn.best_score_)
 print('- Best params: %s' % gs_nn.best_params_ )<compute_test_metric>
train["NumberOfDependents"].fillna(train["NumberOfDependents"].mode() [0], inplace=True)
 mData = train.iloc[:,[6,2,3,4,5,7,8,9,10,11]]
train_known = mData[mData.MonthlyIncome.notnull() ].values
train_unknown = mData[mData.MonthlyIncome.isnull() ].values
train_X = train_known[:,1:]
train_y = train_known[:,0]
rfr = RandomForestRegressor(random_state=0,n_estimators=200,max_depth=3,n_jobs=-1)
 rfr.fit(train_X,train_y)
 predicted_y = rfr.predict(train_unknown[:,1:] ).round(0)
 train.loc[train.MonthlyIncome.isnull() ,'MonthlyIncome'] = predicted_y
output_results(gs_nn, x_test, df_test.listing_id.values, 'basic_nn.csv' )<set_options>
train_X = train_2[train_2.columns[2:]]
train_y = train_2[train_2.columns[1]]
train_X, test_X, train_y, test_y = train_test_split(train_X, train_y, test_size=0.1, random_state=20, stratify=train_y )
pd.options.display.max_rows = 500
pd.options.display.max_columns = 500<feature_engineering>
lgbm = LGBMClassifier(max_depth=20,num_leaves=30,learning_rate=0.02,n_estimators=250,feature_fraction=0.7)
 lgbm.fit(train_X,train_y)
 pre_y = lgbm.predict_proba(test_X)[:,1]
def set_seed(seed: int = 42):
random.seed(seed)
 np.random.seed(seed)
 os.environ["PYTHONHASHSEED"] = str(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 @contextmanager
def timer(name: str)-> None:

 t0 = time.time()
print("[{}] start".format(name))
yield
print("[{}] done in {:.0f} s".format(name, time.time() - t0))<define_variables>
test=pd.read_csv('/kaggle/input/GiveMeSomeCredit/cs-test.csv')
 test.info()
test.loc[test['NumberOfTime30-59DaysPastDueNotWorse']>20, 'NumberOfTime30-59DaysPastDueNotWorse'] = 6
test.loc[test['NumberOfTimes90DaysLate']>20, 'NumberOfTimes90DaysLate'] = 2
test.loc[test['NumberOfTime60-89DaysPastDueNotWorse']>20, 'NumberOfTime60-89DaysPastDueNotWorse'] = 3
test.describe()
set_seed(1213 )<define_variables>
test["NumberOfDependents"].fillna(train["NumberOfDependents"].mode() [0], inplace=True)
 mData2 = test.iloc[:,[6,2,3,4,5,7,8,9,10,11]]
test_known = mData2[mData2.MonthlyIncome.notnull() ].values
test_unknown = mData2[mData2.MonthlyIncome.isnull() ].values
test_X2 = test_known[:,1:]
test_y2 = test_known[:,0]
rfr2 = RandomForestRegressor(random_state=0,n_estimators=200,max_depth=3,n_jobs=-1)
 rfr2.fit(test_X2,test_y2)
 predicted_y = rfr2.predict(test_unknown[:,1:] ).round(0)
 test.loc[test.MonthlyIncome.isnull() ,'MonthlyIncome'] = predicted_y
ROOT = Path.cwd().parent
INPUT_ROOT = ROOT / "input"
RAW_DATA = INPUT_ROOT / "birdsong-recognition"
TRAIN_AUDIO_DIR = RAW_DATA / "train_audio"
TEST_AUDIO_DIR = RAW_DATA / "test_audio"<load_from_csv>
test2 = test[test.columns[2:]]
pre_y2 = lgbm.predict_proba(test2)[:,1]
train = pd.read_csv(RAW_DATA / "train.csv" )<load_from_csv>
result=pd.read_csv('/kaggle/input/GiveMeSomeCredit/sampleEntry.csv')
 result['Probability'] = pre_y2
result.to_csv('./submit.csv',index=False)
 reload = pd.read_csv('./submit.csv')
 reload