Kaggle competition: COVID19 Global Forecasting (Week 2)
def save_importances(importances_):
mean_gain = importances_[['gain', 'feature']].groupby('feature' ).mean()
importances_['mean_gain'] = importances_['feature'].map(mean_gain['gain'])
 return importances_<train_model>
import scipy.optimize as opt
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
from tqdm import tqdm_notebook
from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_squared_log_error
import warnings; warnings.filterwarnings('ignore' )
def smoteAdataset(Xig_train, yig_train, Xig_test, yig_test):
sm=SMOTE(random_state=2)
 Xig_train_res, yig_train_res = sm.fit_sample(Xig_train, yig_train.ravel())
 return Xig_train_res, pd.Series(yig_train_res), Xig_test, pd.Series(yig_test )<compute_train_metric>
train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/train.csv')
 train['Date'] = pd.to_datetime(train['Date'])
 first_test_date = np.datetime64('2020-03-19')
 last_train_date = np.datetime64('2020-03-31')
 eval_set = train[train['Date'] > first_test_date]
overlap_days = last_train_date - first_test_date
overlap_days = int(overlap_days.astype('timedelta64[D]')/ np.timedelta64(1, 'D'))
train = train[train['Date'] <= last_train_date]
train
def lgbm_modeling_cross_validation(params,
full_train,
y,
classes,
class_weights,
nr_fold=12,
random_state=1):
w = y.value_counts()
weights = {i : np.sum(w)/ w[i] for i in w.index}
clfs = []
importances = pd.DataFrame()
folds = StratifiedKFold(n_splits=nr_fold,
shuffle=True,
random_state=random_state)
 oof_preds = np.zeros(( len(full_train), np.unique(y ).shape[0]))
for fold_,(trn_, val_)in enumerate(folds.split(y, y)) :
trn_x, trn_y = full_train.iloc[trn_], y.iloc[trn_]
val_x, val_y = full_train.iloc[val_], y.iloc[val_]
trn_xa, trn_y, val_xa, val_y=smoteAdataset(trn_x.values, trn_y.values, val_x.values, val_y.values)
 trn_x=pd.DataFrame(data=trn_xa, columns=trn_x.columns)
 val_x=pd.DataFrame(data=val_xa, columns=val_x.columns)
 clf = LGBMClassifier(**params)
 clf.fit(
 trn_x, trn_y,
eval_set=[(trn_x, trn_y),(val_x, val_y)],
eval_metric=lgbm_multi_weighted_logloss,
verbose=100,
early_stopping_rounds=50,
sample_weight=trn_y.map(weights)
)
 clfs.append(clf)
 oof_preds[val_, :] = clf.predict_proba(val_x, num_iteration=clf.best_iteration_)
 print('no {}-fold loss: {}'.format(fold_ + 1,
multi_weighted_logloss(val_y, oof_preds[val_, :],
classes, class_weights)))
 imp_df = pd.DataFrame({
'feature': full_train.columns,
'gain': clf.feature_importances_,
'fold': [fold_ + 1] * len(full_train.columns),
})
 importances = pd.concat([importances, imp_df], axis=0, sort=False)
 score = multi_weighted_logloss(y_true=y, y_preds=oof_preds,
classes=classes, class_weights=class_weights)
 print('MULTI WEIGHTED LOG LOSS: {:.5f}'.format(score))
df_importances = save_importances(importances_=importances)
 df_importances.to_csv('lgbm_importances.csv', index=False)
 return clfs, score<predict_on_test>
test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/test.csv')
 test['Date'] = pd.to_datetime(test['Date'])
 test
def predict_chunk(df_, clfs_, features, train_mean):
agg_ = df_
full_test = agg_.reset_index()
full_test = full_test.fillna(0)
 full_test = full_test.round(5)
 preds_ = None
for clf in clfs_:
if preds_ is None:
preds_ = clf.predict_proba(full_test[features])/ len(clfs_)
 else:
preds_ += clf.predict_proba(full_test[features])/ len(clfs_)
 preds_99 = np.ones(preds_.shape[0])
 for i in range(preds_.shape[1]):
preds_99 *=(1 - preds_[:, i])
 preds_df_ = pd.DataFrame(preds_, columns=['class_' + str(s)for s in clfs_[0].classes_])
 preds_df_['object_id'] = full_test['object_id']
preds_df_['class_99'] = 0.14 * preds_99 / np.mean(preds_99)
 return preds_df_<save_to_csv>
sub = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-2/submission.csv')
 sub = sub.set_index('ForecastId', drop=True)
 sub
def process_test(clfs,
testdf,
full_train,
train_mean,
filename='submission.csv',
chunks=40615):
start = time.time()
chunks = 40615
testdf=testdf.round(5)
 testdf.to_csv(filename, index=False)
 for i_c, df in enumerate(pd.read_csv(filename, chunksize=chunks, iterator=True)) :
print(df.shape)
 preds_df = predict_chunk(df_=df,
clfs_=clfs,
features=full_train.columns,
train_mean=train_mean)
 if i_c == 0:
preds_df.to_csv('predictions.csv', header=True, mode='a', index=False)
 else:
preds_df.to_csv('predictions.csv', header=False, mode='a', index=False)
 del preds_df
gc.collect()
print('%15d done in %5.1f minutes' %(chunks *(i_c + 1),(time.time() - start)/ 60), flush=True)
 return<init_hyperparams>
def model(parameters, time):
y_pred = parameters[0] *(1 - np.exp(-parameters[1] *(time - parameters[3])))**parameters[2] + np.maximum(time*parameters[4], 0)
 return np.nan_to_num(y_pred ).clip(0, np.inf)
 def residual(parameters, time, data):
y_pred = model(parameters, time)
 return mean_squared_error(data, y_pred )
best_params = {
'device': 'cpu',
'objective': 'multiclass',
'num_class': 14,
'boosting_type': 'gbdt',
'n_jobs': -1,
'max_depth': 6,
'n_estimators': 1000,
'subsample_freq': 2,
'subsample_for_bin': 5000,
'min_data_per_group': 100,
'max_cat_to_onehot': 4,
'cat_l2': 1.0,
'cat_smooth': 59.5,
'max_cat_threshold': 32,
'metric_freq': 10,
'verbosity': -1,
'metric': 'multi_logloss',
'xgboost_dart_mode': False,
'uniform_drop': False,
'colsample_bytree': 0.5,
'drop_rate': 0.173,
'learning_rate': 0.025,
'max_drop': 5,
'min_child_samples': 10,
'min_child_weight': 200.0,
'min_split_gain': 0.01,
'num_leaves': 7,
'reg_alpha': 0.1,
'reg_lambda': 0.00023,
'skip_drop': 0.44,
'subsample': 0.75} 
<load_from_csv>
def fitModel(time, data, guess):
params = opt.minimize(residual, guess, args=(time, data), method='Nelder-Mead', tol=1e-7)
 return params.x
trainingDartDf=pd.read_csv('.. /input/writefeaturetablefromsmotedartset/trainingFeatures1039.csv')
 trainingJimsDf=pd.read_csv('.. /input/normalizesomethingdifferentfeatures/traindfNormal.csv')
 if 'Unnamed: 0' in trainingDartDf.columns:
trainingDartDf=trainingDartDf.drop('Unnamed: 0', axis=1)
 print(trainingDartDf.shape)
 columnsToAdd=['outlierScore', 'hipd', 'lipd', 'highEnergy_transitory_1.0_TF',
'highEnergy_transitory_1.5_TF', 'lowEnergy_transitory_1.0_TF',
'lowEnergy_transitory_1.5_TF']
for column in columnsToAdd:
trainingDartDf.loc[:,column]=trainingJimsDf.loc[:,column]
traindf=trainingDartDf
del traindf['hostgal_specz']
del traindf['ra'], traindf['decl'], traindf['gal_l'], traindf['gal_b']
del traindf['ddf']
print(traindf.shape)
 traindf.head()<load_from_csv>
model_params = trainModels(train )
testDartDf=pd.read_csv('.. /input/writefeaturetablefromsmotedartset/feat_0.648970_2018-11-23-09-00.csv')
 testJimsDf=pd.read_csv('.. /input/normalizesomethingdifferentfeatures/testdfNormal.csv')
 if 'Unnamed: 0' in testDartDf.columns:
testDartDf=testDartDf.drop('Unnamed: 0', axis=1)
 print(testDartDf.shape)
 testDartDf.head()
for column in columnsToAdd:
testDartDf.loc[:,column]=testJimsDf.loc[:,column]
testdf=testDartDf
del testdf['hostgal_specz']
del testdf['ra'], testdf['decl'], testdf['gal_l'], testdf['gal_b']
del testdf['ddf']
testdf.shape<train_model>
model_predictions = forecast(test, model_params, sub )
for cindex in full_train.columns:
full_train.loc[:,cindex]=np.float64(full_train.loc[:,cindex])
 eval_func = partial(lgbm_modeling_cross_validation,
full_train=full_train,
y=y,
classes=classes,
class_weights=class_weights,
nr_fold=12,
random_state=1)
 best_params.update({'n_estimators': 1000})
 clfs, score = eval_func(best_params )<save_to_csv>
identifier =('Taiwan*', None, 'ConfirmedCases')
 samples_train = train[(train['Country_Region'] == identifier[0])& train['Province_State'].isnull() ][identifier[2]]
samples_eval = eval_set[(eval_set['Country_Region'] == identifier[0])& eval_set['Province_State'].isnull() ][identifier[2]]
if identifier[1] is not None:
samples_train = train[(train['Country_Region'] == identifier[0])&(train['Province_State'] == identifier[1])][identifier[2]]
samples_eval = eval_set[(eval_set['Country_Region'] == identifier[0])&(eval_set['Province_State'] == identifier[1])][identifier[2]]
params = model_params[identifier]['params']
print(params)
 num_samples = model_params[identifier]['num_samples']
start_date = model_params[identifier]['start_date']
predictions = model_predictions[identifier]
plt.scatter(range(num_samples), samples_train)
 plt.scatter(range(num_samples-overlap_days, num_samples-overlap_days+len(samples_eval)) , samples_eval)
 plt.plot(range(start_date, num_samples + len(predictions)) , model(params, range(num_samples-start_date + len(predictions))))
filename = 'subm_{:.6f}_{}.csv'.format(score,
dt.now().strftime('%Y-%m-%d-%H-%M'))
print('save to {}'.format(filename))
process_test(clfs,
testdf,
full_train,
train_mean=train_mean,
filename=filename,
chunks=40615)
 pdf = pd.read_csv('predictions.csv')
 pdf.to_csv(filename, index=False )<set_options>
eval_with_id = pd.merge(eval_set, test, on=['Date', 'Country_Region', 'Province_State'])
 sub = sub.replace([np.inf, -np.inf], np.nan)
 sub = sub.fillna(0)
 merged_eval = pd.merge(eval_with_id, sub, left_on='ForecastId', right_index=True)
 merged_eval
COMPLETE_RUN = False
np.random.seed(1001)
 %matplotlib inline
matplotlib.style.use('ggplot' )<load_from_csv>
score_confirmed = np.sqrt(mean_squared_log_error(merged_eval['ConfirmedCases_x'].values, merged_eval['ConfirmedCases_y'].values))
score_fatality = np.sqrt(mean_squared_log_error(merged_eval['Fatalities_x'].values, merged_eval['Fatalities_y'].values))
print(f'Confirmed Cases Score: {score_confirmed}
Fatality Score: {score_fatality}
Average Score: {np.mean([score_confirmed, score_fatality])}' )
train = pd.read_csv(".. /input/freesound-audio-tagging/train.csv")
 test = pd.read_csv(".. /input/freesound-audio-tagging/sample_submission.csv" )<count_unique_values>
sub.to_csv('submission.csv')
 sub
print("Number of training examples=", train.shape[0], " Number of classes=", len(train.label.unique()))<count_values>
def p2f(x):
try:
return float(x.strip('%')) /100
except:
return None
def s2f(x):
try:
return float(x)
 except:
return None
pop_set = pd.read_csv('/kaggle/input/population-by-country-2020/population_by_country_2020.csv', converters={'Med.Age': s2f, 'Urban Pop %': p2f})
 pop_set.rename(columns={ pop_set.columns[0]: "Country" , pop_set.columns[1]: "Population" , pop_set.columns[4]: "Density", pop_set.columns[8]: 'Median Age', pop_set.columns[9]: "Urban Pop"}, inplace = True)
 pop_set = pop_set.iloc[:, [0, 1, 4, 8, 9]]
pop_set = pop_set.replace(regex={
'Czech Republic(Czechia)': 'Czechia',
"Côte d'Ivoire": "Cote d'Ivoire",
'St.Vincent & Grenadines': 'Saint Vincent and the Grenadines',
'Saint Kitts & Nevis': 'Saint Kitts and Nevis',
'Taiwan': 'Taiwan*',
'South Korea': 'Korea, South',
'United States': 'US'})
 pop_set
print('Minimum samples per category = ', min(train.label.value_counts()))
print('Maximum samples per category = ', max(train.label.value_counts()))<load_pretrained>
freedom_set = pd.read_csv('/kaggle/input/cato-2017-human-freedom-index/cato_2017_hfi_by_year_summary.csv')
 freedom_set = freedom_set[freedom_set['Year'] == 2015]
freedom_set.rename(columns={ freedom_set.columns[2]: "Country" , freedom_set.columns[3]: "Personal Freedom" , freedom_set.columns[4]: "Economic Freedom", freedom_set.columns[5]: 'Human Freedom'}, inplace = True)
 freedom_set = freedom_set.iloc[:, [2, 3, 4, 5]]
freedom_set = freedom_set.replace(regex={
'Czech Republic': 'Czechia',
'Taiwan': 'Taiwan*',
'Korea, Republic of': 'Korea, South',
'United States': 'US'})
 freedom_set
fname = '.. /input/freesound-audio-tagging/audio_train/' + '00044347.wav'
ipd.Audio(fname )<normalization>
country_set = pd.read_csv('/kaggle/input/countries-of-the-world/countries of the world.csv', decimal=",")
 country_set.rename(columns={ country_set.columns[7]: "Infant Mortality" , country_set.columns[8]: "GDP" , country_set.columns[9]: "Literacy"}, inplace = True)
 country_set = country_set.iloc[:, [0,7,8,9]]
country_set['Country'] = country_set['Country'].str.strip()
country_set = country_set.replace(regex={
'Czech Republic': 'Czechia',
'Taiwan': 'Taiwan*',
'Korea, Republic of': 'Korea, South',
'United States': 'US'})
 country_set
wav = wave.open(fname)
 print("Sampling(frame)rate = ", wav.getframerate())
 print("Total samples(frames)= ", wav.getnframes())
 print("Duration = ", wav.getnframes() /wav.getframerate() )<train_model>
def analyzeParams(model_params, index, measurement, external_set, external_column, threshold= 1000, label=False, xmin=None, xmax=None, ymin=None, ymax=None):
external_vals = []
params_vals = []
names = []
for identifier in model_params:
if identifier[0] not in ['US', 'China'] and identifier[2] == measurement and model_params[identifier]['max_value'] > threshold:
try:
val = external_set.loc[external_set['Country'] == identifier[0], external_column].values[0]
if np.isnan(val):
continue
external_vals.append(val)
 if identifier[1] is None:
names.append(identifier[0])
 else:
names.append(identifier[1] + ', ' + identifier[0])
 params = model_params[identifier]['params']
params_vals.append(params[index])
 except:
continue
R = np.corrcoef(external_vals, params_vals)
 plt.figure(figsize=(8, 6))
plt.scatter(external_vals, params_vals)
 plt.xlim(xmin, xmax)
 plt.ylim(ymin, ymax)
 plt.title("Correlation R = " + str(R[0, 1]))
if label:
for i, name in enumerate(names):
if(xmax is None or external_vals[i] <= xmax)and(xmin is None or external_vals[i] >= xmin)and(ymax is None or yparams_vals[i] <= ymax)and(ymin is None or params_vals[i] >= ymin):
plt.text(external_vals[i], params_vals[i], name, size=12)
rate, data = wavfile.read(fname)
 print("Sampling(frame)rate = ", rate)
 print("Total samples(frames)= ", data.shape)
 print(data )<import_modules>
analyzeParams(model_params, 1, 'ConfirmedCases', pop_set, 'Density', 500, True )
ModelCheckpoint, TensorBoard, ReduceLROnPlateau)
 GlobalMaxPool1D, Input, MaxPool1D, concatenate)
<set_options>
analyzeParams(model_params, 1, 'Fatalities', pop_set, 'Median Age', 10, True )
class Config(object):
def __init__(self,
sampling_rate=16000, audio_duration=2, n_classes=41,
use_mfcc=False, n_folds=12, learning_rate=0.0001,
max_epochs=80, n_mfcc=20):
self.sampling_rate = sampling_rate
self.audio_duration = audio_duration
self.n_classes = n_classes
self.use_mfcc = use_mfcc
self.n_mfcc = n_mfcc
self.n_folds = n_folds
self.learning_rate = learning_rate
self.max_epochs = max_epochs
self.audio_length = self.sampling_rate * self.audio_duration
if self.use_mfcc:
self.dim =(self.n_mfcc, 1 + int(np.floor(self.audio_length/512)) , 1)
 else:
self.dim =(self.audio_length, 1 )<define_variables>
analyzeParams(model_params, 1, 'ConfirmedCases', pop_set, 'Median Age', 500, True )
class DataGenerator(Sequence):
def __init__(self, config, data_dir, list_IDs, labels=None,
batch_size=64, preprocessing_fn=lambda x: x):
self.config = config
self.data_dir = data_dir
self.list_IDs = list_IDs
self.labels = labels
self.batch_size = batch_size
self.preprocessing_fn = preprocessing_fn
self.on_epoch_end()
self.dim = self.config.dim
def __len__(self):
return int(np.ceil(len(self.list_IDs)/ self.batch_size))
def __getitem__(self, index):
indexes = self.indexes[index*self.batch_size:(index+1)*self.batch_size]
list_IDs_temp = [self.list_IDs[k] for k in indexes]
return self.__data_generation(list_IDs_temp)
 def on_epoch_end(self):
self.indexes = np.arange(len(self.list_IDs))
def __data_generation(self, list_IDs_temp):
cur_batch_size = len(list_IDs_temp)
 X = np.empty(( cur_batch_size, *self.dim))
input_length = self.config.audio_length
for i, ID in enumerate(list_IDs_temp):
file_path = self.data_dir + ID
data, _ = librosa.core.load(file_path, sr=self.config.sampling_rate,
res_type='kaiser_fast')
 if len(data)> input_length:
max_offset = len(data)- input_length
offset = np.random.randint(max_offset)
 data = data[offset:(input_length+offset)]
else:
if input_length > len(data):
max_offset = input_length - len(data)
 offset = np.random.randint(max_offset)
 else:
offset = 0
data = np.pad(data,(offset, input_length - len(data)- offset), "constant")
 if self.config.use_mfcc:
data = librosa.feature.mfcc(data, sr=self.config.sampling_rate,
n_mfcc=self.config.n_mfcc)
 data = np.expand_dims(data, axis=-1)
 else:
data = self.preprocessing_fn(data)[:, np.newaxis]
X[i,] = data
if self.labels is not None:
y = np.empty(cur_batch_size, dtype=int)
 for i, ID in enumerate(list_IDs_temp):
y[i] = self.labels[ID]
return X, to_categorical(y, num_classes=self.config.n_classes)
 else:
return X<normalization>
analyzeParams(model_params, 1, 'ConfirmedCases', freedom_set, 'Economic Freedom', 500, True )
def audio_norm(data):
max_data = np.max(data)
 min_data = np.min(data)
 data =(data-min_data)/(max_data-min_data+1e-6)
 return data-0.5<choose_model_class>
analyzeParams(model_params, 1, 'ConfirmedCases', freedom_set, 'Personal Freedom', 500, True )
def get_1d_dummy_model(config):
nclass = config.n_classes
input_length = config.audio_length
inp = Input(shape=(input_length,1))
x = GlobalMaxPool1D()(inp)
 out = Dense(nclass, activation=softmax )(x)
 model = models.Model(inputs=inp, outputs=out)
 opt = optimizers.Adam(config.learning_rate)
 model.compile(optimizer=opt, loss=losses.categorical_crossentropy, metrics=['acc'])
 return model
def get_1d_conv_model(config):
nclass = config.n_classes
input_length = config.audio_length
inp = Input(shape=(input_length,1))
x = Convolution1D(32, 9, activation=relu, padding="same" )(inp)
 x = Convolution1D(32, 9, activation=relu, padding="same" )(x)
 x = MaxPool1D(16 )(x)
 x = Dropout(rate=0.1 )(x)
 x = Convolution1D(64, 3, activation=relu, padding="same" )(x)
 x = Convolution1D(64, 3, activation=relu, padding="same" )(x)
 x = MaxPool1D(4 )(x)
 x = Dropout(rate=0.1 )(x)
 x = Convolution1D(64, 3, activation=relu, padding="same" )(x)
 x = Convolution1D(64, 3, activation=relu, padding="same" )(x)
 x = MaxPool1D(4 )(x)
 x = Dropout(rate=0.1 )(x)
 x = Convolution1D(128, 3, activation=relu, padding="same" )(x)
 x = Convolution1D(128, 3, activation=relu, padding="same" )(x)
 x = MaxPool1D(4 )(x)
 x = Dropout(rate=0.1 )(x)
 x = Convolution1D(256, 3, activation=relu, padding="same" )(x)
 x = Convolution1D(256, 3, activation=relu, padding="same" )(x)
 x = GlobalMaxPool1D()(x)
 x = Dropout(rate=0.2 )(x)
 x = Dense(64, activation=relu )(x)
 x = Dense(1028, activation=relu )(x)
 out = Dense(nclass, activation=softmax )(x)
 model = models.Model(inputs=inp, outputs=out)
 opt = optimizers.Adam(config.learning_rate)
 model.compile(optimizer=opt, loss=losses.categorical_crossentropy, metrics=['acc'])
 return model<feature_engineering>
analyzeParams(model_params, 1, 'ConfirmedCases', freedom_set, 'Human Freedom', 500, True )
LABELS = list(train.label.unique())
 label_idx = {label: i for i, label in enumerate(LABELS)}
train.set_index("fname", inplace=True)
 test.set_index("fname", inplace=True)
 train["label_idx"] = train.label.apply(lambda x: label_idx[x])
 if not COMPLETE_RUN:
train = train[:2000]
test = test[:2000]<set_options>
analyzeParams(model_params, 1, 'Fatalities', country_set, 'Infant Mortality', 10, True )
config = Config(sampling_rate=16000, audio_duration=2, n_folds=10, learning_rate=0.001)
 if not COMPLETE_RUN:
config = Config(sampling_rate=100, audio_duration=1, n_folds=2, max_epochs=1 )<choose_model_class>
analyzeParams(model_params, 1, 'ConfirmedCases', country_set, 'Literacy', 500, True )
PREDICTION_FOLDER = "predictions_1d_conv"
if not os.path.exists(PREDICTION_FOLDER):
os.mkdir(PREDICTION_FOLDER)
 if os.path.exists('logs/' + PREDICTION_FOLDER):
shutil.rmtree('logs/' + PREDICTION_FOLDER)
 skf = StratifiedKFold(train.label_idx, n_folds=config.n_folds)
 for i,(train_split, val_split)in enumerate(skf):
train_set = train.iloc[train_split]
val_set = train.iloc[val_split]
checkpoint = ModelCheckpoint('best_%d.h5'%i, monitor='val_loss', verbose=1, save_best_only=True)
 early = EarlyStopping(monitor="val_loss", mode="min", patience=5)
 tb = TensorBoard(log_dir='./logs/' + PREDICTION_FOLDER + '/fold_%d'%i, write_graph=True)
 callbacks_list = [checkpoint, early, tb]
print("Fold: ", i)
 print("
if COMPLETE_RUN:
model = get_1d_conv_model(config)
 else:
model = get_1d_dummy_model(config)
 train_generator = DataGenerator(config, '.. /input/freesound-audio-tagging/audio_train/', train_set.index,
train_set.label_idx, batch_size=64,
preprocessing_fn=audio_norm)
 val_generator = DataGenerator(config, '.. /input/freesound-audio-tagging/audio_train/', val_set.index,
val_set.label_idx, batch_size=64,
preprocessing_fn=audio_norm)
 history = model.fit_generator(train_generator, callbacks=callbacks_list, validation_data=val_generator,
epochs=config.max_epochs, use_multiprocessing=True, workers=6, max_queue_size=20)
 model.load_weights('best_%d.h5'%i)
 train_generator = DataGenerator(config, '.. /input/freesound-audio-tagging/audio_train/', train.index, batch_size=128,
preprocessing_fn=audio_norm)
 predictions = model.predict_generator(train_generator, use_multiprocessing=True,
workers=6, max_queue_size=20, verbose=1)
 np.save(PREDICTION_FOLDER + "/train_predictions_%d.npy"%i, predictions)
 test_generator = DataGenerator(config, '.. /input/freesound-audio-tagging/audio_test/', test.index, batch_size=128,
preprocessing_fn=audio_norm)
 predictions = model.predict_generator(test_generator, use_multiprocessing=True,
workers=6, max_queue_size=20, verbose=1)
 np.save(PREDICTION_FOLDER + "/test_predictions_%d.npy"%i, predictions)
 top_3 = np.array(LABELS)[np.argsort(-predictions, axis=1)[:, :3]]
predicted_labels = [' '.join(list(x)) for x in top_3]
test['label'] = predicted_labels
test[['label']].to_csv(PREDICTION_FOLDER + "/predictions_%d.csv"%i )<load_pretrained>
analyzeParams(model_params, 1, 'ConfirmedCases', country_set, 'GDP', 500, True )