Skip to content

Commit fddbe17

Browse files
authored
KnnClassifier: Proofreading the documentation (#222)
1 parent fddc51e commit fddbe17

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 16.10.5
4+
- KnnClassifier:
5+
- Proofreading the documentation
6+
37
## 16.10.4
48
- DecisionTreeClassifier:
59
- Proofreading the documentation

lib/src/classifier/knn_classifier/knn_classifier.dart

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ import 'package:ml_dataframe/ml_dataframe.dart';
1010
import 'package:ml_linalg/distance.dart';
1111
import 'package:ml_linalg/dtype.dart';
1212

13-
/// A class that performs classification basing on `k nearest neighbours` (KNN)
13+
/// A class that performs classification based on `k nearest neighbours` (KNN)
1414
/// algorithm
1515
///
16-
/// K nearest neighbours algorithm is an algorithm that is targeted to search for
17-
/// the most similar labelled observations (number of these observations is equal
18-
/// to `k`) to the given unlabelled one.
16+
/// K nearest neighbours algorithm is an algorithm that is targeted to search
17+
/// for the most similar k observations to the given one.
1918
///
20-
/// It is possible to use majority class among the `k` found observations as a
21-
/// prediction for the given unlabelled observation, but it may lead to the
22-
/// imprecise result. Thus the weighted version of KNN algorithm is used in the
23-
/// classifier. To get weight of a particular observation one may use a kernel
24-
/// function.
19+
/// It is possible to use the majority class among the `k` found observations
20+
/// as a prediction for the given unlabelled observation, but it may lead to an
21+
/// imprecise result. To overcome this, the weighted version of KNN algorithm
22+
/// is used in the classifier. To get the weight of a particular observation
23+
/// one may use a kernel function.
2524
abstract class KnnClassifier
2625
implements
2726
Assessable,
@@ -35,17 +34,15 @@ abstract class KnnClassifier
3534
/// [targetName] A string that serves as a name of the column containing
3635
/// outcomes.
3736
///
38-
/// [k] a number of nearest neighbours to be found among [trainData]
37+
/// [k] A number of nearest neighbours to be found among [trainData]
3938
///
40-
/// [kernel] a type of a kernel function that is used to predict an
41-
/// outcome for a new observation
39+
/// [kernel] A kernel function that will be used to predict an outcome for a
40+
/// new observation
4241
///
43-
/// [distance] a distance type that is used to measure a distance between two
44-
/// observation vectors
42+
/// [distance] A way to measure a distance between two observation vectors
4543
///
46-
/// [dtype] A data type for all the numeric values, used by the algorithm. Can
47-
/// affect performance or accuracy of the computations. Default value is
48-
/// [DType.float32]
44+
/// [dtype] A data type for all the numeric values, used by the algorithm.
45+
/// Default value is [DType.float32]
4946
factory KnnClassifier(
5047
DataFrame trainData,
5148
String targetName,
@@ -95,8 +92,7 @@ abstract class KnnClassifier
9592
/// final json = await file.readAsString();
9693
/// final restoredClassifier = KnnClassifier.fromJson(json);
9794
///
98-
/// // here you can use previously fitted restored classifier to make
99-
/// // some prediction, e.g. via `KnnClassifier.predict(...)`;
95+
/// // here you can use previously fitted restored classifier
10096
/// ````
10197
factory KnnClassifier.fromJson(String json) =>
10298
initKnnClassifierModule().get<KnnClassifierFactory>().fromJson(json);
@@ -106,13 +102,12 @@ abstract class KnnClassifier
106102
/// The value is read-only, it's a hyperparameter of the model
107103
int get k;
108104

109-
/// A kernel type
105+
/// A kernel function type
110106
///
111107
/// The value is read-only, it's a hyperparameter of the model
112108
KernelType get kernelType;
113109

114-
/// A distance type that is used to measure a distance between two
115-
/// observations
110+
/// A distance type that is used to measure how far are observations from each other
116111
///
117112
/// The value is read-only, it's a hyperparameter of the model
118113
Distance get distanceType;

lib/src/knn_kernel/kernel_type.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// A type of kernel function.
1+
/// A type of a kernel function.
22
///
33
/// Defines a way the weights of the nearest observations are being calculated
44
/// for K nearest neighbours algorithm (KNN).
@@ -11,31 +11,31 @@
1111
/// returns a weight denoting, how much the evaluating observation will
1212
/// contribute in prediction for the target one.
1313
enum KernelType {
14-
/// A kernel, that calculates weights, using the following formula:
14+
/// A kernel that calculates weights using the following formula:
1515
///
1616
///
17-
/// ![K(x)=\left\{\begin{matrix}1/2, & |x|\leqslant \lambda \\ 0, & |x|> \lambda \end{matrix}\right](https://latex.codecogs.com/png.latex?K%28x%29%3D%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D1/2%2C%20%26%20%7Cx%7C%5Cleqslant%20%5Clambda%20%5C%5C%200%2C%20%26%20%7Cx%7C%3E%20%5Clambda%20%5Cend%7Bmatrix%7D%5Cright)
17+
/// ![K(x,\lambda)=\left\{\begin{matrix}1/2,&|x|\leqslant\lambda\\0,&|x|>\lambda\end{matrix}\right.](https://latex.codecogs.com/svg.image?K(x,%5Clambda)=%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D1/2,&%7Cx%7C%5Cleqslant%5Clambda%5C%5C0,&%7Cx%7C%3E%5Clambda%5Cend%7Bmatrix%7D%5Cright.)
1818
///
1919
///
2020
uniform,
2121

22-
/// A kernel, that calculates weights, using the following formula:
22+
/// A kernel that calculates weights using the following formula:
2323
///
2424
///
25-
/// ![K(x)=\left\{\begin{matrix}3/4(1 - x^{2}), & |x|\leqslant \lambda \\ 0, & |x|> \lambda \end{matrix}\right](https://latex.codecogs.com/png.latex?K%28x%29%3D%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D3/4%281%20-%20x%5E%7B2%7D%29%2C%20%26%20%7Cx%7C%5Cleqslant%20%5Clambda%20%5C%5C%200%2C%20%26%20%7Cx%7C%3E%20%5Clambda%20%5Cend%7Bmatrix%7D%5Cright)
25+
/// ![K(x,\lambda)=\left\{\begin{matrix}3/4(1-x^{2}),&|x|\leqslant\lambda\\0,&|x|>\lambda\end{matrix}\right.](https://latex.codecogs.com/svg.image?K(x,%5Clambda)=%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D3/4(1-x%5E%7B2%7D),&%7Cx%7C%5Cleqslant%5Clambda%5C%5C0,&%7Cx%7C%3E%5Clambda%5Cend%7Bmatrix%7D%5Cright.)
2626
///
2727
///
2828
epanechnikov,
2929

30-
/// A kernel, that calculates weights, using the following formula:
30+
/// A kernel that calculates weights using the following formula:
3131
///
3232
///
33-
/// ![K(x)=\left\{\begin{matrix} 0.25\pi cos(0.5\pi x) & |x|\leqslant \lambda \\ 0, & |x|>\lambda \end{matrix}\right](https://latex.codecogs.com/png.latex?K%28x%29%3D%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D%200.25%5Cpi%20cos%280.5%5Cpi%20x%29%20%26%20%7Cx%7C%5Cleqslant%20%5Clambda%20%5C%5C%200%2C%20%26%20%7Cx%7C%3E%5Clambda%20%5Cend%7Bmatrix%7D%5Cright)
33+
/// ![K(x,\lambda)=\left\{\begin{matrix} 0.25\pi cos(0.5\pi x), & |x|\leqslant \lambda \\ 0, & |x|>\lambda \end{matrix}\right.](https://latex.codecogs.com/svg.image?K(x,%5Clambda)=%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D%200.25%5Cpi%20cos(0.5%5Cpi%20x),%20&%20%7Cx%7C%5Cleqslant%20%5Clambda%20%5C%5C%200,%20&%20%7Cx%7C%3E%5Clambda%20%5Cend%7Bmatrix%7D%5Cright.)
3434
///
3535
///
3636
cosine,
3737

38-
/// A kernel, that calculates weights, using the following formula:
38+
/// A kernel that calculates weights using the following formula:
3939
///
4040
///
4141
/// ![K(x)=\frac{1 }{\sqrt{2\pi }} e^{-\frac{1}{2}x^{2}}](https://latex.codecogs.com/png.latex?K%28x%29%3D%5Cfrac%7B1%20%7D%7B%5Csqrt%7B2%5Cpi%20%7D%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7Dx%5E%7B2%7D%7D)

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: ml_algo
22
description: Machine learning algorithms, Machine learning models performance evaluation functionality
3-
version: 16.10.4
3+
version: 16.10.5
44
homepage: https://github.com/gyrdym/ml_algo
55

66
environment:

0 commit comments

Comments
 (0)