Warning: This documentation is for scikits.learn version 0.6.0. — Latest stable version

Contents

6.5.2. scikits.learn.neighbors.NeighborsBarycenter

class scikits.learn.neighbors.NeighborsBarycenter(n_neighbors=5, window_size=1)

Regression based on k-Nearest Neighbor Algorithm.

The target is predicted by local interpolation of the targets associated of the k-Nearest Neighbors in the training set. The interpolation weights correspond to barycenter weights.

Parameters :

X : array-like, shape (n_samples, n_features)

The data points to be indexed. This array is not copied, and so modifying this data will result in bogus results.

y : array

An array representing labels for the data (only arrays of integers are supported).

n_neighbors : int

default number of neighbors.

window_size : int

Window size passed to BallTree

Notes

http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm

Examples

>>> X = [[0], [1], [2], [3]]
>>> y = [0, 0, 1, 1]
>>> from scikits.learn.neighbors import NeighborsBarycenter
>>> neigh = NeighborsBarycenter(n_neighbors=2)
>>> neigh.fit(X, y)
NeighborsBarycenter(n_neighbors=2, window_size=1)
>>> print neigh.predict([[1.5]])
[ 0.5]

Methods

fit(X, y[, copy])
predict(T[, n_neighbors]) Predict the target for the provided data.
score(X, y) Returns the coefficient of determination of the prediction
__init__(n_neighbors=5, window_size=1)

Internally uses the ball tree datastructure and algorithm for fast neighbors lookups on high dimensional datasets.

predict(T, n_neighbors=None)

Predict the target for the provided data.

Parameters :

T : array

A 2-D array representing the test data.

n_neighbors : int

Number of neighbors to get (default is the value passed to the constructor).

Returns :

y: array :

List of target values (one for each data sample).

Examples

>>> X = [[0], [1], [2]]
>>> y = [0, 0, 1]
>>> from scikits.learn.neighbors import NeighborsBarycenter
>>> neigh = NeighborsBarycenter(n_neighbors=2)
>>> neigh.fit(X, y)
NeighborsBarycenter(n_neighbors=2, window_size=1)
>>> print neigh.predict([[.5], [1.5]])
[ 0.   0.5]
score(X, y)

Returns the coefficient of determination of the prediction

Parameters :

X : array-like, shape = [n_samples, n_features]

Training set.

y : array-like, shape = [n_samples]

Returns :

z : float