Kaggle competition: Home Credit Default Risk
<SOS> metric: AUC Kaggle data source: home-credit-default-risk<prepare_x_and_y>
N_FOLDS = 5
MAX_EVALS = 5
X_test = df_test<normalization>
features = pd.read_csv('.. /input/home-credit-default-risk/application_train.csv')
 features = features.sample(n = 17000, random_state = 42)
 features = features.select_dtypes('number')
 labels = np.array(features['TARGET'].astype(np.int32)).reshape(( -1,))
features = features.drop(columns = ['TARGET', 'SK_ID_CURR'])
 train_features, test_features, train_labels, test_labels = train_test_split(features, labels, test_size = 7000, random_state = 37 )
scaler = MinMaxScaler()
cols = X_test.columns
X_test[cols] = scaler.fit_transform(X_test)
 X_test.head()<compute_test_metric>
train_set = lgb.Dataset(data = train_features, label = train_labels)
 test_set = lgb.Dataset(data = test_features, label = test_labels )
def r2_est(X,y):
return r2_score(y, modelo.fit(X,y ).predict(X ).clip(1,100))<compute_test_metric>
model = lgb.LGBMClassifier()
default_params = model.get_params()
del default_params['n_estimators']
cv_results = lgb.cv(default_params, train_set, num_boost_round = 10000, early_stopping_rounds = 100,
metrics = 'auc', nfold = N_FOLDS, seed = 42 )
def mean_absolute_error(y, y_pred):
return(1 / len(y)) * np.sum(np.abs(y - y_pred))<choose_model_class>
print('The maximum validation ROC AUC was: {:.5f} with a standard deviation of {:.5f}.'.format(cv_results['auc-mean'][-1], cv_results['auc-stdv'][-1]))
print('The optimal number of boosting rounds(estimators)was {}.'.format(len(cv_results['auc-mean'])) )
modelo = GradientBoostingRegressor()<train_model>
from sklearn.metrics import roc_auc_score
model_fit = modelo.fit(X,y )<predict_on_test>
model.n_estimators = len(cv_results['auc-mean'])
 model.fit(train_features, train_labels)
 preds = model.predict_proba(test_features)[:, 1]
baseline_auc = roc_auc_score(test_labels, preds)
 print('The baseline model scores {:.5f} ROC AUC on the test set.'.format(baseline_auc))
predictions = model_fit.predict(X ).clip(1,100)
 predictions<compute_test_metric>
def objective(hyperparameters, iteration):

 if 'n_estimators' in hyperparameters.keys() :
del hyperparameters['n_estimators']
cv_results = lgb.cv(hyperparameters, train_set, num_boost_round = 10000, nfold = N_FOLDS,
early_stopping_rounds = 100, metrics = 'auc', seed = 42)
 score = cv_results['auc-mean'][-1]
estimators = len(cv_results['auc-mean'])
 hyperparameters['n_estimators'] = estimators
return [score, hyperparameters, iteration]
print('Baseline R2: %0.3f' % r2_est(X,y))<compute_test_metric>
score, params, iteration = objective(default_params, 1)
 print('The cross-validation ROC AUC was {:.5f}.'.format(score))
print('MAE test score: %0.3f' % mean_absolute_error(y, predictions))<predict_on_test>
model = lgb.LGBMModel()
model.get_params()
predictions = model_fit.predict(X_test ).clip(1,100)
 predictions<save_to_csv>
param_grid = {
'boosting_type': ['gbdt', 'goss', 'dart'],
'num_leaves': list(range(20, 150)) ,
'learning_rate': list(np.logspace(np.log10(0.005), np.log10(0.5), base = 10, num = 1000)) ,
'subsample_for_bin': list(range(20000, 300000, 20000)) ,
'min_child_samples': list(range(20, 500, 5)) ,
'reg_alpha': list(np.linspace(0, 1)) ,
'reg_lambda': list(np.linspace(0, 1)) ,
'colsample_bytree': list(np.linspace(0.6, 1, 10)) ,
'subsample': list(np.linspace(0.5, 1, 100)) ,
'is_unbalance': [True, False]
}
submission = pd.DataFrame()
submission['Property Id'] = index
submission['score'] = predictions.round().astype(int)
 submission.to_csv('submission.csv', index = False )<import_modules>
a = 0
b = 0
for x in param_grid['learning_rate']:
if x >= 0.005 and x < 0.05:
a += 1
elif x >= 0.05 and x < 0.5:
b += 1
print('There are {} values between 0.005 and 0.05'.format(a))
print('There are {} values between 0.05 and 0.5'.format(b))
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score
from math import log as log<load_from_csv>
random_results = pd.DataFrame(columns = ['score', 'params', 'iteration'],
index = list(range(MAX_EVALS)))
 grid_results = pd.DataFrame(columns = ['score', 'params', 'iteration'],
index = list(range(MAX_EVALS)) )
df_train = pd.read_csv('.. /input/web-club-recruitment-2018/train.csv')
 df_test = pd.read_csv('.. /input/web-club-recruitment-2018/test.csv')
<categorify>
com = 1
for x in param_grid.values() :
com *= len(x)
 print('There are {} combinations'.format(com))
def fn(X):
X['X24']=(X.X6+X.X7+X.X8+X.X9+X.X10+X.X11)/X.X1
X['X25']=(X.X12+X.X13+X.X14+X.X15+X.X16+X.X17)/X.X1
X['X26']=(X.X18+X.X19+X.X20+X.X21+X.X22+X.X23)/X.X1
X['X28']=(X.X6+X.X7+X.X8+X.X9+X.X10+X.X11)
 X['X29']=(X.X12+X.X13+X.X14+X.X15+X.X16+X.X17)
 X['X30']=(X.X18+X.X19+X.X20+X.X21+X.X22+X.X23)
 X['X31']=(X.X2==-1)*1+(X.X3==-1)*1+(X.X4==-1)*1+(X.X5==-1)*1
print(X.head())
 return X
train_X = df_train.loc[0:19999, 'X1':'X23']
train_X = fn(train_X)
 print(train_X.head())
 train_y = df_train.loc[0:19999, 'Y']
data_dmatrix = xgb.DMatrix(data=train_X,label=train_y )<choose_model_class>
print('This would take {:.0f} years to finish.'.format(( 100 * com)/(60 * 60 * 24 * 365)) )
xg_reg = xgb.XGBRegressor(objective ='reg:logistic', colsample_bytree = 0.3, learning_rate = 0.024,
max_depth = 6, alpha = 10, n_estimators = 230,eval_metric='auc' )<train_model>
grid_results = grid_search(param_grid)
 print('The best validation score was {:.5f}'.format(grid_results.loc[0, 'score']))
print('
The best hyperparameters were:')
 pprint.pprint(grid_results.loc[0, 'params'] )
xg_reg.fit(train_X,train_y )<predict_on_test>
grid_search_params = grid_results.loc[0, 'params']
model = lgb.LGBMClassifier(**grid_search_params, random_state=42)
 model.fit(train_features, train_labels)
 preds = model.predict_proba(test_features)[:, 1]
print('The best model from grid search scores {:.5f} ROC AUC on the test set.'.format(roc_auc_score(test_labels, preds)) )
train_X = df_test.loc[:, 'X1':'X23']
train_X = fn(train_X)
 pred = xg_reg.predict(train_X)
 pred=pred*(pred>=0)
 pred=(pred*(pred<=1)) + 1*(pred>1 )<save_to_csv>
pd.options.display.max_colwidth = 1000
grid_results['params'].values
result = pd.DataFrame(pred)
 result.index.name = 'id'
result.columns = ['predicted_val']
result.to_csv('output.csv', index=True)
 X = df_train.loc[18000:19999, 'X1':'X23']
X = fn(X)
 Y = df_train.loc[18000:19999, 'Y']
pred = xg_reg.predict(X)
 pred=pred*(pred>=0)
 pred=(pred*(pred<=1)) + 1*(pred>1)
 print(roc_auc_score(Y, pred))<concatenate>
random.seed(50)
 random_params = {k: random.sample(v, 1)[0] for k, v in param_grid.items() }
random_params['subsample'] = 1.0 if random_params['boosting_type'] == 'goss' else random_params['subsample']
random_params
def autocorr_method(frame, sfreq, threshold=0.46, fmin=50, fmax=400):

 frame = frame.astype(np.float)
 frame -= frame.mean()
amax = np.abs(frame ).max()
if amax > 0:
frame /= amax
else:
return 0
corr = correlate(frame, frame)
 corr = corr[len(corr)//2:]
dcorr = np.diff(corr)
 rmin = np.where(dcorr > 0)[0]
if len(rmin)> 0:
rmin1 = rmin[0]
else:
return 0
peak = np.argmax(corr[rmin1:])+ rmin1
rmax = corr[peak]/corr[0]
f0 = sfreq / peak
if rmax > threshold and f0 >= fmin and f0 <= fmax:
return f0
else:
return 0<init_hyperparams>
def random_search(param_grid, max_evals = MAX_EVALS):

 results = pd.DataFrame(columns = ['score', 'params', 'iteration'],
index = list(range(MAX_EVALS)))
 for i in range(MAX_EVALS):
hyperparameters = {k: random.sample(v, 1)[0] for k, v in param_grid.items() }
hyperparameters['subsample'] = 1.0 if hyperparameters['boosting_type'] == 'goss' else hyperparameters['subsample']
eval_results = objective(hyperparameters, i)
 results.loc[i, :] = eval_results
results.sort_values('score', ascending = False, inplace = True)
 results.reset_index(inplace = True)
 return results
class Counters:
def __init__(self, gross_threshold=0.2):
self.num_voiced = 0
self.num_unvoiced = 0
self.num_voiced_unvoiced = 0
self.num_unvoiced_voiced = 0
self.num_voiced_voiced = 0
self.num_gross_errors = 0
self.fine_error = 0
self.e2 = 0
self.gross_threshold = gross_threshold
self.nfiles = 0
def add(self, other):
if other is not None:
self.num_voiced += other.num_voiced
self.num_unvoiced += other.num_unvoiced
self.num_voiced_unvoiced += other.num_voiced_unvoiced
self.num_unvoiced_voiced += other.num_unvoiced_voiced
self.num_voiced_voiced += other.num_voiced_voiced
self.num_gross_errors += other.num_gross_errors
self.fine_error += other.fine_error
self.e2 += other.e2
self.nfiles += 1
def __repr__(self):
nframes = self.num_voiced + self.num_unvoiced
if self.nfiles > 0:
self.fine_error /= self.nfiles
str = [
f"Num.frames:\t{self.num_unvoiced + self.num_voiced} = {self.num_unvoiced} unvoiced + {self.num_voiced} voiced",
f"Unvoiced frames as voiced:\t{self.num_unvoiced_voiced}/{self.num_unvoiced}({100*self.num_unvoiced_voiced/self.num_unvoiced:.2f}%)",
f"Voiced frames as unvoiced:\t{self.num_voiced_unvoiced}/{self.num_voiced}({100*self.num_voiced_unvoiced/self.num_voiced:.2f}%)",
f"Gross voiced errors(>{100*self.gross_threshold}%):\t{self.num_gross_errors}/{self.num_voiced_voiced}({100*self.num_gross_errors/self.num_voiced_voiced:.2f}%)",
f"MSE of fine errors:\t{100*self.fine_error:.2f}%",
f"RMSE:\t{np.sqrt(self.e2/nframes):.2f}"
]
return '
'.join(str )<normalization>
random_results = random_search(param_grid)
 print('The best validation score was {:.5f}'.format(random_results.loc[0, 'score']))
print('
The best hyperparameters were:')
 pprint.pprint(random_results.loc[0, 'params'] )
def compare(fref, pitch):
vref = np.loadtxt(fref)
 vtest = np.array(pitch)
 diff_frames = len(vref)- len(vtest)
 if abs(diff_frames)> 5:
print(f"Error: number of frames in ref({len(vref)})!= number of frames in test({len(vtest)})")
 return None
elif diff_frames > 0:
vref = np.resize(vref, vtest.shape)
 elif diff_frames < 0:
vtest = np.resize(vtest, vref.shape)
 counters = Counters()
counters.num_voiced = np.count_nonzero(vref)
 counters.num_unvoiced = len(vref)- counters.num_voiced
counters.num_unvoiced_voiced = np.count_nonzero(np.logical_and(vref == 0, vtest != 0))
counters.num_voiced_unvoiced = np.count_nonzero(np.logical_and(vref != 0, vtest == 0))
voiced_voiced = np.logical_and(vref != 0, vtest != 0)
 counters.num_voiced_voiced = np.count_nonzero(voiced_voiced)
 f = np.absolute(vref[voiced_voiced] - vtest[voiced_voiced])/vref[voiced_voiced]
gross_errors = f > counters.gross_threshold
counters.num_gross_errors = np.count_nonzero(gross_errors)
 fine_errors = np.logical_not(gross_errors)
 counters.fine_error = np.sqrt(np.square(f[fine_errors] ).mean())if np.count_nonzero(fine_errors)> 0 else 0
counters.e2 = np.square(vref - vtest ).sum()
return counters<categorify>
random_search_params = random_results.loc[0, 'params']
model = lgb.LGBMClassifier(**random_search_params, random_state = 42)
 model.fit(train_features, train_labels)
 preds = model.predict_proba(test_features)[:, 1]
print('The best model from random search scores {:.5f} ROC AUC on the test set.'.format(roc_auc_score(test_labels, preds)) )
def wav2f0(options, gui):
fs = open(options.submission, 'w')if options.submission is not None else None
totalCounters = Counters()
with open(gui)as f:
if fs is not None:
print('id,frequency', file=fs)
 for line in f:
line = line.strip()
if len(line)== 0:
continue
filename = os.path.join(options.datadir, line + ".wav")
 f0ref_filename = os.path.join(options.datadir, line + ".f0ref")
 print("Processing:", filename)
 sfreq, data = wavfile.read(filename)
 nsamples = len(data)
 ns_windowlength = int(round(( options.windowlength * sfreq)/ 1000))
ns_frameshift = int(round(( options.frameshift * sfreq)/ 1000))
ns_left_padding = int(round(( options.left_padding * sfreq)/ 1000))
ns_right_padding = int(round(( options.right_padding * sfreq)/ 1000))
pitch = []
for ini in range(-ns_left_padding, nsamples - ns_windowlength + ns_right_padding + 1, ns_frameshift):
first_sample = max(0, ini)
 last_sample = min(nsamples, ini + ns_windowlength)
 frame = data[first_sample:last_sample]
f0 = autocorr_method(frame, sfreq)
 pitch.append(f0)
 if fs is not None:
for frame_id, f0 in enumerate(pitch):
print(line + '_' + str(frame_id)+ ',', f0, file=fs)
 if os.path.isfile(f0ref_filename):
counters = compare(f0ref_filename, pitch)
 totalCounters.add(counters)
 if totalCounters.num_voiced + totalCounters.num_unvoiced > 0:
print("
print(totalCounters)
 print("-------------------------------
" )<set_options>
out_file = 'random_search_trials.csv'
of_connection = open(out_file, 'w')
 writer = csv.writer(of_connection)
 headers = ['score', 'hyperparameters', 'iteration']
writer.writerow(headers)
 of_connection.close()
fda_ue_options = SimpleNamespace(
 windowlength=32, frameshift=15, left_padding=16, right_padding=16, datadir='.. /input', submission=None)
 wav2f0(fda_ue_options, '.. /input/fda_ue.gui' )<set_options>
def random_search(param_grid, out_file, max_evals = MAX_EVALS):

 results = pd.DataFrame(columns = ['score', 'params', 'iteration'],
index = list(range(MAX_EVALS)))
 for i in range(MAX_EVALS):
random_params = {k: random.sample(v, 1)[0] for k, v in param_grid.items() }
random_params['subsample'] = 1.0 if random_params['boosting_type'] == 'goss' else random_params['subsample']
eval_results = objective(random_params, i)
 results.loc[i, :] = eval_results
of_connection = open(out_file, 'a')
 writer = csv.writer(of_connection)
 writer.writerow(eval_results)
 of_connection.close()
results.sort_values('score', ascending = False, inplace = True)
 results.reset_index(inplace = True)
 return results
test_options = SimpleNamespace(
 windowlength=26.5, frameshift=10, left_padding=13.25, right_padding=7, datadir='.. /input/test', submission='submission.csv')
 wav2f0(test_options, '.. /input/test.gui' )<load_from_csv>
def grid_search(param_grid, out_file, max_evals = MAX_EVALS):

 results = pd.DataFrame(columns = ['score', 'params', 'iteration'],
index = list(range(MAX_EVALS)))
 keys, values = zip(*param_grid.items())
 i = 0
for v in itertools.product(*values):
parameters = dict(zip(keys, v))
parameters['subsample'] = 1.0 if parameters['boosting_type'] == 'goss' else parameters['subsample']
eval_results = objective(parameters, i)
 results.loc[i, :] = eval_results
i += 1
of_connection = open(out_file, 'a')
 writer = csv.writer(of_connection)
 writer.writerow(eval_results)
 of_connection.close()
if i > MAX_EVALS:
break
results.sort_values('score', ascending = False, inplace = True)
 results.reset_index(inplace = True)
 return results
df = pd.read_csv('.. /input/2TWH_train.csv', index_col='IDNum')
 for col in df:
if col[0] == ' ':
df = df.rename(columns={col : col[1:]})
 dt = pd.read_csv('.. /input/test.csv', index_col='IDNum')
 for col in dt:
if col[0] == ' ':
dt = dt.rename(columns={col : col[1:]} )<data_type_conversions>
random_results = pd.read_csv('.. /input/home-credit-model-tuning/random_search_trials_1000.csv')
 grid_results = pd.read_csv('.. /input/home-credit-model-tuning/grid_search_trials_1000.csv' )
df['Source IP'] = df['Source IP'].apply(to_int)
 df['Destination IP'] = df['Destination IP'].apply(to_int)
 df['Timestamp'] = df['Timestamp'].apply(to_int)
 df['Flow Bytes/s'] = df['Flow Bytes/s'].astype(float)
 df['Flow Packets/s'] = df['Flow Packets/s'].astype(float)
 dt['Source IP'] = dt['Source IP'].apply(to_int)
 dt['Destination IP'] = dt['Destination IP'].apply(to_int)
 dt['Timestamp'] = dt['Timestamp'].apply(to_int)
 dt['Flow Bytes/s'] = dt['Flow Bytes/s'].astype(float)
 dt['Flow Packets/s'] = dt['Flow Packets/s'].astype(float )<count_values>
grid_results['hyperparameters'] = grid_results['hyperparameters'].map(ast.literal_eval)
 random_results['hyperparameters'] = random_results['hyperparameters'].map(ast.literal_eval )
MaxValueCount = 100000
df = df.drop(['Private'], axis='columns')
 UselessAttribute = set(['Flow ID'])
 for i in range(df.shape[1]):
value_count = len(df[df.columns[i]].value_counts())
 if(value_count == 1 or value_count > MaxValueCount):
UselessAttribute.add(df.columns[i])
 for attribute in UselessAttribute:
df = df.drop(attribute, axis='columns')
 dt = dt.drop(attribute, axis='columns')
 UselessAttribute.clear()
for i in range(dt.shape[1]):
value_count = len(dt[dt.columns[i]].value_counts())
 if(value_count == 1 or value_count > MaxValueCount):
UselessAttribute.add(dt.columns[i])
 for attribute in UselessAttribute:
df = df.drop(attribute, axis='columns')
 dt = dt.drop(attribute, axis='columns')
 del UselessAttribute<categorify>
def evaluate(results, name):

 results = results.sort_values('score', ascending = False ).reset_index(drop = True)
 print('The highest cross validation score from {} was {:.5f} found on iteration {}.'.format(name, results.loc[0, 'score'], results.loc[0, 'iteration']))
hyperparameters = results.loc[0, 'hyperparameters']
model = lgb.LGBMClassifier(**hyperparameters)
 model.fit(train_features, train_labels)
 preds = model.predict_proba(test_features)[:, 1]
print('ROC AUC from {} on test data = {:.5f}.'.format(name, roc_auc_score(test_labels, preds)))
 hyp_df = pd.DataFrame(columns = list(results.loc[0, 'hyperparameters'].keys()))
for i, hyp in enumerate(results['hyperparameters']):
hyp_df = hyp_df.append(pd.DataFrame(hyp, index = [0]),
ignore_index = True)
 hyp_df['iteration'] = results['iteration']
hyp_df['score'] = results['score']
return hyp_df
df = df.replace([np.inf, 'Infinity', 'infinity', 'inf'], 2**31-1)
 df = df.replace([np.nan, np.inf, 'NaN'], 0)
 dt = dt.replace([np.inf, 'Infinity', 'infinity', 'inf'], 2**31-1)
 dt = dt.replace([np.nan, 'NaN'], 0 )<categorify>
grid_hyp = evaluate(grid_results, name = 'grid search' )
X = df.iloc[:, :-1]
y = df.iloc[:, -1]
enc = LabelEncoder()
y = enc.fit_transform(y )<train_model>
random_hyp = evaluate(random_results, name = 'random search' )
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state = 42)
 ohe = OneHotEncoder(categories='auto')
 y_train_ohe = ohe.fit_transform(y_train.reshape(-1, 1))
y_test_ohe = ohe.fit_transform(y_test.reshape(-1, 1))
y_ohe = ohe.fit_transform(y.reshape(-1, 1))
scaler = StandardScaler()
X_scale = scaler.fit_transform(X.astype(float))
X_train_scale = scaler.fit_transform(X_train.astype(float))
X_test_scale = scaler.transform(X_test.astype(float))<choose_model_class>
alt.renderers.enable('notebook' )
model = Sequential()
model.add(Dense(units=20, activation='relu', input_dim=X.shape[1]))
model.add(Dense(units=10, activation='relu'))
model.add(Dense(units=3, activation='softmax'))
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'] )<train_model>
random_hyp['search'] = 'random'
grid_hyp['search'] = 'grid'
hyp = random_hyp.append(grid_hyp)
 hyp.head()
history = model.fit(X_train_scale,
y_train_ohe,
epochs=1000,
batch_size=8192,
validation_data=(X_test_scale, y_test_ohe))<compute_test_metric>
best_grid_hyp = grid_hyp.iloc[grid_hyp['score'].idxmax() ].copy()
best_random_hyp = random_hyp.iloc[random_hyp['score'].idxmax() ].copy()
confusion_matrix(y, model.predict_classes(X))<save_to_csv>
print('Average validation score of grid search = {:.5f}.'.format(np.mean(grid_hyp['score'])))
 print('Average validation score of random search = {:.5f}.'.format(np.mean(random_hyp['score'])) )
dt_scale = scaler.transform(dt)
 dftest = pd.DataFrame(enc.inverse_transform(model.predict_classes(dt_scale)) , columns=['Label'], index=dt.index ).reset_index()
dftest.sort_values('IDNum')
 dftest.to_csv('submission.csv', index=False )<load_from_csv>
random_hyp['score'] = random_hyp['score'].astype(float)
 best_random_hyp = random_hyp.loc[0, :].copy()
test_df = pd.read_csv('/kaggle/input/epam-ml-training-imdb/train.csv', index_col='Id')
 test_df.head()<define_variables>
train = pd.read_csv('.. /input/home-credit-simple-featuers/simple_features_train.csv')
 test = pd.read_csv('.. /input/home-credit-simple-featuers/simple_features_test.csv')
 test_ids = test['SK_ID_CURR']
train_labels = np.array(train['TARGET'].astype(np.int32)).reshape(( -1,))
train = train.drop(columns = ['SK_ID_CURR', 'TARGET'])
 test = test.drop(columns = ['SK_ID_CURR'])
 print('Training shape: ', train.shape)
 print('Testing shape: ', test.shape )
predictions = ['positive']*len(test_df )<prepare_output>
train_set = lgb.Dataset(train, label = train_labels)
 hyperparameters = dict(**random_results.loc[0, 'hyperparameters'])
 del hyperparameters['n_estimators']
cv_results = lgb.cv(hyperparameters, train_set,
num_boost_round = 10000, early_stopping_rounds = 100,
metrics = 'auc', nfold = N_FOLDS )
subm_df = pd.DataFrame({'Predicted': predictions}, index=test_df.index)
 subm_df.head()<save_to_csv>
print('The cross validation score on the full dataset = {:.5f} with std: {:.5f}.'.format(
 cv_results['auc-mean'][-1], cv_results['auc-stdv'][-1]))
print('Number of estimators = {}.'.format(len(cv_results['auc-mean'])) )
subm_df.to_csv('/kaggle/working/submission.csv' )<import_modules>
model = lgb.LGBMClassifier(n_estimators = len(cv_results['auc-mean']), **hyperparameters)
 model.fit(train, train_labels)
 preds = model.predict_proba(test)[:, 1]
import numpy as np
import matplotlib.pyplot as plt<prepare_x_and_y>
submission = pd.DataFrame({'SK_ID_CURR': test_ids, 'TARGET': preds})
 submission.to_csv('submission_simple_features_random.csv', index = False )
X_train = np.load('.. /input/uci-math-10-winter2020/kmnist-train-imgs.npz')['X']
y_train = np.load('.. /input/uci-math-10-winter2020/kmnist-train-labels.npz')['y']
X_test = np.load('.. /input/uci-math-10-winter2020/kmnist-test-imgs.npz')['X']<import_modules>
clf_xgBoost = xgb.XGBClassifier(
 learning_rate =0.01, n_estimators=1000, max_depth=4, min_child_weight=4, subsample=0.8, colsample_bytree=0.8, objective= 'binary:logistic',
nthread=4, scale_pos_weight=2, seed=27)
 clf_xgBoost.fit(train,train_labels )
from sklearn.neighbors import KNeighborsClassifier<import_modules>
pred = clf_xgBoost.predict_proba(test)[:, 1]
<import_modules><EOS> 
submission = pd.DataFrame({'SK_ID_CURR': test_ids, 'TARGET': pred})
 submission.to_csv('submission_xgboost.csv', index = False)
 submission.head()