KNearestCenters
KNearestCenters.KncKNearestCenters.KncKNearestCenters.KncConfigSpaceDistances.evaluateDistances.evaluateDistances.evaluateDistances.evaluateDistances.evaluateDistances.evaluateDistances.evaluateKNearestCenters.accuracy_scoreKNearestCenters.change_criterionKNearestCenters.classification_scoresKNearestCenters.combine_configurationsKNearestCenters.epsilon_criterionKNearestCenters.f1_scoreKNearestCenters.fun_criterionKNearestCenters.isqerrorKNearestCenters.mean_labelKNearestCenters.most_frequent_labelKNearestCenters.pearsonKNearestCenters.precision_recallKNearestCenters.precision_scoreKNearestCenters.random_configurationKNearestCenters.recall_scoreKNearestCenters.salesman_criterionKNearestCenters.size_criterionKNearestCenters.softmax!KNearestCenters.spearmanKNearestCenters.transformStatsBase.predict
KNearestCenters.Knc — TypeA simple nearest centroid classifier with support for kernel functions
KNearestCenters.Knc — MethodKnc(config::KncConfig, X, y::CategoricalArray; verbose=true)
Knc(config::KncConfig,
input_clusters::ClusteringData,
train_X::AbstractVector,
train_y::CategoricalArray;
verbose=false
)Creates a Knc classifier using the given configuration and data.
KNearestCenters.KncConfigSpace — MethodKncConfigSpace(;
kernel::Array=[k_(d_()) for k_ in [DirectKernel, ReluKernel],
d_ in [L2Distance, CosineDistance]],
centerselection::AbstractVector=[CentroidSelection(), RandomCenterSelection(), MedoidSelection(), KnnCentroidSelection()],
k::AbstractVector=[1],
maxiters::AbstractVector=[1, 3, 10],
recall::AbstractVector=[1.0],
ncenters::AbstractVector=[0, 10],
initial_clusters::AbstractVector=[:fft, :dnet, :rand],
split_entropy::AbstractVector=[0.3, 0.6, 0.9],
minimum_elements_per_region::AbstractVector=[1, 3, 5]
)Creates a configuration space for KncConfig
Distances.evaluate — Methodevaluate(kernel::CauchyKernel, a, b, σ::AbstractFloat)::Float64Creates a Cauchy kernel with the given distance function
Distances.evaluate — Methodevaluate(kernel::DirectKernel, a, b, σ::AbstractFloat)::Float64Creates a Direct kernel with the given distance function
Distances.evaluate — Methodevaluate(kernel::GaussianKernel, a, b, σ::AbstractFloat)::Float64Creates a Gaussian kernel with the given distance function
Distances.evaluate — Methodevaluate(kernel::LaplacianKernel, a, b, σ::AbstractFloat)::Float64Creates a Laplacian kernel with the given distance function
Distances.evaluate — Methodevaluate(kernel::ReluKernel, a, b, σ::AbstractFloat)::Float64Creates a Relu kernel with the given distance function
Distances.evaluate — Methodevaluate(kernel::SigmoidKernel, a, b, σ::AbstractFloat)::Float64Creates a Sigmoid kernel with the given distance function
Distances.evaluate — Methodevaluate(kernel::TanhKernel, a, b, σ::AbstractFloat)::Float64Creates a Tanh kernel with the given distance function
KNearestCenters.accuracy_score — Methodaccuracy_score(gold::T, predicted::T) where TComputes 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)Computes several scores for the given gold-standard and predictions, namely: precision, recall, and f1 scores, for global and per-class granularity
KNearestCenters.combine_configurations — Methodcombine_configurations(::Type{T}, config_list) where {T<:KncConfig}Creates a new configuration combining the given configurations
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, predict; weight=:macro)::Float64It computes the F1 score between the gold dataset and the list of predictions predict
It applies the desired weighting scheme for binary and multiclass problems
:macroperforms a uniform weigth to each class:weigthedthe weight of each class is proportional to its population in gold:microreturns 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.mean_label — Methodmean_label(nc::Knc, res::KnnResult)Summary function that computes the label as the mean of the k nearest labels (ordinal classification)
KNearestCenters.most_frequent_label — Methodmost_frequent_label(nc::Knc, res::KnnResult)Summary function that computes the label as the most frequent label among labels of the k nearest prototypes (categorical labels)
KNearestCenters.pearson — Methodpearson(X::AbstractVector{F}, Y::AbstractVector{F}) where {F <: AbstractFloat}Pearson correlation score
KNearestCenters.precision_recall — Methodprecision_recall(gold::AbstractVector{T1}, predicted::AbstractVector{T2}) where {T1<:Integer} where {T2<:IntegerComputes the global and per-class precision and recall values between the gold standard and the predicted set
KNearestCenters.precision_score — Methodprecision_score(gold, predict; weight=:macro)::Float64It computes the precision between the gold dataset and the list of predictions predict
It applies the desired weighting scheme for binary and multiclass problems
:macroperforms a uniform weigth to each class:weigthedthe weight of each class is proportional to its population in gold:microreturns the global precision, without distinguishing among classes
KNearestCenters.random_configuration — Methodrandom_configuration(space::KncConfigSpace)Creates a random KncConfig instance based on the space definition.
KNearestCenters.recall_score — Methodrecall_score(gold, predict; weight=:macro)::Float64It computes the recall between the gold dataset and the list of predictions predict
It applies the desired weighting scheme for binary and multiclass problems
:macroperforms a uniform weigth to each class:weigthedthe weight of each class is proportional to its population in gold:microreturns 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)
StatsBase.predict — Methodpredict(nc::Knc, x, res::KnnResult)
predict(nc::Knc, x)Predicts the class of x using the label of the k nearest centers under the kernel function.