knn代码
来源:互联网 发布:ubuntu 升级python2.7 编辑:程序博客网 时间:2024/05/29 19:29
k-Nearest Neighbor (kNN) exercise
Complete and hand in this completed worksheet (including its outputs and any supporting code outside of the worksheet) with your assignment submission. For more details see the assignments page on the course website.
The kNN classifier consists of two stages:
- During training, the classifier takes the training data and simply remembers it
- During testing, kNN classifies every test image by comparing to all training images and transfering the labels of the k most similar training examples
- The value of k is cross-validated
In this exercise you will implement these steps and understand the basic Image Classification pipeline, cross-validation, and gain proficiency in writing efficient, vectorized code.
We would now like to classify the test data with the kNN classifier. Recall that we can break down this process into two steps:
- First we must compute the distances between all test examples and all train examples.
- Given these distances, for each test example we find the k nearest examples and have them vote for the label
Lets begin with computing the distance matrix between all training and test examples. For example, if there are Ntr training examples and Nte test examples, this stage should result in a Nte x Ntr matrix where each element (i,j) is the distance between the i-th test and j-th train example.
First, open cs231n/classifiers/k_nearest_neighbor.py
and implement the function compute_distances_two_loops
that uses a (very inefficient) double loop over all pairs of (test, train) examples and computes the distance matrix one element at a time.
Inline Question #1: Notice the structured patterns in the distance matrix, where some rows or columns are visible brighter. (Note that with the default color scheme black indicates low distances while white indicates high distances.)
- What in the data is the cause behind the distinctly bright rows?
- What causes the columns?
Your Answer: fill this in.
You should expect to see approximately 27%
accuracy. Now lets try out a larger k
, say k = 5
:
You should expect to see a slightly better performance than with k = 1
.
Cross-validation
We have implemented the k-Nearest Neighbor classifier but we set the value k = 5 arbitrarily. We will now determine the best value of this hyperparameter with cross-validation.
- knn代码
- kNN代码
- knn代码
- 代码笔记--kNN算法
- KNN-Dating完整代码
- kNN算法python代码学习
- KNN算法--python实现代码
- KNN算法matlab代码实现
- KNN算法 代码详细解释
- 机器学习实战 KNN代码
- knn
- knn
- KNN
- KNN
- KNN
- KNN
- KNN
- knn
- Altium Designer 16相关入门教程
- 算法 (排序乐园Lv-2) 插入排序代码实现
- python抽象类、抽象方法的实现
- codeforces 890B. Vlad and Cafes
- 字符串编码解码的一点理解
- knn代码
- node.js那些事
- X64 SEH的展开
- 如何写高质量代码?
- 双向绑定伪代码
- 静态顺序表的一些操作
- Java| Java关键字-static,final比较
- Altium Designer 16学习笔记——原理图和PCB元件对应查找
- data为什么是一个函数