diff --git a/doc/sphinx/source/conf.py b/doc/sphinx/source/conf.py index 0168893d0a4..64e54b270a9 100644 --- a/doc/sphinx/source/conf.py +++ b/doc/sphinx/source/conf.py @@ -28,7 +28,8 @@ # ones. extensions = [ 'sphinx.ext.pngmath', - 'sgexample' + 'sgexample', + 'sphinxcontrib.bibtex', ] # Add any paths that contain templates here, relative to this directory. diff --git a/doc/sphinx/source/examples/classifier/knn.rst b/doc/sphinx/source/examples/classifier/knn.rst index 4ed3c1e34df..ac177354546 100644 --- a/doc/sphinx/source/examples/classifier/knn.rst +++ b/doc/sphinx/source/examples/classifier/knn.rst @@ -4,24 +4,37 @@ K Nearest neighbours KNN classifies data according to the majority of labels in the nearest neighbourhood, according to some underlying distance function :math:`d(x,x')`. -For :math:`k=1`, the label for point :math:`x_i` is :math:`y_{k^*}`, where :math:`k^*=\argmin_n d(x_i, x_n)`. +For :math:`k=1`, the label for point :math:`x_i` is :math:`y_{k^*}`, where + +.. math:: + + k^*=\argmin_n d(x_i, x_n). + +See Chapter 14 in :cite:`barber2012bayesian` for a detailed introduction. ------- Example ------- -Imagine you have some training and test data. +Load some training and test data. .. sgexample:: knn.sg:load_data -In order to run KNN, we need to choose a distance, for example CEuclideanDistance, or other sub-classes of CDistance. The distance needs the data we want to classify. +In order to run KNN, we need to choose a distance, for example CEuclideanDistance, or other sub-classes of CDistance. The distance is initialized with the data we want to classify. .. sgexample:: knn.sg:choose_distance -Once you have chosen a distance, create an instance of the CKNN classifier, passing it training data and labels +Once we have chosen a distance, we create an instance of the CKNN classifier, passing it training data and labels. .. sgexample:: knn.sg:create_instance -Now we run the KNN algorithm and apply it to test data +Then we run the KNN algorithm and apply it to test data. .. sgexample:: knn.sg:train_and_apply + +---------- +References +---------- +`KNN on Wikipedia `_ + +.. bibliography:: ../../references.bib diff --git a/doc/sphinx/source/references.bib b/doc/sphinx/source/references.bib new file mode 100644 index 00000000000..121d99957c9 --- /dev/null +++ b/doc/sphinx/source/references.bib @@ -0,0 +1,6 @@ +@book{barber2012bayesian, + title={Bayesian reasoning and machine learning}, + author={Barber, David}, + year={2012}, + publisher={Cambridge University Press} +}