Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [k-nn]

The tag has no usage guidance.

0
votes
1answer
18 views

How Does Weighted KNN Work?

I am reading notes on using weights for KNN and I came across an example that I don't really understand. Suppose we have K = 7 and we obtain the following: Decision set = {A, A, A, A, B, B, B} If ...
0
votes
1answer
6 views

Features selection in KNN

I have a naive question about using the K Nearest Neighbor algorithm: is feature selection more important in KNN than in other algorithms? If a particular feature is not predictive in a neural ...
1
vote
2answers
90 views

How can I implement tangent distance for k-nearest neighbor in python/scikit-learn?

My ultimate aim is to have a function which I can feed into scikit-learn's NearestNeighbor class as a custom metric parameter. ...
1
vote
1answer
26 views

How does KNN work if there are duplicates?

I am currently debating with my friend about how KNN handles duplicates. Suppose K = 2, and we have a 1-dimensional set of data points to illustrate my dilemma I = {1, 2, 2, 2, 2, 2, 6} Thus is it ...
0
votes
1answer
50 views

Is there any way of ordering/sorting vectors?

I am working on KD-Tree for nearest neighbor algorithm, where at each level of the tree we arbitrarily choose a dimension to cut upon and sort the points based on that chosen dimension value, after ...
1
vote
0answers
12 views

Best way to find dissimilarity in a 6x2 DataFrame?

I'm new to data science and am currently learning different techniques that I can do with Python. Currently, I'm trying it out with Spotify's API for my own playlists. The goal is to find the most ...
0
votes
0answers
13 views

Encoding Target variable missing data imputing using KNN

I'm working on a classification model, so my target variable for the training set contains some missing data, I'm trying to impute it using KNN. Should I encode the target variable before training ...
0
votes
1answer
36 views

Is there an upper bound for k in nearest neighbors-based methods?

When applying a nearest neighbors-based method to a data of, for instance, 2000 points, what is the largest number of neighbors that can be considered ? I am using a nearest neighbors method in an ...
2
votes
1answer
32 views

Creating a single number from a numpy array - Python [closed]

I am working on a gender classification project. I am extracting the pixels of an image using a Numpy array in Python, similar to the one below: ...
1
vote
1answer
31 views

Problem with calculating error rate for KNN

I am trying to validate the accuracy of my KNN algorithm for the movie rating prediction. I have $2$ vectors: $Y$ - with the real ratings, $Y'$ - with predicted ones. When I calculate Standard ...
3
votes
2answers
26 views

Why isn't local averaging (including KNN) used often for regression?

My professor said that the "holy grail of regression" is the function E(Y|X=x) i.e. the conditional expectation of Y on X. In practice, you'd take a small window of X and take the average value of Y ...
7
votes
1answer
52 views

How to decide the shape of input features, when each data file is of different length?

To help me understand the benefits and shortcomings of decision trees, KNN, Neural Networks, ...
2
votes
2answers
103 views

Taking Neural Network's false positives as the recommendation system result?

I am creating a recommendation system and considering two parallel ways of formalizing the problem. One classical, using proximity (recommend the product to the customer if a majority vote of 2k+1 ...
1
vote
0answers
17 views

How to determine the k in kNN [duplicate]

I'm looking to use the k-Nearest Neighbors (kNN) algorithm. What are the possible methods for determining the best K? From what I have read, looking at many different values(say 10-100) should work, ...
5
votes
2answers
60 views

Is K-NN applicable for binary variables?

I need help because I'm just new to machine learning and I do not know if k-nearest neighbors algorithm can be used to identify the appropriate program(s) for Student 11 in the table below. The ...
1
vote
1answer
26 views

scalable tools to build kNN graph over sparse data

I'm looking for scalable tools to build kNN graph over sparse data points. The dimension and number of data points can be both up to millions. What I have tried already: sklearn.neighbors....
1
vote
0answers
62 views

Python-SQL database [closed]

There are two SQL databases in which one database contains user data and other database contains service data. Firstly, I am connecting the databases and fetching it on python.Based on the user data, ...
3
votes
1answer
255 views

Sklearn: unsupervised knn vs k-means

Sklearn has an unsupervised version of knn and also it provides an implementation of k-means. If I am right, kmeans is done exactly by identifying "neighbors" (at ...
3
votes
2answers
488 views

sklearn.neighbors.NearestNeighbors - knn for unsupervised learning?

From basic theory I know that knn is a supervised algorithm while for example k-means is an unsupervised algorithm. However, at Sklearn there are is an implementation of KNN for unsupervised learning ...
0
votes
0answers
27 views

Estimate the number of very distinct elements inside a dataset

Lets take for example the MNIST dataset, this dataset is composed of 60 000 training samples each sample is a handwritten digit between 0 and 9. however, we may find several samples inside this ...
1
vote
0answers
23 views

advice on distance metric for knn w/image recognition

I'm getting my feet wet with machine learning and am implementing a knn algorithm on a dataset that i've created. I've created a set of images of circles and squares and want the knn algorithm to ...
2
votes
1answer
61 views

How can I apply PCA to KNN?

I want to know the do not want to how to use library I will denote a $n\times p$ data matrix by $X$, where $n<p$. That is, each row of $X$ is one sample data with $p$ feature variables. By using ...
2
votes
1answer
770 views

How to calculate the silhouette coefficient?

Calculate the silhouette coefficient of point Pi from the above image. To apply the given formula, how to know which is a(i) and b(i)?
0
votes
0answers
11 views

How Metacost operator act on Knn

Intuitively, the metacost operator ( in a case where we have only 2 classification classes) allow to increase the cost associated in making a misclassification error. In rapidminer software, i can ...
2
votes
1answer
536 views

Knn and euclidean distance

I'm studying the knn classification algorithm. Why can the euclidean distance be considered a nice measure of affinity between examples ? In one dimension (1 attribute) this seems correct, but if I ...
2
votes
0answers
23 views

How to weigh feature array

I have a feature array of around 4000 elements, extracted from one source. On this array I've extracted 7 more feature from other source and now I basically have a 4007 feature array from each data ...
0
votes
1answer
45 views

How to get nearest 5 points mean with Nearest Neighbours?

In a dataset of longitude, latitude and price (of houses) I'm using sklearn's KNearestRegressor to get the 5 nearest neighbors mean price for each point. The problem is I want to do this for the whole ...
1
vote
1answer
37 views

Question about Knn and split validation

I have a big database with 40k recors and 2 classification classes. In this big database the 76% of records belong to the first class. I've used a 70-30 split partition with stratified sampling, and ...
3
votes
0answers
48 views

k-Nearest Neighbours with time series data - how to obtain whole-time-period estimators

I have a large dataset for the activities performed by multiple staff in a factory over a long period of time - 01/01/2017 - present. The activities performed by different staff are recorded at each ...
3
votes
1answer
533 views

Evaluation metrics for Decision Tree regressor and KNN regressor

I have started working on the Decision Tree Regressor and KNN Regressor. I have built the model and not sure what are the metrics needs to be considered for evaluation. As of now I have considered ...
3
votes
1answer
1k views

Why is cross-validation score so low?

I am using Scikit-Learn for this classification problem. The dataset has 3 features and 600 data points with labels. First I used Nearest Neighbor classifier. ...
0
votes
1answer
89 views

Visualizing Decision Tree of K-Nearest-Neighbours classifier

I'm using Sklearn's KNN to build a classifier and was wondering if there is any way to visualize the decision tree that the algorithm builds. Maybe something of this fashion
0
votes
1answer
118 views

Is there a way to standardize latitude and longitude to be used as predictors in KNN algorithm? [closed]

The predictors are latitude and longitude, and target variable is region.
0
votes
0answers
32 views

Sklearn's NearestNeighbors for case-control matching?

I'm trying to match cases and controls based on age, gender, race, and a few disease statuses. I have race one-hot encoded, where each column is a different race, and a 1 means the patient is of that ...
0
votes
0answers
16 views

Combine metrics for k-NN

I have two separate metrics that give me the similarity/distance of two instances of what I'm clustering. What are ways to combine those two metrics? I think I could just simply add them together or ...
0
votes
0answers
11 views

In paper “Neighbourhood Components Analysis”, how to determine the optimal number of neighbours (K)?

Recently, I am reading the paper "Neighbourhood Components Analysis" (Goldberger, Jacob, et al. "Neighbourhood components analysis." Advances in neural information processing systems. 2005.). At the ...
0
votes
0answers
37 views

Scaling data with multiple Imputation with KNN?

Since it is required that data is normalised prior to imputing with KNN, if we were to scale, wouldn't this affect "imputation accuracy" ? If it would, what would you suggest in terms of an approach ...
0
votes
0answers
1k views

Why classification accuracy of kNN for irisdataset is not coming correct?

Context I am working on a program assignment to calculate the classification accuracy of kNN for the irisdata set. My trainingList consists of total 90 data sets with the first 30 from each type of ...
0
votes
2answers
40 views

Testing unsupervised clustering

Assume we train a KMeans model using data X. This will give a set of centroids that can be used to cluster data X* using a Nearest Centroid Classifier. If we use a density-based model such as DBSCAN ...
3
votes
2answers
60 views

Find which type of log using machine learning?

I am the beginner of Machine learning. The process is: I have different log files (System log, MSSQL Server log, Linux log, MySQL Log, FTP log, IIS log).If any input is given, I will find out which ...
3
votes
1answer
760 views

How does sklearn KNeighborsClassifier compute class probabilites?

The KNeighborsClassifier has a method for predicting class probabilities. However, I cannot find any documentation describing how these probabilities are computed. ...