def trial_running_pca(): lower_dimension = 4 iris_dataset = IRIS(crossvalidation=1) test_data,test_label,train_data,train_label = iris_dataset.load_data() test_points,test_dimension = test_data.shape train_points,train_dimension = train_data.shape complete_data = zeros((test_points+train_points,test_dimension),float32) complete_data[:test_points,:] = test_data complete_data[test_points:,:] = train_data ''' A = LDA(complete_data.T) dimension_reduced_data = dot(complete_data,A) markers = {'1':'r.','2':'g.','3':'b.'} plot_2d(dimension_reduced_data,test_label.tolist()+train_label.tolist(),markers) ''' pca = PCA(train_data, output_dim=lower_dimension) dimension_reduced_test_data = pca.execute(test_data,n=lower_dimension) dimension_reduced_train_data = pca.execute(train_data,n=lower_dimension) train_data = train_data.T test_data = test_data.T dimension_reduced_test_data = dimension_reduced_test_data.T dimension_reduced_train_data = dimension_reduced_train_data.T classification_error(dimension_reduced_train_data, train_label, dimension_reduced_test_data, test_label ) print train_data.shape print test_data.shape print dimension_reduced_test_data.shape markers = {'1':'r.','2':'g.','3':'b.', '4':'b*', '5':'g*', '6':'r*','7':'rs', '8':'gs','9':'bs'} plot_2d(dimension_reduced_test_data,test_label.tolist(),markers)
def run_kde(): print "-- Starting kde--" landsat_dataset = IRIS(crossvalidation = 0) test_data,test_label,train_data,train_label = landsat_dataset.load_data() print test_data.shape print train_data.shape lower_dimension = 2 kde_cub = KDECUB(train_data, train_label, lower_dimension, test_data = test_data, test_label = test_label) kde_cub.train()