upd README.md, refactor

This commit is contained in:
hashlag
2024-02-04 21:20:00 +03:00
parent d8a96bedbc
commit 59423546ea
10 changed files with 20 additions and 14 deletions

View File

@@ -1,6 +1,6 @@
# 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
@@ -19,13 +19,22 @@ Built-in distance metrics:
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
Random projection forest is used to search for neighbours.
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.
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
```python
import neighbours as ns
```
@@ -84,4 +94,4 @@ The only third-party dependency is `numpy`.
### 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).

View File

@@ -1,7 +1,3 @@
import sys
sys.path.append("../")
import neighbours as ns
import numpy as np

View File

@@ -1,6 +1,6 @@
import matplotlib.pyplot as plt
import neighbours as ns
import matplotlib.pyplot as plt
import numpy as np
import random
import math

View File

@@ -28,7 +28,7 @@ class KNNClassifier:
"""
self.features = features
self.forest = RPTForest(features, trees_count, rpt_m)
self.forest = RPForest(features, trees_count, rpt_m)
self.classes = None
self.classes_count = classes_count

View File

@@ -26,7 +26,7 @@ class KNNRegressor:
"""
self.features = features
self.forest = RPTForest(features, trees_count, rpt_m)
self.forest = RPForest(features, trees_count, rpt_m)
self.targets = None
def load(self, points, targets):

View File

@@ -48,7 +48,7 @@ class LeafNode:
"""
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
"""
@@ -56,8 +56,8 @@ class LeafNode:
self.indexes = set(ixs)
class RPTForest:
"""Forest of random projection trees
class RPForest:
"""Random projection forest
Attributes:
features: number of features in each sample
@@ -68,7 +68,7 @@ class RPTForest:
"""
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 trees_count: number of trees in the forest