Kaggle competition: Mechanisms of Action (MoA) Prediction
train_df.isnull().sum().sum()
test_df.isnull().sum().sum()<feature_engineering>
train = pd.read_csv('/kaggle/input/lish-moa/train_features.csv')
 train.shape
def add_new_feature_row(df,features):
for feature in features:
df[feature+"_pct"] = df[feature].pct_change()
df[feature+"_diff"] = df[feature].diff()
df.drop(feature,axis=1)
 return df 
<feature_engineering>
train_target = pd.read_csv('/kaggle/input/lish-moa/train_targets_scored.csv')
 train_target.shape
def add_feature_df(df,features):
df['count+'] = np.array(df>0 ).sum(axis=1)
 df['count-'] = np.array(df<0 ).sum(axis=1)
 for feature in features:
df['tanh_'+feature] = np.tanh(df[feature])
 return df 
<set_options>
test = pd.read_csv('/kaggle/input/lish-moa/test_features.csv')
 test.shape
gc.collect()<concatenate>
train.at[train['cp_type'].str.contains('ctl_vehicle'),train.filter(regex='-.*' ).columns] = 0.0
test.at[test['cp_type'].str.contains('ctl_vehicle'),test.filter(regex='-.*' ).columns] = 0.0
test_df['target']= np.nan
combine_df = train_df.append(test_df,ignore_index=True )<split>
train_size = train.shape[0]
traintest = pd.concat([train, test])
 traintest = pd.concat([traintest, pd.get_dummies(traintest['cp_type'], prefix='cp_type')], axis=1)
 traintest = pd.concat([traintest, pd.get_dummies(traintest['cp_time'], prefix='cp_time')], axis=1)
 traintest = pd.concat([traintest, pd.get_dummies(traintest['cp_dose'], prefix='cp_dose')], axis=1)
 traintest = traintest.drop(['cp_type', 'cp_time', 'cp_dose'], axis=1)
 train = traintest[:train_size]
test = traintest[train_size:]
del traintest
train_df = combine_df[combine_df['target'].notnull() ].reset_index(drop=True)
 test_df = combine_df[combine_df['target'].isnull() ].reset_index(drop=True)
<filter>
g_columns = [ c for c in train.columns if 'g-' in c ]
scaler = StandardScaler()
train[g_columns] = scaler.fit_transform(train[g_columns])
 test[g_columns] = scaler.transform(test[g_columns] )
fs = FeatureSelector(data = train_df[features], labels = train_df["target"] )<set_options>
x_train = train.drop('sig_id', axis=1)
 y_train = train_target.drop('sig_id', axis=1)
 x_test = test.drop('sig_id', axis=1 )
fs.identify_all(selection_params = {'missing_threshold': 0.6,
'correlation_threshold': 0.95,
'task': 'classification',
'eval_metric': 'auc',
'cumulative_importance': 0.95} )<define_variables>
options = {
'default': {
'features': list(x_train.columns)
 }
}
zero_importance_features = fs.ops['zero_importance']
zero_importance_features<drop_column>
def make_x(option):
features = options[option]['features']
return x_train[features], x_test[features]
train_removed_all = fs.remove(methods = 'all',
keep_one_hot=False )<save_to_csv>
from sklearn.feature_selection import RFECV
import lightgbm as lgb
with open("feat_sel.csv","w")as fp:
for line in feat_sel:
fp.write(str(line)+"
")
<load_from_csv>
params = {
'objective': 'binary',
'learning_rate': 0.05,
'max_depth': -1,
'num_leaves': 31,
'num_threads': 4,
'random_state': 42
}
train_df = pd.read_csv('.. /input/train.csv')
 test_df = pd.read_csv('.. /input/test.csv')
 test_df['target']= np.nan
combine_df = train_df.append(test_df,ignore_index=True)
 features = train_df.columns[~train_df.columns.isin(['target','ID_code'])]
combine_df = add_feature_df(combine_df,features)
 train_df = combine_df[combine_df['target'].notnull() ].reset_index(drop=True)
 test_df = combine_df[combine_df['target'].isnull() ].reset_index(drop=True )<save_to_csv>
options['500'] = {
'features': ['g-0', 'g-1', 'g-2', 'g-3', 'g-4', 'g-5', 'g-6', 'g-7', 'g-8', 'g-9', 'g-10', 'g-11', 'g-12', 'g-13', 'g-14', 'g-15', 'g-16', 'g-17', 'g-18', 'g-19', 'g-20', 'g-21', 'g-22', 'g-23', 'g-24', 'g-25', 'g-26', 'g-27', 'g-28', 'g-29', 'g-30', 'g-31', 'g-32', 'g-33', 'g-34', 'g-35', 'g-36', 'g-37', 'g-38', 'g-39', 'g-40', 'g-41', 'g-42', 'g-43', 'g-44', 'g-45', 'g-46', 'g-47', 'g-48', 'g-49', 'g-50', 'g-51', 'g-52', 'g-53', 'g-54', 'g-55', 'g-56', 'g-57', 'g-58', 'g-59', 'g-60', 'g-61', 'g-62', 'g-63', 'g-64', 'g-65', 'g-66', 'g-67', 'g-68', 'g-69', 'g-70', 'g-71', 'g-72', 'g-73', 'g-74', 'g-75', 'g-76', 'g-77', 'g-78', 'g-79', 'g-80', 'g-81', 'g-82', 'g-83', 'g-84', 'g-85', 'g-86', 'g-87', 'g-88', 'g-89', 'g-90', 'g-91', 'g-92', 'g-93', 'g-94', 'g-95', 'g-96', 'g-97', 'g-98', 'g-99', 'g-100', 'g-101', 'g-102', 'g-103', 'g-104', 'g-105', 'g-106', 'g-107', 'g-108', 'g-109', 'g-110', 'g-111', 'g-112', 'g-113', 'g-114', 'g-115', 'g-116', 'g-117', 'g-118', 'g-121', 'g-122', 'g-123', 'g-125', 'g-126', 'g-127', 'g-128', 'g-129', 'g-130', 'g-131', 'g-132', 'g-133', 'g-139', 'g-144', 'g-149', 'g-152', 'g-153', 'g-154', 'g-155', 'g-158', 'g-161', 'g-162', 'g-165', 'g-166', 'g-167', 'g-168', 'g-169', 'g-170', 'g-171', 'g-172', 'g-173', 'g-174', 'g-175', 'g-176', 'g-177', 'g-178', 'g-179', 'g-180', 'g-182', 'g-185', 'g-188', 'g-189', 'g-191', 'g-192', 'g-193', 'g-194', 'g-195', 'g-196', 'g-197', 'g-198', 'g-199', 'g-200', 'g-201', 'g-202', 'g-203', 'g-204', 'g-209', 'g-211', 'g-213', 'g-214', 'g-217', 'g-220', 'g-221', 'g-222', 'g-223', 'g-225', 'g-226', 'g-229', 'g-233', 'g-239', 'g-240', 'g-243', 'g-244', 'g-246', 'g-247', 'g-250', 'g-254', 'g-255', 'g-256', 'g-257', 'g-259', 'g-261', 'g-262', 'g-265', 'g-269', 'g-270', 'g-271', 'g-273', 'g-279', 'g-282', 'g-284', 'g-286', 'g-289', 'g-292', 'g-294', 'g-295', 'g-298', 'g-299', 'g-300', 'g-303', 'g-306', 'g-310', 'g-311', 'g-312', 'g-314', 'g-316', 'g-317', 'g-318', 'g-320', 'g-321', 'g-323', 'g-326', 'g-327', 'g-328', 'g-332', 'g-333', 'g-335', 'g-339', 'g-340', 'g-341', 'g-346', 'g-347', 'g-351', 'g-353', 'g-355', 'g-357', 'g-360', 'g-364', 'g-365', 'g-370', 'g-375', 'g-383', 'g-385', 'g-388', 'g-389', 'g-390', 'g-391', 'g-392', 'g-399', 'g-401', 'g-402', 'g-403', 'g-404', 'g-409', 'g-417', 'g-423', 'g-424', 'g-425', 'g-426', 'g-428', 'g-429', 'g-430', 'g-431', 'g-433', 'g-434', 'g-438', 'g-439', 'g-440', 'g-441', 'g-443', 'g-444', 'g-445', 'g-446', 'g-447', 'g-448', 'g-449', 'g-450', 'g-451', 'g-452', 'g-453', 'g-454', 'g-455', 'g-456', 'g-460', 'g-461', 'g-463', 'g-465', 'g-467', 'g-470', 'g-473', 'g-474', 'g-475', 'g-476', 'g-481', 'g-483', 'g-485', 'g-486', 'g-489', 'g-490', 'g-495', 'g-500', 'g-501', 'g-502', 'g-504', 'g-509', 'g-513', 'g-516', 'g-517', 'g-518', 'g-527', 'g-531', 'g-535', 'g-540', 'g-542', 'g-543', 'g-544', 'g-547', 'g-548', 'g-549', 'g-552', 'g-556', 'g-558', 'g-562', 'g-566', 'g-571', 'g-572', 'g-573', 'g-574', 'g-578', 'g-584', 'g-585', 'g-590', 'g-592', 'g-595', 'g-596', 'g-600', 'g-602', 'g-603', 'g-605', 'g-606', 'g-611', 'g-612', 'g-615', 'g-617', 'g-618', 'g-619', 'g-620', 'g-623', 'g-624', 'g-625', 'g-626', 'g-627', 'g-628', 'g-629', 'g-630', 'g-631', 'g-632', 'g-633', 'g-634', 'g-635', 'g-636', 'g-637', 'g-638', 'g-639', 'g-640', 'g-643', 'g-645', 'g-646', 'g-648', 'g-651', 'g-654', 'g-657', 'g-658', 'g-659', 'g-660', 'g-661', 'g-662', 'g-663', 'g-664', 'g-665', 'g-666', 'g-668', 'g-670', 'g-672', 'g-673', 'g-674', 'g-675', 'g-677', 'g-678', 'g-679', 'g-685', 'g-689', 'g-695', 'g-697', 'g-698', 'g-699', 'g-701', 'g-702', 'g-703', 'g-704', 'g-707', 'g-709', 'g-710', 'g-712', 'g-713', 'g-714', 'g-715', 'g-721', 'g-722', 'g-724', 'g-725', 'g-726', 'g-734', 'g-736', 'g-737', 'g-740', 'g-742', 'g-743', 'g-745', 'g-747', 'g-750', 'g-751', 'g-752', 'g-753', 'g-756', 'g-757', 'g-758', 'g-759', 'g-760', 'g-761', 'g-762', 'g-763', 'g-764', 'g-766', 'g-767', 'g-768', 'g-769', 'g-770', 'g-771', 'c-0', 'c-1', 'c-2', 'c-3', 'c-4', 'c-5', 'c-11', 'c-12', 'c-14', 'c-19', 'c-20', 'c-21', 'c-22', 'c-23', 'c-25', 'c-27', 'c-32', 'c-35', 'c-36', 'c-37', 'c-40', 'c-47', 'c-54', 'c-55', 'c-57', 'c-58', 'c-61', 'c-62', 'c-63', 'c-65', 'c-66', 'c-71', 'c-74', 'c-75', 'c-77', 'c-78', 'c-79', 'c-80', 'c-81', 'c-82', 'c-83', 'c-84', 'c-85', 'c-86', 'c-87', 'c-88', 'c-89', 'c-90', 'c-91', 'c-92', 'c-93', 'c-97']
}
imp_df.sort_values(by="importance_gain",ascending=False ).to_csv("imp_lgb.csv", index=False)
<sort_values>
options['600'] = {
'features': ['g-0', 'g-1', 'g-2', 'g-3', 'g-4', 'g-5', 'g-6', 'g-7', 'g-8', 'g-9', 'g-10', 'g-11', 'g-12', 'g-13', 'g-14', 'g-15', 'g-16', 'g-17', 'g-18', 'g-19', 'g-20', 'g-21', 'g-22', 'g-23', 'g-24', 'g-25', 'g-26', 'g-27', 'g-28', 'g-29', 'g-30', 'g-31', 'g-32', 'g-33', 'g-34', 'g-35', 'g-36', 'g-37', 'g-38', 'g-39', 'g-40', 'g-41', 'g-42', 'g-43', 'g-44', 'g-45', 'g-46', 'g-47', 'g-48', 'g-49', 'g-50', 'g-51', 'g-52', 'g-53', 'g-54', 'g-55', 'g-56', 'g-57', 'g-58', 'g-59', 'g-60', 'g-61', 'g-62', 'g-63', 'g-64', 'g-65', 'g-66', 'g-67', 'g-68', 'g-69', 'g-70', 'g-71', 'g-72', 'g-73', 'g-74', 'g-75', 'g-76', 'g-77', 'g-78', 'g-79', 'g-80', 'g-81', 'g-82', 'g-83', 'g-84', 'g-85', 'g-86', 'g-87', 'g-88', 'g-89', 'g-90', 'g-91', 'g-92', 'g-93', 'g-94', 'g-95', 'g-96', 'g-97', 'g-98', 'g-99', 'g-100', 'g-101', 'g-102', 'g-103', 'g-104', 'g-105', 'g-106', 'g-107', 'g-108', 'g-109', 'g-110', 'g-111', 'g-112', 'g-113', 'g-114', 'g-115', 'g-116', 'g-117', 'g-118', 'g-119', 'g-120', 'g-121', 'g-122', 'g-123', 'g-124', 'g-125', 'g-126', 'g-127', 'g-128', 'g-129', 'g-130', 'g-131', 'g-132', 'g-133', 'g-134', 'g-135', 'g-136', 'g-137', 'g-138', 'g-139', 'g-140', 'g-141', 'g-142', 'g-143', 'g-144', 'g-145', 'g-146', 'g-147', 'g-148', 'g-149', 'g-150', 'g-151', 'g-152', 'g-153', 'g-154', 'g-155', 'g-156', 'g-157', 'g-158', 'g-159', 'g-160', 'g-161', 'g-162', 'g-163', 'g-164', 'g-165', 'g-166', 'g-167', 'g-168', 'g-169', 'g-170', 'g-171', 'g-172', 'g-173', 'g-174', 'g-175', 'g-176', 'g-177', 'g-178', 'g-179', 'g-180', 'g-181', 'g-182', 'g-183', 'g-184', 'g-185', 'g-186', 'g-187', 'g-188', 'g-189', 'g-190', 'g-191', 'g-192', 'g-193', 'g-194', 'g-195', 'g-196', 'g-197', 'g-198', 'g-199', 'g-200', 'g-201', 'g-202', 'g-203', 'g-204', 'g-205', 'g-206', 'g-207', 'g-208', 'g-209', 'g-210', 'g-211', 'g-212', 'g-213', 'g-214', 'g-215', 'g-217', 'g-220', 'g-221', 'g-222', 'g-223', 'g-225', 'g-226', 'g-229', 'g-233', 'g-239', 'g-240', 'g-241', 'g-242', 'g-243', 'g-244', 'g-245', 'g-246', 'g-247', 'g-250', 'g-254', 'g-255', 'g-256', 'g-257', 'g-259', 'g-261', 'g-262', 'g-265', 'g-269', 'g-270', 'g-271', 'g-272', 'g-273', 'g-279', 'g-282', 'g-284', 'g-286', 'g-289', 'g-292', 'g-294', 'g-295', 'g-298', 'g-299', 'g-300', 'g-303', 'g-306', 'g-310', 'g-311', 'g-312', 'g-314', 'g-316', 'g-317', 'g-318', 'g-320', 'g-321', 'g-323', 'g-326', 'g-327', 'g-328', 'g-332', 'g-333', 'g-335', 'g-339', 'g-340', 'g-341', 'g-346', 'g-347', 'g-351', 'g-353', 'g-355', 'g-357', 'g-360', 'g-364', 'g-365', 'g-370', 'g-375', 'g-383', 'g-385', 'g-388', 'g-389', 'g-390', 'g-391', 'g-392', 'g-399', 'g-401', 'g-402', 'g-403', 'g-404', 'g-409', 'g-417', 'g-423', 'g-424', 'g-425', 'g-426', 'g-428', 'g-429', 'g-430', 'g-431', 'g-433', 'g-434', 'g-438', 'g-439', 'g-440', 'g-441', 'g-443', 'g-444', 'g-445', 'g-446', 'g-447', 'g-448', 'g-449', 'g-450', 'g-451', 'g-452', 'g-453', 'g-454', 'g-455', 'g-456', 'g-460', 'g-461', 'g-463', 'g-465', 'g-467', 'g-470', 'g-473', 'g-474', 'g-475', 'g-476', 'g-481', 'g-483', 'g-485', 'g-486', 'g-489', 'g-490', 'g-495', 'g-500', 'g-501', 'g-502', 'g-504', 'g-509', 'g-513', 'g-516', 'g-517', 'g-518', 'g-527', 'g-531', 'g-535', 'g-540', 'g-542', 'g-543', 'g-544', 'g-547', 'g-548', 'g-549', 'g-552', 'g-556', 'g-558', 'g-562', 'g-566', 'g-571', 'g-572', 'g-573', 'g-574', 'g-578', 'g-584', 'g-585', 'g-590', 'g-592', 'g-595', 'g-596', 'g-599', 'g-600', 'g-601', 'g-602', 'g-603', 'g-604', 'g-605', 'g-606', 'g-607', 'g-608', 'g-609', 'g-610', 'g-611', 'g-612', 'g-613', 'g-614', 'g-615', 'g-616', 'g-617', 'g-618', 'g-619', 'g-620', 'g-621', 'g-622', 'g-623', 'g-624', 'g-625', 'g-626', 'g-627', 'g-628', 'g-629', 'g-630', 'g-631', 'g-632', 'g-633', 'g-634', 'g-635', 'g-636', 'g-637', 'g-638', 'g-639', 'g-640', 'g-643', 'g-645', 'g-646', 'g-647', 'g-648', 'g-651', 'g-654', 'g-657', 'g-658', 'g-659', 'g-660', 'g-661', 'g-662', 'g-663', 'g-664', 'g-665', 'g-666', 'g-668', 'g-670', 'g-672', 'g-673', 'g-674', 'g-675', 'g-676', 'g-677', 'g-678', 'g-679', 'g-680', 'g-685', 'g-688', 'g-689', 'g-690', 'g-691', 'g-695', 'g-697', 'g-698', 'g-699', 'g-700', 'g-701', 'g-702', 'g-703', 'g-704', 'g-707', 'g-708', 'g-709', 'g-710', 'g-711', 'g-712', 'g-713', 'g-714', 'g-715', 'g-716', 'g-717', 'g-718', 'g-719', 'g-720', 'g-721', 'g-722', 'g-723', 'g-724', 'g-725', 'g-726', 'g-728', 'g-729', 'g-730', 'g-731', 'g-732', 'g-733', 'g-734', 'g-736', 'g-737', 'g-739', 'g-740', 'g-742', 'g-743', 'g-744', 'g-745', 'g-747', 'g-748', 'g-749', 'g-750', 'g-751', 'g-752', 'g-753', 'g-756', 'g-757', 'g-758', 'g-759', 'g-760', 'g-761', 'g-762', 'g-763', 'g-764', 'g-766', 'g-767', 'g-768', 'g-769', 'g-770', 'g-771', 'c-0', 'c-1', 'c-2', 'c-3', 'c-4', 'c-5', 'c-10', 'c-11', 'c-12', 'c-13', 'c-14', 'c-15', 'c-16', 'c-17', 'c-18', 'c-19', 'c-20', 'c-21', 'c-22', 'c-23', 'c-24', 'c-25', 'c-26', 'c-27', 'c-32', 'c-35', 'c-36', 'c-37', 'c-40', 'c-43', 'c-47', 'c-48', 'c-52', 'c-53', 'c-54', 'c-55', 'c-56', 'c-57', 'c-58', 'c-61', 'c-62', 'c-63', 'c-64', 'c-65', 'c-66', 'c-67', 'c-68', 'c-69', 'c-70', 'c-71', 'c-72', 'c-73', 'c-74', 'c-75', 'c-76', 'c-77', 'c-78', 'c-79', 'c-80', 'c-81', 'c-82', 'c-83', 'c-84', 'c-85', 'c-86', 'c-87', 'c-88', 'c-89', 'c-90', 'c-91', 'c-92', 'c-93', 'c-94', 'c-97']
}
imp_df.sort_values(by="importance_gain",ascending=False)[:150]<save_to_csv>
options['700'] = {
'features': ['g-0', 'g-1', 'g-2', 'g-3', 'g-4', 'g-5', 'g-6', 'g-7', 'g-8', 'g-9', 'g-10', 'g-11', 'g-12', 'g-13', 'g-14', 'g-15', 'g-16', 'g-17', 'g-18', 'g-19', 'g-20', 'g-21', 'g-22', 'g-23', 'g-24', 'g-25', 'g-26', 'g-27', 'g-28', 'g-29', 'g-30', 'g-31', 'g-32', 'g-33', 'g-34', 'g-35', 'g-36', 'g-37', 'g-38', 'g-39', 'g-40', 'g-41', 'g-42', 'g-43', 'g-44', 'g-45', 'g-46', 'g-47', 'g-48', 'g-49', 'g-50', 'g-51', 'g-52', 'g-53', 'g-54', 'g-55', 'g-56', 'g-57', 'g-58', 'g-59', 'g-60', 'g-61', 'g-62', 'g-63', 'g-64', 'g-65', 'g-66', 'g-67', 'g-68', 'g-69', 'g-70', 'g-71', 'g-72', 'g-73', 'g-74', 'g-75', 'g-76', 'g-77', 'g-78', 'g-79', 'g-80', 'g-81', 'g-82', 'g-83', 'g-84', 'g-85', 'g-86', 'g-87', 'g-88', 'g-89', 'g-90', 'g-91', 'g-92', 'g-93', 'g-94', 'g-95', 'g-96', 'g-97', 'g-98', 'g-99', 'g-100', 'g-101', 'g-102', 'g-103', 'g-104', 'g-105', 'g-106', 'g-107', 'g-108', 'g-109', 'g-110', 'g-111', 'g-112', 'g-113', 'g-114', 'g-115', 'g-116', 'g-117', 'g-118', 'g-119', 'g-120', 'g-121', 'g-122', 'g-123', 'g-124', 'g-125', 'g-126', 'g-127', 'g-128', 'g-129', 'g-130', 'g-131', 'g-132', 'g-133', 'g-134', 'g-135', 'g-136', 'g-137', 'g-138', 'g-139', 'g-140', 'g-141', 'g-142', 'g-143', 'g-144', 'g-145', 'g-146', 'g-147', 'g-148', 'g-149', 'g-150', 'g-151', 'g-152', 'g-153', 'g-154', 'g-155', 'g-156', 'g-157', 'g-158', 'g-159', 'g-160', 'g-161', 'g-162', 'g-163', 'g-164', 'g-165', 'g-166', 'g-167', 'g-168', 'g-169', 'g-170', 'g-171', 'g-172', 'g-173', 'g-174', 'g-175', 'g-176', 'g-177', 'g-178', 'g-179', 'g-180', 'g-181', 'g-182', 'g-183', 'g-184', 'g-185', 'g-186', 'g-187', 'g-188', 'g-189', 'g-190', 'g-191', 'g-192', 'g-193', 'g-194', 'g-195', 'g-196', 'g-197', 'g-198', 'g-199', 'g-200', 'g-201', 'g-202', 'g-203', 'g-204', 'g-205', 'g-206', 'g-207', 'g-208', 'g-209', 'g-210', 'g-211', 'g-212', 'g-213', 'g-214', 'g-215', 'g-216', 'g-217', 'g-218', 'g-219', 'g-220', 'g-221', 'g-222', 'g-223', 'g-224', 'g-225', 'g-226', 'g-227', 'g-228', 'g-229', 'g-230', 'g-231', 'g-232', 'g-233', 'g-234', 'g-235', 'g-236', 'g-237', 'g-238', 'g-239', 'g-240', 'g-241', 'g-242', 'g-243', 'g-244', 'g-245', 'g-246', 'g-247', 'g-248', 'g-249', 'g-250', 'g-251', 'g-252', 'g-253', 'g-254', 'g-255', 'g-256', 'g-257', 'g-258', 'g-259', 'g-260', 'g-261', 'g-262', 'g-263', 'g-264', 'g-265', 'g-266', 'g-267', 'g-268', 'g-269', 'g-270', 'g-271', 'g-272', 'g-273', 'g-274', 'g-275', 'g-279', 'g-282', 'g-284', 'g-285', 'g-286', 'g-287', 'g-288', 'g-289', 'g-290', 'g-291', 'g-292', 'g-293', 'g-294', 'g-295', 'g-296', 'g-297', 'g-298', 'g-299', 'g-300', 'g-301', 'g-302', 'g-303', 'g-304', 'g-305', 'g-306', 'g-307', 'g-310', 'g-311', 'g-312', 'g-314', 'g-316', 'g-317', 'g-318', 'g-319', 'g-320', 'g-321', 'g-322', 'g-323', 'g-324', 'g-325', 'g-326', 'g-327', 'g-328', 'g-332', 'g-333', 'g-335', 'g-339', 'g-340', 'g-341', 'g-342', 'g-343', 'g-344', 'g-345', 'g-346', 'g-347', 'g-348', 'g-349', 'g-350', 'g-351', 'g-352', 'g-353', 'g-354', 'g-355', 'g-357', 'g-360', 'g-364', 'g-365', 'g-370', 'g-375', 'g-383', 'g-385', 'g-388', 'g-389', 'g-390', 'g-391', 'g-392', 'g-399', 'g-401', 'g-402', 'g-403', 'g-404', 'g-405', 'g-406', 'g-407', 'g-409', 'g-417', 'g-423', 'g-424', 'g-425', 'g-426', 'g-428', 'g-429', 'g-430', 'g-431', 'g-433', 'g-434', 'g-435', 'g-436', 'g-438', 'g-439', 'g-440', 'g-441', 'g-443', 'g-444', 'g-445', 'g-446', 'g-447', 'g-448', 'g-449', 'g-450', 'g-451', 'g-452', 'g-453', 'g-454', 'g-455', 'g-456', 'g-460', 'g-461', 'g-463', 'g-465', 'g-467', 'g-470', 'g-473', 'g-474', 'g-475', 'g-476', 'g-481', 'g-483', 'g-485', 'g-486', 'g-489', 'g-490', 'g-495', 'g-500', 'g-501', 'g-502', 'g-504', 'g-509', 'g-513', 'g-516', 'g-517', 'g-518', 'g-527', 'g-531', 'g-535', 'g-540', 'g-542', 'g-543', 'g-544', 'g-547', 'g-548', 'g-549', 'g-552', 'g-556', 'g-558', 'g-562', 'g-566', 'g-571', 'g-572', 'g-573', 'g-574', 'g-578', 'g-584', 'g-585', 'g-590', 'g-592', 'g-595', 'g-596', 'g-599', 'g-600', 'g-601', 'g-602', 'g-603', 'g-604', 'g-605', 'g-606', 'g-607', 'g-608', 'g-609', 'g-610', 'g-611', 'g-612', 'g-613', 'g-614', 'g-615', 'g-616', 'g-617', 'g-618', 'g-619', 'g-620', 'g-621', 'g-622', 'g-623', 'g-624', 'g-625', 'g-626', 'g-627', 'g-628', 'g-629', 'g-630', 'g-631', 'g-632', 'g-633', 'g-634', 'g-635', 'g-636', 'g-637', 'g-638', 'g-639', 'g-640', 'g-641', 'g-642', 'g-643', 'g-644', 'g-645', 'g-646', 'g-647', 'g-648', 'g-649', 'g-650', 'g-651', 'g-652', 'g-654', 'g-655', 'g-656', 'g-657', 'g-658', 'g-659', 'g-660', 'g-661', 'g-662', 'g-663', 'g-664', 'g-665', 'g-666', 'g-667', 'g-668', 'g-670', 'g-672', 'g-673', 'g-674', 'g-675', 'g-676', 'g-677', 'g-678', 'g-679', 'g-680', 'g-685', 'g-687', 'g-688', 'g-689', 'g-690', 'g-691', 'g-692', 'g-695', 'g-697', 'g-698', 'g-699', 'g-700', 'g-701', 'g-702', 'g-703', 'g-704', 'g-705', 'g-706', 'g-707', 'g-708', 'g-709', 'g-710', 'g-711', 'g-712', 'g-713', 'g-714', 'g-715', 'g-716', 'g-717', 'g-718', 'g-719', 'g-720', 'g-721', 'g-722', 'g-723', 'g-724', 'g-725', 'g-726', 'g-727', 'g-728', 'g-729', 'g-730', 'g-731', 'g-732', 'g-733', 'g-734', 'g-735', 'g-736', 'g-737', 'g-738', 'g-739', 'g-740', 'g-741', 'g-742', 'g-743', 'g-744', 'g-745', 'g-746', 'g-747', 'g-748', 'g-749', 'g-750', 'g-751', 'g-752', 'g-753', 'g-754', 'g-755', 'g-756', 'g-757', 'g-758', 'g-759', 'g-760', 'g-761', 'g-762', 'g-763', 'g-764', 'g-765', 'g-766', 'g-767', 'g-768', 'g-769', 'g-770', 'g-771', 'c-0', 'c-1', 'c-2', 'c-3', 'c-4', 'c-5', 'c-6', 'c-7', 'c-10', 'c-11', 'c-12', 'c-13', 'c-14', 'c-15', 'c-16', 'c-17', 'c-18', 'c-19', 'c-20', 'c-21', 'c-22', 'c-23', 'c-24', 'c-25', 'c-26', 'c-27', 'c-28', 'c-29', 'c-30', 'c-31', 'c-32', 'c-33', 'c-34', 'c-35', 'c-36', 'c-37', 'c-40', 'c-41', 'c-42', 'c-43', 'c-44', 'c-45', 'c-46', 'c-47', 'c-48', 'c-49', 'c-50', 'c-51', 'c-52', 'c-53', 'c-54', 'c-55', 'c-56', 'c-57', 'c-58', 'c-59', 'c-60', 'c-61', 'c-62', 'c-63', 'c-64', 'c-65', 'c-66', 'c-67', 'c-68', 'c-69', 'c-70', 'c-71', 'c-72', 'c-73', 'c-74', 'c-75', 'c-76', 'c-77', 'c-78', 'c-79', 'c-80', 'c-81', 'c-82', 'c-83', 'c-84', 'c-85', 'c-86', 'c-87', 'c-88', 'c-89', 'c-90', 'c-91', 'c-92', 'c-93', 'c-94', 'c-95', 'c-96', 'c-97']
}
sub_df = pd.DataFrame({"ID_code": test_df.ID_code.values})
 sub_df["target"] = predictions
sub_df.to_csv("sant_lgb.csv", index=False)
 sub_df[:10]<feature_engineering>
import tensorflow as tf
import tensorflow_addons as tfa
from sklearn.model_selection import StratifiedKFold, KFold
from sklearn.metrics import accuracy_score
import tensorflow.keras.backend as K
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
random.seed(1234)
 warnings.filterwarnings('ignore')
 class StackingEstimator(BaseEstimator, TransformerMixin):
def __init__(self, estimator):
self.estimator = estimator
def fit(self, X, y=None, **fit_params):
self.estimator.fit(X, y, **fit_params)
 return self
def transform(self, X):
X = check_array(X)
 X_transformed = np.copy(X)
 if issubclass(self.estimator.__class__, ClassifierMixin)and hasattr(self.estimator, 'predict_proba'):
X_transformed = np.hstack(( self.estimator.predict_proba(X), X))
X_transformed = np.hstack(( np.reshape(self.estimator.predict(X),(-1, 1)) , X_transformed))
return X_transformed
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 class GaussRankScaler() :
def __init__(self):
self.epsilon = 1e-9
self.lower = -1 + self.epsilon
self.upper = 1 - self.epsilon
self.range = self.upper - self.lower
def fit_transform(self, X):
i = np.argsort(X, axis = 0)
 j = np.argsort(i, axis = 0)
 assert(j.min() == 0 ).all()
assert(j.max() == len(j)- 1 ).all()
j_range = len(j)- 1
self.divider = j_range / self.range
transformed = j / self.divider
transformed = transformed - self.upper
transformed = scipy.special.erfinv(transformed)
 return transformed
target_col='target'
id_col='ID_code'
submission = pd.read_csv('.. /input/sample_submission.csv')
 id_test = submission[id_col].values
def neural_compression_v2(train, test):
dataset = pd.concat([train.drop(target_col, axis=1), test], axis=0)
 ids = dataset[id_col]
dataset.drop(id_col, axis=1, inplace=True)
 y_train = train[target_col]
cat_vars = [c for c in dataset.columns if dataset[c].dtype == 'object']
for c in cat_vars:
t_data = pd.get_dummies(dataset[c], prefix=c)
 dataset = pd.concat([dataset, t_data], axis=1)
 dataset.drop(cat_vars, axis=1, inplace=True)
 sc = StandardScaler()
sc.fit_transform(dataset)
 dataset = sc.fit_transform(dataset)
 train = dataset[:train.shape[0]]
test = dataset[train.shape[0]:]
print("one hot encoded train shape :: {}".format(train.shape))
print("one hot encoded test shape :: {}".format(test.shape))

 train = train + 0.5 * np.random.normal(loc=0.0, scale=1.0, size=train.shape)
 test = test + 0.5 * np.random.normal(loc=0.0, scale=1.0, size=test.shape)
 l2_reg_embedding = 1e-5
print(keras.__version__)
 init_dim = train.shape[1]
input_row = Input(shape=(init_dim,))
encoded = Dense(512, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(input_row)
 encoded = Dropout(0.2 )(encoded)
 encoded=BatchNormalization()(encoded)
 encoded = Dense(256, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(encoded)
 encoded = Dropout(0.2 )(encoded)
 encoded = Dense(128, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(encoded)
 encoded = Dropout(0.2 )(encoded)
 encoded = Dense(64, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(encoded)
 encoded = Dropout(0.2 )(encoded)
 encoded = Dense(32, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(encoded)
 encoded = Dense(16, activation='elu' )(encoded)
 decoded = Dense(32, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(encoded)
 encoded = Dropout(0.2 )(encoded)
 decoded = Dense(64, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(decoded)
 encoded = Dropout(0.2 )(encoded)
 decoded = Dense(128, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(decoded)
 encoded = Dropout(0.2 )(encoded)
 decoded = Dense(256, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(decoded)
 encoded = Dropout(0.2 )(encoded)
 encoded = BatchNormalization()(encoded)
 decoded = Dense(512, activation='elu',kernel_regularizer=l2(l2_reg_embedding))(decoded)
 decoded = Dense(init_dim, activation='sigmoid' )(decoded)
 autoencoder = Model(inputs=input_row, outputs=decoded)
 autoencoder.compile(optimizer='rmsprop', loss='binary_crossentropy')
 autoencoder.fit(train, train,
batch_size=512,verbose=2,
shuffle=True, validation_data=(test, test), epochs=4)
 encoder = Model(inputs=input_row, outputs=encoded)
 train_compress = encoder.predict(train,batch_size=4048)
 test_compress = encoder.predict(test,batch_size=4048)
 denoised_train = autoencoder.predict(train,batch_size=4048)
 denoised_test = autoencoder.predict(test,batch_size=4048)
 return train_compress, test_compress, denoised_train, denoised_test
train_compress, test_compress, denoised_train, denoised_test = neural_compression_v2(train, test)
 for c in train.columns:
if train[c].dtype == 'object':
lbl = LabelEncoder()
lbl.fit(list(train[c].values)+ list(test[c].values))
train[c] = lbl.transform(list(train[c].values))
test[c] = lbl.transform(list(test[c].values))
n_comp = 12
tsvd = TruncatedSVD(n_components=n_comp, random_state=420)
 tsvd_results_train = tsvd.fit_transform(train.drop([target_col], axis=1))
tsvd_results_test = tsvd.transform(test)
 pca = PCA(n_components=n_comp, random_state=420)
 pca2_results_train = pca.fit_transform(train.drop([target_col], axis=1))
pca2_results_test = pca.transform(test)
 ica = FastICA(n_components=n_comp, random_state=420)
 ica2_results_train = ica.fit_transform(train.drop([target_col], axis=1))
ica2_results_test = ica.transform(test)
 grp = GaussianRandomProjection(n_components=n_comp, eps=0.1, random_state=420)
 grp_results_train = grp.fit_transform(train.drop([target_col], axis=1))
grp_results_test = grp.transform(test)
 srp = SparseRandomProjection(n_components=n_comp, dense_output=True, random_state=420)
 srp_results_train = srp.fit_transform(train.drop([target_col], axis=1))
srp_results_test = srp.transform(test)
 fag = FeatureAgglomeration(n_clusters=n_comp, linkage='ward')
 fag_results_train = fag.fit_transform(train.drop([target_col], axis=1))
fag_results_test = fag.transform(test)
 usable_columns = list(set(train.columns)- set([target_col]))
for i in range(1, n_comp + 1):
train['pca_' + str(i)] = pca2_results_train[:, i - 1]
test['pca_' + str(i)] = pca2_results_test[:, i - 1]
train['ica_' + str(i)] = ica2_results_train[:, i - 1]
test['ica_' + str(i)] = ica2_results_test[:, i - 1]
train['tsvd_' + str(i)] = tsvd_results_train[:, i - 1]
test['tsvd_' + str(i)] = tsvd_results_test[:, i - 1]
train['grp_' + str(i)] = grp_results_train[:, i - 1]
test['grp_' + str(i)] = grp_results_test[:, i - 1]
train['srp_' + str(i)] = srp_results_train[:, i - 1]
test['srp_' + str(i)] = srp_results_test[:, i - 1]
for j in range(1, train_compress.shape[1]):
train['aen_' + str(j)] = denoised_train[:, j-1]
test['aen_' + str(j)] = denoised_test[:, j-1]
y = train[target_col].values
finaltrainset = train[usable_columns].values
finaltestset = test[usable_columns].values
X=train.drop(target_col, axis=1)
<init_hyperparams>
def make_layer(x, units, dropout_rate):
t = tfa.layers.WeightNormalization(tf.keras.layers.Dense(units))(x)
 t = tf.keras.layers.BatchNormalization()(t)
 t = tf.keras.layers.Activation('relu' )(t)
 t = tf.keras.layers.Dropout(dropout_rate )(t)
 return t
def make_model(data, units, dropout_rates):
inputs = tf.keras.layers.Input(shape=(data.shape[1],))
x = tf.keras.layers.BatchNormalization()(inputs)
 for i in range(len(units)) :
u = units[i]
d = dropout_rates[i]
x = make_layer(x, u, d)
 y = tf.keras.layers.Dense(206, activation='sigmoid', name='dense_output' )(x)
 model = tf.keras.Model(inputs=inputs, outputs=y)
 model.compile(loss='binary_crossentropy',
optimizer=tfa.optimizers.AdamW(learning_rate=1e-3, weight_decay=1e-5),
metrics=['accuracy'])
 return model
DEVICE = "TPU"
CFG = dict(
 net_count = 7,
batch_size = 16,
read_size = 256,
crop_size = 250,
net_size = 384,
LR_START = 0.000005,
LR_MAX = 0.000020,
LR_MIN = 0.000001,
LR_RAMPUP_EPOCHS = 5,
LR_SUSTAIN_EPOCHS = 0,
LR_EXP_DECAY = 0.8,
epochs = 13,
rot = 180.0,
shr = 2.0,
hzoom = 8.0,
wzoom = 8.0,
hshift = 8.0,
wshift = 8.0,
optimizer = 'adam',
label_smooth_fac = 0.05,
tta_steps = 25
)<install_modules>
def fit_predict(n_splits, x_train, y_train, units, dropout_rates, epochs, x_test, verbose, random_state):
histories = []
scores = []
y_preds = []
cv = KFold(n_splits=n_splits, shuffle=True, random_state=random_state)
 for train_idx, valid_idx in cv.split(x_train, y_train):
x_train_train = x_train.iloc[train_idx]
y_train_train = y_train.iloc[train_idx]
x_train_valid = x_train.iloc[valid_idx]
y_train_valid = y_train.iloc[valid_idx]
K.clear_session()
estimator = make_model(x_train, units, dropout_rates)
 es = tf.keras.callbacks.EarlyStopping(monitor='val_loss', min_delta=0.0001, patience=10,
verbose=verbose, mode='min', restore_best_weights=True)
 rl = tf.keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, min_lr=1e-5,
mode='min', verbose=verbose)
 history = estimator.fit(x_train_train, y_train_train,
batch_size=128, epochs=epochs, callbacks=[es, rl],
validation_data=(x_train_valid, y_train_valid),
verbose=verbose)
 if x_test is not None:
y_part = estimator.predict(x_test)
 y_preds.append(y_part)
 histories.append(history)
 scores.append(history.history['val_loss'][-1])
 if x_test is not None:
y_pred = np.mean(y_preds, axis=0)
 else:
y_pred = None
score = np.mean(scores)
 return y_pred, histories, score
!pip install -q efficientnet<feature_engineering>
optuna.logging.set_verbosity(CRITICAL )
seed=123
random.seed(seed)
 np.random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 tf.random.set_seed(seed)
<load_from_csv>
def objective(trial):
n_layers = trial.suggest_int('n_layers', 1, 5)
 units = []
dropout_rates = []
for i in range(n_layers):
u = trial.suggest_categorical('units_{}'.format(i+1), [1024, 512, 256, 128])
 units.append(u)
 r = trial.suggest_loguniform('dropout_rate_{}'.format(i+1), 0.1, 0.5)
 dropout_rates.append(r)
 print('Units:', units, "Dropout rates:", dropout_rates)
 _, _, score = fit_predict(3, x_train, y_train, units, dropout_rates, 25, None, 0, 42)
 return score
BASEPATH = ".. /input/siim-isic-melanoma-classification"
df_train = pd.read_csv(os.path.join(BASEPATH, 'train.csv'))
df_test = pd.read_csv(os.path.join(BASEPATH, 'test.csv'))
df_sub = pd.read_csv(os.path.join(BASEPATH, 'sample_submission.csv'))
GCS_PATH = KaggleDatasets().get_gcs_path('melanoma-256x256')
 files_train = np.sort(np.array(tf.io.gfile.glob(GCS_PATH + '/train*.tfrec')))
 files_test = np.sort(np.array(tf.io.gfile.glob(GCS_PATH + '/test*.tfrec')) )<choose_model_class>
params = {
'n_layers': 5,
'units_1': 128,
'units_2': 256,
'units_3': 512,
'units_4': 256,
'units_5': 1024,
'dropout_rate_1': 0.3478936880741539,
'dropout_rate_2': 0.3478936880741539,
'dropout_rate_3': 0.3478936880741539,
'dropout_rate_4': 0.3478936880741539,
'dropout_rate_5': 0.3478936880741539
}
options['default']['params'] = params
if DEVICE == "TPU":
print("connecting to TPU...")
 try:
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
print('Running on TPU ', tpu.master())
 except ValueError:
print("Could not connect to TPU")
 tpu = None
if tpu:
try:
print("initializing TPU...")
 tf.config.experimental_connect_to_cluster(tpu)
 tf.tpu.experimental.initialize_tpu_system(tpu)
 strategy = tf.distribute.experimental.TPUStrategy(tpu)
 print("TPU initialized")
 except _:
print("failed to initialize TPU")
 else:
DEVICE = "GPU"
if DEVICE != "TPU":
print("Using default strategy for CPU and single GPU")
 strategy = tf.distribute.get_strategy()
if DEVICE == "GPU":
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
 AUTO = tf.data.experimental.AUTOTUNE
REPLICAS = strategy.num_replicas_in_sync
print(f'REPLICAS: {REPLICAS}' )<normalization>
params = {
'n_layers': 3,
'units_1': 1024,
'units_2': 512,
'units_3': 256,
'dropout_rate_1': 0.4501813451502177,
'dropout_rate_2': 0.4501813451502177,
'dropout_rate_3': 0.4501813451502177
}
options['500']['params'] = params
options['600']['params'] = params
options['700']['params'] = params
def get_mat(rotation, shear, height_zoom, width_zoom, height_shift, width_shift):
rotation = math.pi * rotation / 180.
 shear = math.pi * shear / 180.
 def get_3x3_mat(lst):
return tf.reshape(tf.concat([lst],axis=0), [3,3])
 c1 = tf.math.cos(rotation)
 s1 = tf.math.sin(rotation)
 one = tf.constant([1],dtype='float32')
 zero = tf.constant([0],dtype='float32')
 rotation_matrix = get_3x3_mat([c1, s1, zero,
-s1, c1, zero,
zero, zero, one])
 c2 = tf.math.cos(shear)
 s2 = tf.math.sin(shear)
 shear_matrix = get_3x3_mat([one, s2, zero,
zero, c2, zero,
zero, zero, one])
 zoom_matrix = get_3x3_mat([one/height_zoom, zero, zero,
zero, one/width_zoom, zero,
zero, zero, one])
 shift_matrix = get_3x3_mat([one, zero, height_shift,
zero, one, width_shift,
zero, zero, one])
 return K.dot(K.dot(rotation_matrix, shear_matrix),
K.dot(zoom_matrix, shift_matrix))
def transform(image, cfg):
DIM = cfg["read_size"]
XDIM = DIM%2
rot = cfg['rot'] * tf.random.normal([1], dtype='float32')
 shr = cfg['shr'] * tf.random.normal([1], dtype='float32')
 h_zoom = 1.0 + tf.random.normal([1], dtype='float32')/ cfg['hzoom']
w_zoom = 1.0 + tf.random.normal([1], dtype='float32')/ cfg['wzoom']
h_shift = cfg['hshift'] * tf.random.normal([1], dtype='float32')
 w_shift = cfg['wshift'] * tf.random.normal([1], dtype='float32')
 m = get_mat(rot,shr,h_zoom,w_zoom,h_shift,w_shift)
 x = tf.repeat(tf.range(DIM//2, -DIM//2,-1), DIM)
 y = tf.tile(tf.range(-DIM//2, DIM//2), [DIM])
 z = tf.ones([DIM*DIM], dtype='int32')
 idx = tf.stack([x,y,z])
 idx2 = K.dot(m, tf.cast(idx, dtype='float32'))
idx2 = K.cast(idx2, dtype='int32')
 idx2 = K.clip(idx2, -DIM//2+XDIM+1, DIM//2)
 idx3 = tf.stack([DIM//2-idx2[0,], DIM//2-1+idx2[1,]])
 d = tf.gather_nd(image, tf.transpose(idx3))
return tf.reshape(d,[DIM, DIM,3] )<prepare_x_and_y>
def fit_predict_option(option, random_state):
print('Option:', option)
 params = options[option]['params']
n_layers = params['n_layers']
units = []
dropout_rates = []
for i in range(n_layers):
u = params['units_{}'.format(i+1)]
units.append(u)
 d = params['dropout_rate_{}'.format(i+1)]
dropout_rates.append(d)
 x_train_option, x_test_option = make_x(option)
 y_pred, histories, score = fit_predict(7, x_train_option, y_train, units, dropout_rates, 100, x_test_option, 2, random_state)
 print('Score:', score)
 return y_pred, histories, score
def read_labeled_tfrecord(example):
tfrec_format = {
'image' : tf.io.FixedLenFeature([], tf.string),
'image_name' : tf.io.FixedLenFeature([], tf.string),
'patient_id' : tf.io.FixedLenFeature([], tf.int64),
'sex' : tf.io.FixedLenFeature([], tf.int64),
'age_approx' : tf.io.FixedLenFeature([], tf.int64),
'anatom_site_general_challenge': tf.io.FixedLenFeature([], tf.int64),
'diagnosis' : tf.io.FixedLenFeature([], tf.int64),
'target' : tf.io.FixedLenFeature([], tf.int64)
 }
example = tf.io.parse_single_example(example, tfrec_format)
 return example['image'], example['target']
def read_unlabeled_tfrecord(example, return_image_name):
tfrec_format = {
'image' : tf.io.FixedLenFeature([], tf.string),
'image_name' : tf.io.FixedLenFeature([], tf.string),
}
example = tf.io.parse_single_example(example, tfrec_format)
 return example['image'], example['image_name'] if return_image_name else 0
def prepare_image(img, cfg=None, augment=True):
img = tf.image.decode_jpeg(img, channels=3)
 img = tf.image.resize(img, [cfg['read_size'], cfg['read_size']])
 img = tf.cast(img, tf.float32)/ 255.0
if augment:
img = transform(img, cfg)
 img = tf.image.random_crop(img, [cfg['crop_size'], cfg['crop_size'], 3])
 img = tf.image.random_flip_left_right(img)
 img = tf.image.random_hue(img, 0.01)
 img = tf.image.random_saturation(img, 0.7, 1.3)
 img = tf.image.random_contrast(img, 0.8, 1.2)
 img = tf.image.random_brightness(img, 0.1)
 else:
img = tf.image.central_crop(img, cfg['crop_size'] / cfg['read_size'])
 img = tf.image.resize(img, [cfg['net_size'], cfg['net_size']])
 img = tf.reshape(img, [cfg['net_size'], cfg['net_size'], 3])
 return img
def count_data_items(filenames):
n = [int(re.compile(r"-([0-9]*)\." ).search(filename ).group(1))
for filename in filenames]
return np.sum(n )<categorify>
y_preds = []
for option in options:
y_pred, histories, score = fit_predict_option(option, 42)
 y_preds.append(y_pred)
<prepare_x_and_y><EOS> 
submission = pd.read_csv('/kaggle/input/lish-moa/sample_submission.csv')
 columns = list(submission.columns)
 columns.remove('sig_id')
 for i in range(len(columns)) :
submission[columns[i]] = y_pred[:,i]
submission.to_csv('submission.csv', index=False )