KNearestCenters
The KNearestCenters package contains classification algorithms based on prototype selection and feature mapping through kernel functions. It model selection to improve the classification performance.
KNearestCenters.Knc
KNearestCenters.KncProto
Base.rand
Base.rand
KNearestCenters.accuracy_score
KNearestCenters.change_criterion
KNearestCenters.classification_scores
KNearestCenters.epsilon_criterion
KNearestCenters.f1_score
KNearestCenters.fun_criterion
KNearestCenters.isqerror
KNearestCenters.kfun
KNearestCenters.kfun
KNearestCenters.kfun
KNearestCenters.kfun
KNearestCenters.kfun
KNearestCenters.kfun
KNearestCenters.kfun
KNearestCenters.pearson
KNearestCenters.precision_recall
KNearestCenters.precision_score
KNearestCenters.predict_raw
KNearestCenters.recall_score
KNearestCenters.salesman_criterion
KNearestCenters.size_criterion
KNearestCenters.softmax!
KNearestCenters.spearman
KNearestCenters.transform
SearchModels.combine
SearchModels.combine
SearchModels.mutate
StatsAPI.fit
StatsAPI.fit
StatsAPI.fit
StatsAPI.fit
StatsAPI.predict
StatsAPI.predict
KNearestCenters.Knc
— TypeA nearest centroid classifier with support for kernel functions
KNearestCenters.KncProto
— TypeA simple nearest centroid classifier
Base.rand
— Methodrand(space::KncConfigSpace)
Creates a random KncConfig
instance based on the space
definition.
Base.rand
— Methodrand(space::KncProtoConfigSpace)
Creates a random KncProtoConfig
instance based on the space
definition.
KNearestCenters.accuracy_score
— Methodaccuracy_score(gold, predicted)
Computes the accuracy score between the gold and the predicted sets
KNearestCenters.change_criterion
— Functionchange_criterion(tol=0.001, window=3)
Creates a fuction that stops the process whenever the maximum distance converges (averaging window
far items). The tol
parameter defines the tolerance range.
KNearestCenters.classification_scores
— Methodclassification_scores(gold, predicted; labelnames=nothing)
Computes several scores for the given gold-standard and predictions, namely: precision, recall, and f1 scores, for global and per-class granularity. If labelnames is given, then it is an array of label names.
KNearestCenters.epsilon_criterion
— Methodepsilon_criterion(e)
Creates a function that evaluates the stop criterion when the distance between far items achieves the given e
KNearestCenters.f1_score
— Methodf1_score(gold, predicted; weight=:macro)::Float64
It computes the F1 score between the gold dataset and the list of predictions predicted
It applies the desired weighting scheme for binary and multiclass problems
:macro
performs a uniform weigth to each class:weigthed
the weight of each class is proportional to its population in gold:micro
returns the global F1, without distinguishing among classes
KNearestCenters.fun_criterion
— Methodfun_criterion(fun::Function)
Creates a stop-criterion function that stops whenever the number of far items reaches $\lceil fun(|database|)\rceil$. Already defined examples:
sqrt_criterion() = fun_criterion(sqrt)
log2_criterion() = fun_criterion(log2)
KNearestCenters.isqerror
— Methodisqerror(X::AbstractVector{F}, Y::AbstractVector{F}) where {F <: AbstractFloat}
Negative squared error (to be used for maximizing algorithms)
KNearestCenters.kfun
— Methodkfun(kernel::CauchyKernel, d, σ::AbstractFloat)::Float64
Creates a Cauchy kernel with the given distance function
KNearestCenters.kfun
— Methodkfun(kernel::DirectKernel, d, σ::AbstractFloat)::Float64
Creates a Direct kernel with the given distance function
KNearestCenters.kfun
— Methodkfun(kernel::GaussianKernel, d, σ::AbstractFloat)::Float64
Creates a Gaussian kernel with the given distance function
KNearestCenters.kfun
— Methodkfun(kernel::LaplacianKernel, d, σ::AbstractFloat)::Float64
Creates a Laplacian kernel with the given distance function
KNearestCenters.kfun
— Methodkfun(kernel::ReluKernel, d, σ::AbstractFloat)::Float64
Creates a Relu kernel with the given distance function
KNearestCenters.kfun
— Methodkfun(kernel::SigmoidKernel, d, σ::AbstractFloat)::Float64
Creates a Sigmoid kernel with the given distance function
KNearestCenters.kfun
— Methodkfun(kernel::TanhKernel, d, σ::AbstractFloat)::Float64
Creates a Tanh kernel with the given distance function
KNearestCenters.pearson
— Methodpearson(X::AbstractVector{F}, Y::AbstractVector{F}) where {F <: AbstractFloat}
Pearson correlation score
KNearestCenters.precision_recall
— Methodprecision_recall(gold::AbstractVector, predicted::AbstractVector)
Computes the global and per-class precision and recall values between the gold standard and the predicted set
KNearestCenters.precision_score
— Methodprecision_score(gold, predicted; weight=:macro)::Float64
It computes the precision between the gold dataset and the list of predictions predict
It applies the desired weighting scheme for binary and multiclass problems
:macro
performs a uniform weigth to each class:weigthed
the weight of each class is proportional to its population in gold:micro
returns the global precision, without distinguishing among classes
KNearestCenters.predict_raw
— Methodpredict_raw(model::KnnModel, x)
Computes the correspoding vectors without any normalization (or determining the label).
KNearestCenters.recall_score
— Methodrecall_score(gold, predicted; weight=:macro)::Float64
It computes the recall between the gold dataset and the list of predictions predict
It applies the desired weighting scheme for binary and multiclass problems
:macro
performs a uniform weigth to each class:weigthed
the weight of each class is proportional to its population in gold:micro
returns the global recall, without distinguishing among classes
KNearestCenters.salesman_criterion
— Methodsalesman_criterion()
It creates a function that explores the entire dataset making a full farthest first traversal approximation
KNearestCenters.size_criterion
— Methodsize_criterion(maxsize)
Creates a function that stops when the number of far items are equal or larger than the given maxsize
KNearestCenters.softmax!
— Methodsoftmax!(vec::AbstractVector)
Inline computation of the softmax function on the input vector
KNearestCenters.spearman
— Methodspearman(X::AbstractVector{F}, Y::AbstractVector{F}) where {F <: AbstractFloat}
Spearman rank correleation score
KNearestCenters.transform
— Functiontransform(nc::Knc, kernel::Function, X, normalize!::Function=softmax!)
Maps a collection of objects to the vector space defined by each center in nc
; the kernel
function is used measure the similarity between each $u \in X$ and each center in nc. The normalization function is applied to each vector (normalization methods needing to know the attribute's distribution can be applied on the output of transform
)
SearchModels.combine
— Methodcombine(a::KncConfig, b::KncConfig)
Creates a new configuration combining the given configurations
SearchModels.combine
— Methodcombine(a::KncProtoConfig, b::KncProtoConfig)
Creates a new configuration combining the given configurations
SearchModels.mutate
— Methodmutate(space::KncProtoConfigSpace, a::KncProtoConfig, iter)
Creates a new configuration based on a slight perturbation of a
StatsAPI.fit
— Methodfit(config::KncConfig, X, y::CategoricalArray; verbose=true)
Creates a Knc classifier using the given configuration and data.
StatsAPI.fit
— Methodfit(config::KncProtoConfig, X, y::CategoricalArray; verbose=true)
fit(config::KncProtoConfig,
input_clusters::ClusteringData,
train_X::AbstractVector,
train_y::CategoricalArray;
verbose=false
)
Creates a KncProto classifier using the given configuration and data.
StatsAPI.fit
— Methodfit(::Type{KnnModel}, index::AbstractSearchIndex, meta::AbstractVecOrMat{<:Real}; k=3, weight=KnnUniformWeightKernel(), prediction=KnnSoftmaxPrediction())
fit(::Type{KnnModel}, examples::AbstractMatrix, meta::AbstractVecOrMat{<:Real}; k=3, weight=KnnUniformWeightKernel(), prediction=KnnSoftmaxPrediction(), dist=L2Distance())
Creates a new KnnModel
classifier with the examples indexed by index
and it associated labels
Arguments:
KnnModel
: the type to dispatch the fit requestindex
: the search structure seeSimilaritySearch.jl
examples
: a matrix that will be indexed usingSimilaritySearch.jl
meta
: numerical associated data
Keyword arguments
k
: the number of neighbors to be used.weight
: the neighbor weighting scheme.dist
: distance function to be used
StatsAPI.fit
— Methodfit(::Type{KnnModel}, index::AbstractSearchIndex, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel())
Creates a new KnnModel
classifier with the examples indexed by index
and it associated labels
Arguments:
KnnModel
: the type to dispatch the fit requestindex
: the search structure seeSimilaritySearch.jl
labels
: Categorical array of labels
Keyword arguments
k
: the number of neighbors to be used.weight
: the neighbor weighting scheme.
StatsAPI.predict
— Methodpredict(nc::KncProto, x)
Predicts the class of x
using the label of the k
nearest centers
StatsAPI.predict
— Methodpredict(model::KnnModel, x)
Predict based on examples using the model
, a KnnModel
object.
Arguments:
model
: TheKnnModel
struct.x
: A compatible object with the exemplars given to themodel
while fitting.