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.

Base.randMethod
rand(space::KncConfigSpace)

Creates a random KncConfig instance based on the space definition.

source
Base.randMethod
rand(space::KncProtoConfigSpace)

Creates a random KncProtoConfig instance based on the space definition.

source
KNearestCenters.change_criterionFunction
change_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.

source
KNearestCenters.classification_scoresMethod
classification_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.

source
KNearestCenters.f1_scoreMethod
f1_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
source
KNearestCenters.fun_criterionMethod
fun_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)
source
KNearestCenters.isqerrorMethod
isqerror(X::AbstractVector{F}, Y::AbstractVector{F}) where {F <: AbstractFloat}

Negative squared error (to be used for maximizing algorithms)

source
KNearestCenters.kfunMethod
kfun(kernel::CauchyKernel, d, σ::AbstractFloat)::Float64

Creates a Cauchy kernel with the given distance function

source
KNearestCenters.kfunMethod
kfun(kernel::DirectKernel, d, σ::AbstractFloat)::Float64

Creates a Direct kernel with the given distance function

source
KNearestCenters.kfunMethod
kfun(kernel::GaussianKernel, d, σ::AbstractFloat)::Float64

Creates a Gaussian kernel with the given distance function

source
KNearestCenters.kfunMethod
kfun(kernel::LaplacianKernel, d, σ::AbstractFloat)::Float64

Creates a Laplacian kernel with the given distance function

source
KNearestCenters.kfunMethod
kfun(kernel::ReluKernel, d, σ::AbstractFloat)::Float64

Creates a Relu kernel with the given distance function

source
KNearestCenters.kfunMethod
kfun(kernel::SigmoidKernel, d, σ::AbstractFloat)::Float64

Creates a Sigmoid kernel with the given distance function

source
KNearestCenters.kfunMethod
kfun(kernel::TanhKernel, d, σ::AbstractFloat)::Float64

Creates a Tanh kernel with the given distance function

source
KNearestCenters.precision_recallMethod
precision_recall(gold::AbstractVector, predicted::AbstractVector)

Computes the global and per-class precision and recall values between the gold standard and the predicted set

source
KNearestCenters.precision_scoreMethod
precision_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
source
KNearestCenters.recall_scoreMethod
recall_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
source
KNearestCenters.spearmanMethod
spearman(X::AbstractVector{F}, Y::AbstractVector{F}) where {F <: AbstractFloat}

Spearman rank correleation score

source
KNearestCenters.transformFunction
transform(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)

source
SearchModels.combineMethod
combine(a::KncConfig, b::KncConfig)

Creates a new configuration combining the given configurations

source
SearchModels.combineMethod
combine(a::KncProtoConfig, b::KncProtoConfig)

Creates a new configuration combining the given configurations

source
SearchModels.mutateMethod
mutate(space::KncProtoConfigSpace, a::KncProtoConfig, iter)

Creates a new configuration based on a slight perturbation of a

source
StatsAPI.fitMethod
fit(config::KncConfig, X, y::CategoricalArray; verbose=true)

Creates a Knc classifier using the given configuration and data.

source
StatsAPI.fitMethod
fit(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.

source
StatsAPI.fitMethod
fit(::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 request
  • index: the search structure see SimilaritySearch.jl
  • examples: a matrix that will be indexed using SimilaritySearch.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
source
StatsAPI.fitMethod
fit(::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 request
  • index: the search structure see SimilaritySearch.jl
  • labels: Categorical array of labels

Keyword arguments

  • k: the number of neighbors to be used.
  • weight: the neighbor weighting scheme.
source
StatsAPI.predictMethod
predict(nc::KncProto, x)

Predicts the class of x using the label of the k nearest centers

source
StatsAPI.predictMethod
predict(model::KnnModel, x)

Predict based on examples using the model, a KnnModel object.

Arguments:

  • model: The KnnModel struct.
  • x: A compatible object with the exemplars given to the model while fitting.
source