Skip to content

Commit 7879246

Browse files
committed
update documentation
1 parent 0178e99 commit 7879246

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

docs/numpy_ml.nonparametric.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ Nonparametric models
33

44
.. raw:: html
55

6-
<h2>Nearest Neighbors</h2>
7-
8-
TODO
6+
<h2>K-Nearest Neighbors</h2>
7+
8+
The `k-nearest neighbors`_ (KNN) model is a nonparametric supervised learning
9+
approach that can be applied to classification or regression problems. In a
10+
classification context, the KNN model assigns a class label for a new datapoint
11+
by taking a majority vote amongst the labels for the `k` closest points
12+
("neighbors") in the training data. Similarly, in a regression context, the KNN
13+
model predicts the target value associated with a new datapoint by taking the
14+
average of the targets associated with the `k` closes points in the training
15+
data.
16+
17+
.. _`k-nearest neighbors`: https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm
918

1019
**Models**
1120

docs/numpy_ml.trees.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ associated with at least one data point from the original training set.
1515
:align: center
1616

1717
A binary decision tree trained on the dataset :math:`X = \{ \mathbf{x}_1,
18-
\ldots, \mathbf{x}_{10} \}`. Each example in the dataset is a 5-dimensional
19-
vector of real-valued features labeled :math:`x_1, \ldots, x_5`. Unshaded
18+
\ldots, \mathbf{x}_{10} \}`. Each example in the dataset is a 4-dimensional
19+
vector of real-valued features labeled :math:`x_1, \ldots, x_4`. Unshaded
2020
circles correspond to internal decision nodes, while shaded circles
2121
correspond to leaf nodes. Each leaf node is associated with a subset of the
2222
examples in `X`, selected based on the decision rules along the path from
@@ -52,13 +52,13 @@ impurity after a particular split is
5252
.. math::
5353
5454
\Delta \mathcal{L} = \mathcal{L}(\text{Parent}) -
55-
P_{left} \mathcal{L}(\text{Left child}) -
56-
(1 - P_{left})\mathcal{L}(\text{Right child})
55+
P_{\text{left}} \mathcal{L}(\text{Left child}) -
56+
(1 - P_{\text{left}})\mathcal{L}(\text{Right child})
5757
5858
where :math:`\mathcal{L}(x)` is the impurity of the dataset at node `x`,
59-
and :math:`P_{left}`/:math:`P_{right}` are the proportion of examples at the
60-
current node that are partitioned into the left / right children, respectively,
61-
by the proposed split.
59+
and :math:`P_{\text{left}}`/:math:`P_{\text{right}}` are the proportion of
60+
examples at the current node that are partitioned into the left / right
61+
children, respectively, by the proposed split.
6262

6363
.. _`Decision trees`: https://en.wikipedia.org/wiki/Decision_tree_learning
6464

@@ -123,7 +123,7 @@ that proceeds by iteratively fitting a sequence of `m` weak learners such that:
123123
124124
where `b` is a fixed initial estimate for the targets, :math:`\eta` is
125125
a learning rate parameter, and :math:`w_{i}` and :math:`g_{i}`
126-
denote the weights and predictions for `i` th learner.
126+
denote the weights and predictions of the :math:`i^{th}` learner.
127127

128128
At each training iteration a new weak learner is fit to predict the negative
129129
gradient of the loss with respect to the previous prediction,

numpy_ml/bandits/bandits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,14 @@ def _pull(self, arm_id, context):
406406
class ContextualLinearBandit(Bandit):
407407
def __init__(self, K, D, payoff_variance=1):
408408
r"""
409-
A linear multi-armed bandit where .
409+
A contextual linear multi-armed bandit.
410410
411411
Notes
412412
-----
413413
In a contextual linear bandit the expected payoff of an arm :math:`a
414414
\in \mathcal{A}` at time `t` is a linear combination of its context
415415
vector :math:`\mathbf{x}_{t,a}` with a coefficient vector
416-
:math:`\\theta_a`:
416+
:math:`\theta_a`:
417417
418418
.. math::
419419

numpy_ml/factorization/factors.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,16 @@ def fit(self, X, W=None, H=None, n_initializations=10, verbose=False):
295295
the input data matrix, and :math:`\mathbf{w}_j` and
296296
:math:`\mathbf{h}_j` are the :math:`j^{th}` columns of the current
297297
factor matrices **W** and **H**. HALS proceeds by minimizing the cost
298-
for each residue, first with respect to :math:`\mathbf{w}_j` holding
299-
:math:`\mathbf{h}_j` fixed, and then with respect to
300-
:math:`\mathbf{h}_j`, holding the newly updated :math:`\mathbf{w}_j`
301-
fixed. The residue cost :math:`\mathcal{L}^{(j)}` for
302-
:math:`\mathbf{X}^{j}` is simply:
298+
for each residue, first with respect to :math:`\mathbf{w}_j`, and then
299+
with respect to :math:`\mathbf{h}_j`. In either case, the cost for
300+
residue `j`, :math:`\mathcal{L}^{(j)}` is simply:
303301
304302
.. math::
305303
306304
\mathcal{L}^{(j)} :=
307305
|| \mathbf{X}^{(j)} - \mathbf{w}_j \mathbf{h}_j^\top ||
308306
309-
where :math:`||\cdot||` denotes the Frobenius norm. For NMF, this
307+
where :math:`||\cdot||` denotes the Frobenius norm. For NMF,
310308
minimization is performed under the constraint that all elements of
311309
both **W** and **H** are nonnegative.
312310

0 commit comments

Comments
 (0)