Return confidence level on KNN example
See original GitHub issue- face_recognition version: 1.2.3
- Python version: python:3.4-slim
- Operating System: Docker Linux on a Windows Machine (Development) and RancherOS K8s (Production)
Description
Basically I want to achieve what you suggested on #541 on the following knn example https://github.com/ageitgey/face_recognition/blob/master/examples/face_recognition_knn.py
What I Did
I used docker to get the example working fine
Have tried to print the result from this code, which are
closest_distances
, are_matches
but don’t think those are relevant to what I need
# Find encodings for faces in the test iamge
faces_encodings = face_recognition.face_encodings(X_img, known_face_locations=X_face_locations)
# Use the KNN model to find the best matches for the test face
closest_distances = knn_clf.kneighbors(faces_encodings, n_neighbors=1)
are_matches = [closest_distances[0][i][0] <= distance_threshold for i in range(len(X_face_locations))]
# Predict classes and remove classifications that aren't within the threshold
return [(pred, loc) if rec else ("unknown", loc) for pred, loc, rec in zip(knn_clf.predict(faces_encodings), X_face_locations, are_matches)]
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
classification algorithms that return confidences?
Given a machine learning model built on top of scikit-learn, how can I classify new instances but then choose only those with the...
Read more >Confidence Intervals for Machine Learning
First, the desired lower percentile is calculated based on the chosen confidence interval. Then the observation at this percentile is retrieved ...
Read more >K Nearest Neighbor | KNN Algorithm | KNN in Python & R
The three closest points to BS is all RC. Hence, with a good confidence level, we can say that the BS should belong...
Read more >Prediction intervals for kNN regression - Cross Validated
Run the knn regression over each new data-set and sort the point predictions. The confidence interval is just the distance between the 5th ......
Read more >Prediction using kNN and Linear Regression - Student Version
We explained Confidence Intervals above where because we assume normal symetric distribution of data, the 95% Confidence Interval means there's 2.5% chance of ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
closest_distances
is the distance between the unknown face and the known face. The lower the value, the stronger the match. Thedistance_threshold
is how small that distance has to be to be considered a match. The default distance threshold is 0.6. So a closest_distance greater than 0.6 is not considered a match and a value less than 0.6 is considered a match - with smaller numbers being stronger matches.That’s how this model works. It doesn’t use percentage match scores. But if you want to convert that distance value into an estimate of a percentage match so the number is more clear to you, you can use this function: https://github.com/ageitgey/face_recognition/wiki/Calculating-Accuracy-as-a-Percentage
@ageitgey How can I use the same function for multiple faces in the frame?