def extract_features_percentage(classifier, percentage, X, Y, extraction_type): tiempo_i = time.time() Errores = np.ones(10) Metrics = np.zeros((10, 5)) j = 0 kf = KFold(n_splits=10) clf = classifier ex = extract_features(extraction_type, int(X.shape[1] * percentage / 100)) if (extraction_type == "pca"): ex = ex.fit(X) elif (extraction_type == "lda"): ex = ex.fit(X, Y.astype(int)) X_ex = ex.transform(X) for train_index, test_index in kf.split(X_ex): X_train, X_test = X_ex[train_index], X_ex[test_index] y_train, y_test = Y[train_index], Y[test_index] model = clf.fit(X_train, y_train) y_pred = model.predict(X_test) Errores[j] = 1 - metrics(y_test, y_pred)[0] Metrics[j, :] = metrics(y_test, y_pred) j += 1 print("\nError de validación aplicando " + str(extraction_type) + " at " + str(percentage) + "%: " + str(np.mean(Errores)) + "+/-" + str(np.std(Errores))) print("\nEficiencia en validación aplicando " + str(extraction_type) + " at " + str(percentage) + "%: " + str((1 - np.mean(Errores)) * 100) + "%") print("\nTiempo total de ejecución: " + str(time.time() - tiempo_i) + " segundos.") MetricsMean = meanMetrics(Metrics) MetricsStd = stdMetrics(Metrics) printMetrics(MetricsMean) print("\nDesviaciones Estandard") printMetrics(MetricsStd) return ex
def select_features_filter_percentage(classifier, percentage, X, Y): tiempo_i = time.time() Errores = np.ones(10) Metrics = np.zeros((10, 5)) j = 0 kf = KFold(n_splits=10) filter_method = SelectPercentile(mutual_info_classif, percentile=percentage) filter_method.fit(X, Y) X_sf = filter_method.transform(X) for train_index, test_index in kf.split(X_sf): X_train, X_test = X_sf[train_index], X_sf[test_index] y_train, y_test = Y[train_index], Y[test_index] classifier.fit(X_train, y_train) y_pred = classifier.predict(X_test) Metrics[j, :] = metrics(y_test, y_pred) Errores[j] = 1 - metrics(y_test, y_pred)[0] j += 1 print("\nError de validación aplicando at " + str(percentage) + "%: " + str(np.mean(Errores)) + "+/-" + str(np.std(Errores))) print("\nEficiencia en validación aplicando at " + str(percentage) + "%: " + str((1 - np.mean(Errores)) * 100) + "%") print("\nTiempo total de ejecución: " + str(time.time() - tiempo_i) + " segundos.") MetricsMean = meanMetrics(Metrics) MetricsStd = stdMetrics(Metrics) printMetrics(MetricsMean) print("\nDesviaciones Estandard") printMetrics(MetricsStd) return filter_method
def select_features_number(classifier, number_features, fwd, fltg, X, Y): tiempo_i = time.time() Errores = np.ones(10) Metrics = np.zeros((10, 5)) j = 0 kf = KFold(n_splits=10) clf = classifier sf = select_features(clf, number_features, fwd, fltg) sf = sf.fit(X, Y) X_sf = sf.transform(X) for train_index, test_index in kf.split(X_sf): X_train, X_test = X_sf[train_index], X_sf[test_index] y_train, y_test = Y[train_index], Y[test_index] classifier.fit(X_train, y_train) y_pred = classifier.predict(X_test) Errores[j] = 1 - metrics(y_test, y_pred)[0] Metrics[j, :] = metrics(y_test, y_pred) j += 1 print("\nError de validación aplicando SFS: " + str(np.mean(Errores)) + "+/-" + str(np.std(Errores))) print("\nEficiencia en validación aplicando SFS: " + str((1 - np.mean(Errores)) * 100) + "%") print("\nTiempo total de ejecución: " + str(time.time() - tiempo_i) + " segundos.") MetricsMean = meanMetrics(Metrics) MetricsStd = stdMetrics(Metrics) printMetrics(MetricsMean) print("\nDesviaciones Estandard") printMetrics(MetricsStd) return sf
exactitud = np.zeros((num_splits, 5)) iteration = 0 for train_index, test_index in kf.split(x): X_train, X_test = x[train_index], x[test_index] y_train, y_test = y[train_index], y[test_index] clf.fit(X_train, y_train) y_pred = clf.predict(X_test) exactitud[iteration, :] = metrics(y_test, y_pred) iteration += 1 error_standard = stdMetrics(error_promedio) error_promedio = meanMetrics(error_promedio) print('Error para C=', c) printMetrics(error_promedio) print('Desviación estandar') print('###################################') printMetrics(error_standard) error_by_parameter[i, :] = error_promedio i += 1 elapsed_time = time.time() - start print('Elapsed time for one neuron Classification: ', elapsed_time) plt.plot(C, error_by_parameter[:, 0], 'b--')
X_train, X_test = x[train_index], x[test_index] y_train, y_test = y[train_index], y[test_index] clf.fit(X_train,y_train) y_pred = clf.predict(X_test) error_promedio[iteration, :] = metrics(y_test, y_pred) iteration += 1 error_desviacion = stdMetrics(error_promedio) error_promedio = meanMetrics(error_promedio) print('Error para', B, ' forest: ') print('###########################################') printMetrics(error_promedio) print('Desviación estandar') print('##########################################') printMetrics(error_desviacion) np.savetxt(saveFile, error_promedio) error_by_B[i, :]=error_promedio i+=1 saveFile.close() elapsed_time = time.time()-start print('Elapsed time for one neuron Classification: ',elapsed_time) plt.plot(range(10,51,10), error_by_B[:, 0], 'b--') plt.xlabel('Numero de Arboles')
"fossdriverrc.json") fdServer = fossdriverSetup(fossdriverrc_path) if not fdServer: print(f"Unable to connect to Fossology server with fossdriver") sys.exit(1) all_metrics = getMetrics(cfg, fdServer) metricsFilename = os.path.join(cfg._storepath, cfg._month, "metrics.json") saveMetrics(metricsFilename, all_metrics) elif command == "printmetrics": ran_command = True metricsFilename = os.path.join(cfg._storepath, cfg._month, "metrics.json") printMetrics(metricsFilename) elif command == "transfer": ran_command = True # set up fossdriver server connections old_fossdriverrc_path = os.path.join(str(Path.home()), ".fossdriver", "fossdriverrc.json") old_server = fossdriverSetup(old_fossdriverrc_path) if not old_server: print( f"Unable to connect to old Fossology server with fossdriver" ) sys.exit(1) new_fossdriverrc_path = os.path.join(str(Path.home()),
kf = KFold(n_splits=num_splits) kf.get_n_splits(x) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=["accuracy"]) exactitud = np.zeros((num_splits, 5)) iteration = 0 start = time.time() for train_index, test_index in kf.split(x): X_train, X_test = x[train_index], x[test_index] y_train, y_test = y[train_index], y[test_index] model.fit(X_train, y_train, batch_size=100, epochs=5) y_pred = model.predict_classes(X_test) exactitud[iteration, :] = metrics(y_test, y_pred) iteration += 1 elapsed_time = time.time() - start mean_metrics = meanMetrics(exactitud) std_metrics = stdMetrics(exactitud) printMetrics(mean_metrics) print('Desviación estandar') print('########################################') printMetrics(std_metrics)