KnnClassifier class abstract

A class that performs classification based on k nearest neighbours (KNN) algorithm

K nearest neighbours algorithm is an algorithm that is targeted to search for the most similar k observations to the given one.

It is possible to use the majority class among the k found observations as a prediction for the given unlabelled observation, but it may lead to an imprecise result. To overcome this, the weighted version of KNN algorithm is used in the classifier. To get the weight of a particular observation one may use a kernel function.

Constructors

KnnClassifier(DataFrame trainData, String targetName, int k, {KernelType kernel = KernelType.gaussian, Distance distance = Distance.euclidean, String classLabelPrefix = 'Class label', DType dtype = dTypeDefaultValue})
Parameters:
factory
KnnClassifier.fromJson(String json)
Restores previously fitted classifier instance from the given json
factory

Properties

distanceType Distance
A distance type that is used to measure how far are observations from each other
no setter
dtype DType
A type for all numeric values using by the Predictor
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
k int
A number of nearest neighbours
no setter
kernelType KernelType
A kernel function type
no setter
negativeLabel num
A value using to encode negative class.
no setterinherited
positiveLabel num
A value using to encode positive class.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
schemaVersion int?
Contains a version of the current json schema
no setterinherited
targetNames Iterable<String>
A collection of target column names of a dataset which was used to learn the ML model
no setterinherited

Methods

assess(DataFrame observations, MetricType metricType) double
Assesses model performance according to provided metricType
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
predict(DataFrame testFeatures) → DataFrame
Returns prediction, based on the learned coefficients
inherited
predictProbabilities(DataFrame testFeatures) → DataFrame
Returns predicted distribution of probabilities for each observation in the passed testFeatures
inherited
retrain(DataFrame data) KnnClassifier
Re-runs the learning process on the new training data. The features, model algorithm, and hyperparameters remain the same.
inherited
saveAsJson(String filePath) Future<File>
Saves a json-serializable map into a newly created file with the path filePath
inherited
toJson() Map<String, dynamic>
Returns a json-serializable map
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited