Kaggle competition: Amazon.com - Employee Access Challenge
gb_acc = gb.score(x_test.loc[:, gb_selected_features], y_test )<compute_test_metric>
!pip install --user catboost
print('Area Under Curve: {}, Accuracy: {}'.format(gb_auc, gb_acc))<choose_model_class>
train = pd.read_csv('train.csv')
 test = pd.read_csv('test.csv' )
xgboost = xgb.XGBClassifier()<define_search_space>
print(train.isnull().sum())
 test.isnull().sum()
threshold = np.arange(1, 10, 0.5)*1e-2<compute_test_metric>
df = train.drop(columns=['ACTION'])
 train_x = train.drop(columns=['ACTION'])
 train_y = train['ACTION']
test_x = test.drop(columns=['id'])
print('The highest accuracy score is obtained after execluding features whose variance is less than: ',
np.round(threshold[np.argmax(np.array(scores)) ],3))<compute_test_metric>
X_train, X_test, y_train, y_test = train_test_split(train_x, train_y )
print('The highest accuracy score is:', np.max(np.array(scores)) )<define_variables>
model = lm.LogisticRegression()
model.fit(X_train, y_train)
 predictions = model.predict_proba(test_x)
number_of_features = list(range(1,13))<compute_test_metric>
print(f"{X_train.shape}, {X_test.shape}, {test.drop(columns=['id'] ).shape}")
 test_x = test.drop(columns=['id'])
 X_train.reset_index(drop=True, inplace=True)
 y_train.reset_index(drop=True, inplace=True )
print("Maximum accuracy score is :", max(scores_k))<define_variables>
model = naive_bayes.CategoricalNB()
print("Optimal number of features :", np.argmax(np.array(scores_k)) + 1 )<define_variables>
model = DecisionTreeClassifier(max_depth=30)
 clf = model.fit(X_train, y_train)
 print(f'{clf.score(X_test,y_test)}')
 predictions = clf.predict(test_x)
print("Optimal number of features : %d" % selector.n_features_ )<compute_test_metric>
model = RandomForestClassifier(n_estimators = 300)
 clf = model.fit(X_train, y_train)
 print(f'{clf.score(X_test, y_test)}')
 predictions = clf.predict_proba(test_x)
print("Maximum accuracy score is :", np.max(selector.grid_scores_))<define_search_space>
feature_names = dict()
for column, name in enumerate(train):
if column == 0:
continue
feature_names[column - 1] = name
dataset_dir = './amazon'
create_cd(
 label=0,
cat_features=list(range(1, train.columns.shape[0])) ,
feature_names=feature_names,
output_path=os.path.join(dataset_dir, 'train.cd')
 )
threshold = [0.001, 0.0025, 0.005, 0.01, 0.025 ,0.05, 0.1, 0.15]<compute_test_metric>
X = train.drop(columns=['ACTION'])
 y = train.ACTION
cat_features = list(range(0, X.shape[1]))
print(cat_features )
print("Maximum accuracy score is :", np.max(np.array(scores_sfm)) )<compute_test_metric>
pool1 = Pool(data=X, label=y, cat_features=cat_features)
 pool2 = Pool(
 data=os.path.join('/kaggle/input/amazon-employee-access-challenge/', 'train.csv'),
delimiter=',',
column_description=os.path.join(dataset_dir, 'train.cd'),
has_header=True 
)
 pool3 = Pool(data=X, cat_features=cat_features)
 X_prepared = X.values.astype(str ).astype(object)
 pool4 = Pool(
 data=FeaturesData(
 cat_feature_data=X_prepared,
cat_feature_names=list(X)
),
label=y.values 
)
 print('Dataset shape')
 print('dataset 1:' + str(pool1.shape)+
'
dataset 2:' + str(pool2.shape)+
'
dataset 3:' + str(pool3.shape)+
'
dataset 4: ' + str(pool4.shape))
print('
')
 print('Column names')
 print('dataset 1:')
 print(pool1.get_feature_names())
 print('
dataset 2:')
 print(pool2.get_feature_names())
 print('
dataset 3:')
 print(pool3.get_feature_names())
 print('
dataset 4:')
 print(pool4.get_feature_names() )
print("Optimal threshold :", threshold[np.argmax(np.array(scores_sfm)) ] )<train_model>
X_train, X_validation, y_train, y_validation = train_test_split(X, y, train_size=0.7, random_state=1234 )
xgboost = xgb.XGBClassifier()
xgboost.fit(features, target )<compute_train_metric>
model = CatBoostClassifier(
 iterations=3000,
random_seed=1,
learning_rate=0.03,
loss_function = 'CrossEntropy' 
)
 model.fit(
 X_train, y_train,
cat_features=cat_features,
eval_set=(X_validation, y_validation),
verbose=50,
)
y_scores_xgb = xgboost.predict_proba(x_test)[:, 1]
xgb_fpr, xgb_tpr, xgb_thresholds = sklearn.metrics.roc_curve(y_test, y_scores_xgb)
 xgb_auc = sklearn.metrics.auc(x=xgb_fpr, y=xgb_tpr )<compute_test_metric>
model.get_feature_importance(prettified=True )
xgb_acc = xgboost.score(x_test, y_test )<compute_test_metric>
params = {}
params['loss_function'] = 'Logloss'
params['iterations'] = 93
params['custom_loss'] = 'AUC'
params['random_seed'] = 63
params['learning_rate'] = 0.5
cv_data = cv(
 params = params,
pool = Pool(X, label=y, cat_features=cat_features),
fold_count=5,
shuffle=True,
partition_random_seed=0,
stratified=False,
verbose=False
)
print('Area Under Curve: {}, Accuracy: {}'.format(xgb_auc, xgb_acc))<choose_model_class>
best_value = np.min(cv_data['test-Logloss-mean'])
 best_iter = np.argmin(cv_data['test-Logloss-mean'])
 print('Best validation Logloss score, not stratified: {:.4f}±{:.4f} on step {}'.format(
 best_value,
cv_data['test-Logloss-std'][best_iter],
best_iter)
 )
lgboost = lgb.LGBMClassifier()<define_search_space>
test = pd.read_csv('/kaggle/input/amazon-employee-access-challenge/test.csv')
 predictions = model.predict_proba(test_x )
threshold = [0.001, 0.01,0.1,0.5]<define_variables>
predictions = predictions[:,1]
<define_variables><EOS> 
os.chdir('/kaggle/working/')
 os.curdir
sol = pd.DataFrame(predictions)
 sol = sol.rename(columns={0:'Action'})
 sol.index = range(1, 58922,1)
 sol = sol.rename_axis('Id')
 sol.to_csv('submission.csv' )