Category : knn

Assume that I have 3 different classes which follow a Gaussian distribution generated in the following way : x1 = np.random.random((100,7)) x2 = np.random.random((200,7)) x3 = np.random.random((300,7)) mean_x1 = np.mean(x1, axis = 0) mean_x2 = np.mean(x2, axis = 0) mean_x3 = np.mean(x3, axis = 0) cov_x1 = np.cov(x1.T) cov_x2 = np.cov(x2.T) cov_x3 = np.cov(x3.T) Class_1 ..

Read more

I am using gridsearch to find the best parameters and I want to save them and use them for the testing. When saving the best ^parameters and giving it to the algo, I encountered an error : BEST PARAMETERS: {‘metric’: ‘euclidean’, ‘n_neighbors’: 5, ‘weights’: ‘uniform’} BEST SCORE: 0.631578947368421 —Filename in processed corpus_ix_test_FMC_ small Traceback (most ..

Read more

In most cases, linalg.eigs has similar results with results from eigs in MATLAB. However in some cases, the two results are quite different. I offered two dates here: https://drive.google.com/file/d/1xBWCu_uUwEsAeF85uZAb70Bf4A2SOpM2/view?usp=sharing https://drive.google.com/file/d/1z3QFHiDfX8Qz099yTSJdGvwot9uMW8K4/view?usp=sharing (you can use it to create a KNN graph then calculate the generalized eigenvalue) when K =10, the biggest generalized eigenvalue from linalg.eigs would be ..

Read more

i am working on KNN in python. Anyone who can help me with this. MY CODE import numpy as np import pandas as pd from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt from sklearn.preprocessing import StandardScaler from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics import confusion_matrix import pickle import glob from sklearn.model_selection import GridSearchCV from sklearn.multioutput import ..

Read more

I can run a KNN classifier with the default classifier (L2 – Euclidean distance): def L2(trainx, trainy, testx): from sklearn.neighbors import KNeighborsClassifier # Create KNN Classifier knn = KNeighborsClassifier(n_neighbors=1) # Train the model using the training sets knn.fit(trainx, trainy) # Predict the response for test dataset y_pred = knn.predict(testx) return y_pred However, I want to ..

Read more