You've already forked neighbours
upd README.md, refactor
This commit is contained in:
16
README.md
16
README.md
@@ -1,6 +1,6 @@
|
|||||||
# Neighbours
|
# Neighbours
|
||||||
|
|
||||||
Weighted kNN classifier implementation based on random projection forest.
|
Weighted kNN classifier and Nadaraya-Watson kernel regressor implementation based on random projection forest.
|
||||||
|
|
||||||
### Classifier description
|
### Classifier description
|
||||||
|
|
||||||
@@ -19,13 +19,22 @@ Built-in distance metrics:
|
|||||||
|
|
||||||
Custom distance metrics and smoothing kernels are supported.
|
Custom distance metrics and smoothing kernels are supported.
|
||||||
|
|
||||||
|
Demo: `demo/regressor_demo.py`
|
||||||
|
|
||||||
|
### Regressor description
|
||||||
|
|
||||||
|
Nadaraya-Watson kernel regressor is implemented.
|
||||||
|
|
||||||
|
Demo: `demo/classifier_demo.py`
|
||||||
|
|
||||||
### Neighbors search algorithm
|
### Neighbors search algorithm
|
||||||
|
|
||||||
Random projection forest is used to search for neighbours.
|
Random projection forest is used to search for neighbours.
|
||||||
|
|
||||||
RP trees are built by recursive binary splits of space by selected hyperplanes.
|
RP trees are built by recursive binary splits of space by selected hyperplanes.
|
||||||
|
|
||||||
On each step algorithm chooses two random objects from train set and calculates a hyperplane symmetrically separating these two objects in feature space.
|
On each step algorithm chooses two random objects from the train set
|
||||||
|
and calculates a hyperplane symmetrically separating these two objects in feature space.
|
||||||
Such hyperplanes become splitting nodes of an RP tree.
|
Such hyperplanes become splitting nodes of an RP tree.
|
||||||
|
|
||||||
Each resulting subset is split again if it contains more than `m` (hyperparameter) objects.
|
Each resulting subset is split again if it contains more than `m` (hyperparameter) objects.
|
||||||
@@ -52,6 +61,7 @@ Since nodes are organized into a tree, we can perform search by evaluating the e
|
|||||||
Import the package, for example, as
|
Import the package, for example, as
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
import neighbours as ns
|
import neighbours as ns
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -84,4 +94,4 @@ The only third-party dependency is `numpy`.
|
|||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
This project is licensed under [the MIT License](https://raw.githubusercontent.com/hashlag/neighbours/main/LICENSE)
|
This project is licensed under [the MIT License](https://raw.githubusercontent.com/hashlag/neighbours/main/LICENSE).
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
sys.path.append("../")
|
|
||||||
|
|
||||||
import neighbours as ns
|
import neighbours as ns
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import matplotlib.pyplot as plt
|
|
||||||
import neighbours as ns
|
import neighbours as ns
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import random
|
import random
|
||||||
import math
|
import math
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class KNNClassifier:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.features = features
|
self.features = features
|
||||||
self.forest = RPTForest(features, trees_count, rpt_m)
|
self.forest = RPForest(features, trees_count, rpt_m)
|
||||||
self.classes = None
|
self.classes = None
|
||||||
self.classes_count = classes_count
|
self.classes_count = classes_count
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ class KNNRegressor:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.features = features
|
self.features = features
|
||||||
self.forest = RPTForest(features, trees_count, rpt_m)
|
self.forest = RPForest(features, trees_count, rpt_m)
|
||||||
self.targets = None
|
self.targets = None
|
||||||
|
|
||||||
def load(self, points, targets):
|
def load(self, points, targets):
|
||||||
@@ -48,7 +48,7 @@ class LeafNode:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, ixs):
|
def __init__(self, ixs):
|
||||||
"""Creates new LeafNode with given set of point indexes
|
"""Creates new LeafNode with a given set of point indexes
|
||||||
|
|
||||||
:param ixs: list of point indexes
|
:param ixs: list of point indexes
|
||||||
"""
|
"""
|
||||||
@@ -56,8 +56,8 @@ class LeafNode:
|
|||||||
self.indexes = set(ixs)
|
self.indexes = set(ixs)
|
||||||
|
|
||||||
|
|
||||||
class RPTForest:
|
class RPForest:
|
||||||
"""Forest of random projection trees
|
"""Random projection forest
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
features: number of features in each sample
|
features: number of features in each sample
|
||||||
@@ -68,7 +68,7 @@ class RPTForest:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, features, trees_count, m):
|
def __init__(self, features, trees_count, m):
|
||||||
"""Creates new random projection tree forest
|
"""Creates new random projection forest
|
||||||
|
|
||||||
:param features: number of features in each sample
|
:param features: number of features in each sample
|
||||||
:param trees_count: number of trees in the forest
|
:param trees_count: number of trees in the forest
|
||||||
Reference in New Issue
Block a user