def test_VQPCA(self): VQPCA = clustering.lpca(self.X) VQPCA.eigens = self.nPCtest VQPCA.clusters = self.nKtest VQPCA.initialization = 'uniform' VQPCA.writeFolder = False try: idx = VQPCA.fit() passed = True except: passed = False self.assertEqual(passed, True)
"evaluate_clustering": True, } X = readCSV(file_options["path_to_file"], file_options["input_file_name"]) print("matrix dimensions: {}".format(X.shape)) if settings["select_variables"]: PVs = model_order_reduction.variables_selection(X, settings) labels, numbers = PVs.fit() redX = X[:, numbers] print("The new data dimensions are: {}".format(X.shape)) model = clustering.lpca(redX, settings) index = model.fit() if settings["evaluate_clustering"]: #evaluate the clustering solution PHC_coeff, PHC_deviations = evaluate_clustering_PHC(X, index, method='PHC_standard') print(PHC_coeff) #evaluate the clustering solution by means of the Davies-Bouldin index X_tilde = center_scale(X, center(X, method=settings["centering_method"]), scale(X, method=settings["scaling_method"])) DB = evaluate_clustering_DB(X_tilde, index)
False, # --> call the method to classify a new matrix Y on the basis of the lpca clustering "write_on_txt": True, # --> write the idx vector containing the label for each observation "evaluate_clustering": True, # --> enable the calculation of indeces to evaluate the goodness of the clustering } # Load the matrices and the mesh, to plot the classification results X = readCSV(file_options["path_to_file"], file_options["input_file_name"]) Y = readCSV(file_options["path_to_file"], file_options["test_file_name"]) mesh = np.genfromtxt(mesh_options["path_to_file"] + "/" + mesh_options["mesh_file_name"], delimiter=',') # Start the clustering step model = clustering.lpca(X, settings_clustering) index = model.fit() # Start the classification step classifier = classification.VQPCA(X, index, Y) classification_vector = classifier.fit() # Plot the results matplotlib.rcParams.update({'font.size': 14, 'text.usetex': True}) fig = plt.figure() axes = fig.add_axes([0.15, 0.15, 0.7, 0.7], frameon=True) axes.scatter(mesh[:, 0], mesh[:, 1], c=classification_vector, alpha=1, cmap='gnuplot')