def simu_fit_test(arma_params, ll, order, n_train_samples, n_test_samples, data='arma', embedding='lead_lag'): inputSig = InputSig(data, embedding, order, ll=ll, arma_params=arma_params) train_X, train_y = get_input_X_y(inputSig, n_train_samples, start_row, n_processes=n_processes) max_train_X = np.amax(np.absolute(train_X), axis=0) train_X = train_X / max_train_X test_X, test_y = get_input_X_y(inputSig, n_test_samples, start_row + n_train_samples, n_processes=n_processes) test_X = test_X / max_train_X # Fit and evaluate algorithm learnSig = LearnSig(algo, inputSig, n_processes=n_processes) learnSig.train(train_X, train_y) test_results = learnSig.evaluate(test_X, test_y, metrics=['error_l2']) return (test_results['error_l2'])
n_processes=n_processes) valid_X = valid_X / max_train_X test_X = test_X / max_train_X # Fit and evaluate algorithm learnSig = LearnSig(algo, inputSig, n_processes=n_processes) # Train with custom parameters, for example for Urban Sound best random forest #custom_params={'n_estimators':460,'max_depth':30,'max_features':500} #learnSig.train( # train_X,train_y,valid_X=valid_X,valid_y=valid_y,params=custom_params) learnSig.train(train_X, train_y, valid_X=valid_X, valid_y=valid_y) test_results = learnSig.evaluate(test_X, test_y, metrics=['accuracy', 'f1_score']) print(test_results) # Write the results in a separate text file. results_path = os.path.join(results_dir, learnSig.model_name + ".txt") file = open(results_path, "w") file.write("Dataset: %s \n" % (data)) file.write("Algorithm: %s \n" % (algo)) file.write("Embedding: %s \n" % (embedding)) file.write("Signature order: %i \n" % (order)) file.write("Number of training samples: %i \n" % (n_train_samples)) file.write("Number of validation samples: %i \n" % (n_valid_samples)) file.write("Number of test samples: %i \n" % (n_test_samples))
n_processes=n_processes) valid_X = valid_X / max_train_X test_X, test_y = get_input_X_y(inputSig, n_test_samples, start_row + n_train_samples + n_valid_samples, n_processes=n_processes) valid_X = valid_X / max_train_X test_X = test_X / max_train_X for algo in algo_list: # Fit and evaluate algorithm learnSig = LearnSig(algo, inputSig, n_processes=n_processes) learnSig.train(train_X, train_y, valid_X=valid_X, valid_y=valid_y) test_results = learnSig.evaluate(test_X, test_y, metrics=metrics) print(test_results) results_df = results_df.append( { 'embedding': embedding, 'algo': algo, 'order': order, 'n_features': train_X.shape[1] }, ignore_index=True) print(results_df) for metric in metrics: results_df[metric].iloc[-1] = test_results[metric] # Write the results in a separate text file.