def KNearestNCA(): ''' Test the nearest neighbor regressor. Separate function, to play with NCA. ''' nca = neighbors.NeighborhoodComponentsAnalysis(random_state=42) knn = neighbors.KNeighborsRegressor() nca_pipe = Pipeline([('nca', nca), ('knn', knn)]) #nca_pipe.fit(X_train, y_train) rmselist = loopTrainSizeFixedMdl(nca_pipe, tsize=30, rep=1000)
random_state=0, eigen_solver="arpack") t0 = time() X_se = embedder.fit_transform(X) plot_embedding(X_se, "Spectral embedding of the digits (time %.2fs)" % (time() - t0)) # ---------------------------------------------------------------------- # t-SNE embedding of the digits dataset print("Computing t-SNE embedding") tsne = manifold.TSNE(n_components=2, init='pca', random_state=0) t0 = time() X_tsne = tsne.fit_transform(X) plot_embedding(X_tsne, "t-SNE embedding of the digits (time %.2fs)" % (time() - t0)) # ---------------------------------------------------------------------- # NCA projection of the digits dataset print("Computing NCA projection") nca = neighbors.NeighborhoodComponentsAnalysis(init='random', n_components=2, random_state=0) t0 = time() X_nca = nca.fit_transform(X, y) plot_embedding(X_nca, "NCA embedding of the digits (time %.2fs)" % (time() - t0)) plt.show()
fullX, fullY = createSetForSelection() rank = selection(fullX, fullY, 1) finalRank = labelAndSortScores(rank, "dane/features.txt") # WYPISANIE RANKINGU CECH DO PLIKU #outputFile = open("indexed_sortedRank.txt", "w") #for record in finalRank: # outputFile.write(str(record)+"\n") #outputFile.close() #initialising custom metric component weightedMetric = WeightedEucledianMetric() # initialising analysis component nca = neighbors.NeighborhoodComponentsAnalysis() amountOfTests = 25 testOutputFile = open("statisticTestResults.txt", "w") testOutputFile.write("Testing metrics for averaged " + str(amountOfTests) + " random tests\n") testOutputFile.close() # square root from number of cases in the training set (90% of the whole data set) numOfNeighbours = int(math.sqrt(len(fullY) * 0.9)) featuresFromTo = [53, 45, 37, 30, 22, 15, 10] # for now number of neighbors is based on features # neighboursFromTo = [5,10,15] for featuresToInclude in featuresFromTo: