Convenience methods
MLJModelInterface.table
— Functiontable(columntable; prototype=nothing)
Convert a named tuple of vectors or tuples columntable
, into a table of the "preferred sink type" of prototype
. This is often the type of prototype
itself, when prototype
is a sink; see the Tables.jl documentation. If prototype
is not specified, then a named tuple of vectors is returned.
table(A::AbstractMatrix; names=nothing, prototype=nothing)
Wrap an abstract matrix A
as a Tables.jl compatible table with the specified column names
(a tuple of symbols). If names
are not specified, names=(:x1, :x2, ..., :xn)
is used, where n=size(A, 2)
.
If a prototype
is specified, then the matrix is materialized as a table of the preferred sink type of prototype
, rather than wrapped. Note that if prototype
is not specified, then matrix(table(A))
is essentially a no-op.
MLJModelInterface.matrix
— Functionmatrix(X; transpose=false)
If X isa AbstractMatrix
, return X
or permutedims(X)
if transpose=true
. Otherwise if X
is a Tables.jl compatible table source, convert X
into a Matrix
.
MLJModelInterface.int
— Functionint(x)
The positional integer of the CategoricalString
or CategoricalValue
x
, in the ordering defined by the pool of x
. The type of int(x)
is the reference type of x
.
Not to be confused with x.ref
, which is unchanged by reordering of the pool of x
, but has the same type.
int(X::CategoricalArray)
+Convenience methods · MLJModelInterface Convenience methods
MLJModelInterface.table
— Functiontable(columntable; prototype=nothing)
Convert a named tuple of vectors or tuples columntable
, into a table of the "preferred sink type" of prototype
. This is often the type of prototype
itself, when prototype
is a sink; see the Tables.jl documentation. If prototype
is not specified, then a named tuple of vectors is returned.
table(A::AbstractMatrix; names=nothing, prototype=nothing)
Wrap an abstract matrix A
as a Tables.jl compatible table with the specified column names
(a tuple of symbols). If names
are not specified, names=(:x1, :x2, ..., :xn)
is used, where n=size(A, 2)
.
If a prototype
is specified, then the matrix is materialized as a table of the preferred sink type of prototype
, rather than wrapped. Note that if prototype
is not specified, then matrix(table(A))
is essentially a no-op.
sourceMLJModelInterface.matrix
— Functionmatrix(X; transpose=false)
If X isa AbstractMatrix
, return X
or permutedims(X)
if transpose=true
. Otherwise if X
is a Tables.jl compatible table source, convert X
into a Matrix
.
sourceMLJModelInterface.int
— Functionint(x)
The positional integer of the CategoricalString
or CategoricalValue
x
, in the ordering defined by the pool of x
. The type of int(x)
is the reference type of x
.
Not to be confused with x.ref
, which is unchanged by reordering of the pool of x
, but has the same type.
int(X::CategoricalArray)
int(W::Array{<:CategoricalString})
int(W::Array{<:CategoricalValue})
Broadcasted versions of int
.
julia> v = categorical(["c", "b", "c", "a"])
4-element CategoricalArrays.CategoricalArray{String,1,UInt32}:
@@ -19,7 +19,7 @@
0x00000003
0x00000002
0x00000003
- 0x00000001
See also: decoder
.
sourceMLJModelInterface.UnivariateFinite
— FunctionUnivariateFinite(
+ 0x00000001
See also: decoder
.
sourceMLJModelInterface.UnivariateFinite
— FunctionUnivariateFinite(
support,
probs;
pool=nothing,
@@ -79,7 +79,7 @@
UnivariateFinite{Multiclass{4}}(x=>0.727, y=>0.234, z=>0.0391)
UnivariateFinite{Multiclass{4}}(x=>0.674, y=>0.00535, z=>0.321)
⋮
- UnivariateFinite{Multiclass{4}}(x=>0.292, y=>0.339, z=>0.369)
Probability augmentation
If augment=true
the provided array is augmented by inserting appropriate elements ahead of those provided, along the last dimension of the array. This means the user only provides probabilities for the classes c2, c3, ..., cn
. The class c1
probabilities are chosen so that each UnivariateFinite
distribution in the returned array is a bona fide probability distribution.
UnivariateFinite(prob_given_class; pool=nothing, ordered=false)
Construct a discrete univariate distribution whose finite support is the set of keys of the provided dictionary, prob_given_class
, and whose values specify the corresponding probabilities.
The type requirements on the keys of the dictionary are the same as the elements of support
given above with this exception: if non-categorical elements (raw labels) are used as keys, then pool=...
must be specified and cannot be missing
.
If the values (probabilities) are arrays instead of scalars, then an abstract array of UnivariateFinite
elements is created, with the same size as the array.
sourceMLJModelInterface.classes
— Functionclasses(x)
All the categorical elements with the same pool as x
(including x
), returned as a list, with an ordering consistent with the pool. Here x
has CategoricalValue
type, and classes(x)
is a vector of the same eltype. Note that x in classes(x)
is always true.
Not to be confused with levels(x.pool)
. See the example below.
julia> v = categorical(["c", "b", "c", "a"])
+ UnivariateFinite{Multiclass{4}}(x=>0.292, y=>0.339, z=>0.369)
Probability augmentation
If augment=true
the provided array is augmented by inserting appropriate elements ahead of those provided, along the last dimension of the array. This means the user only provides probabilities for the classes c2, c3, ..., cn
. The class c1
probabilities are chosen so that each UnivariateFinite
distribution in the returned array is a bona fide probability distribution.
UnivariateFinite(prob_given_class; pool=nothing, ordered=false)
Construct a discrete univariate distribution whose finite support is the set of keys of the provided dictionary, prob_given_class
, and whose values specify the corresponding probabilities.
The type requirements on the keys of the dictionary are the same as the elements of support
given above with this exception: if non-categorical elements (raw labels) are used as keys, then pool=...
must be specified and cannot be missing
.
If the values (probabilities) are arrays instead of scalars, then an abstract array of UnivariateFinite
elements is created, with the same size as the array.
sourceMLJModelInterface.classes
— Functionclasses(x)
All the categorical elements with the same pool as x
(including x
), returned as a list, with an ordering consistent with the pool. Here x
has CategoricalValue
type, and classes(x)
is a vector of the same eltype. Note that x in classes(x)
is always true.
Not to be confused with levels(x.pool)
. See the example below.
julia> v = categorical(["c", "b", "c", "a"])
4-element CategoricalArrays.CategoricalArray{String,1,UInt32}:
"c"
"b"
@@ -105,7 +105,7 @@
3-element Vector{String}:
"a"
"b"
- "c"
sourceMLJModelInterface.decoder
— Functiondecoder(x)
Return a callable object for decoding the integer representation of a CategoricalValue
sharing the same pool the CategoricalValue
x
. Specifically, one has decoder(x)(int(y)) == y
for all CategoricalValue
s y
having the same pool as x
. One can also call decoder(x)
on integer arrays, in which case decoder(x)
is broadcast over all elements.
Examples
julia> v = categorical(["c", "b", "c", "a"])
+ "c"
sourceMLJModelInterface.decoder
— Functiondecoder(x)
Return a callable object for decoding the integer representation of a CategoricalValue
sharing the same pool the CategoricalValue
x
. Specifically, one has decoder(x)(int(y)) == y
for all CategoricalValue
s y
having the same pool as x
. One can also call decoder(x)
on integer arrays, in which case decoder(x)
is broadcast over all elements.
Examples
julia> v = categorical(["c", "b", "c", "a"])
4-element CategoricalArrays.CategoricalArray{String,1,UInt32}:
"c"
"b"
@@ -122,7 +122,7 @@
julia> d = decoder(v[3]);
julia> d(int(v)) == v
-true
Warning:
It is not true that int(d(u)) == u
always holds.
See also: int
.
sourceMLJModelInterface.select
— Functionselect(X, r, c)
Select element(s) of a table or matrix at row(s) r
and column(s) c
. An object of the sink type of X
(or a matrix) is returned unless c
is a single integer or symbol. In that case a vector is returned, unless r
is a single integer, in which case a single element is returned.
See also: selectrows
, selectcols
.
sourceMLJModelInterface.selectrows
— Functionselectrows(X, r)
Select single or multiple rows from a table, abstract vector or matrix X
. If X
is tabular, the object returned is a table of the preferred sink type of typeof(X)
, even if only a single row is selected.
If the object is neither a table, abstract vector or matrix, X
is returned and r
is ignored.
sourceMLJModelInterface.selectcols
— Functionselectcols(X, c)
Select single or multiple columns from a matrix or table X
. If c
is an abstract vector of integers or symbols, then the object returned is a table of the preferred sink type of typeof(X)
. If c
is a single integer or column, then an AbstractVector
is returned.
sourceMLJModelInterface.UnivariateFinite
— Functionsource MLJModelInterface.select
— Functionselect(X, r, c)
Select element(s) of a table or matrix at row(s) r
and column(s) c
. An object of the sink type of X
(or a matrix) is returned unless c
is a single integer or symbol. In that case a vector is returned, unless r
is a single integer, in which case a single element is returned.
See also: selectrows
, selectcols
.
sourceMLJModelInterface.selectrows
— Functionselectrows(X, r)
Select single or multiple rows from a table, abstract vector or matrix X
. If X
is tabular, the object returned is a table of the preferred sink type of typeof(X)
, even if only a single row is selected.
If the object is neither a table, abstract vector or matrix, X
is returned and r
is ignored.
sourceMLJModelInterface.selectcols
— Functionselectcols(X, c)
Select single or multiple columns from a matrix or table X
. If c
is an abstract vector of integers or symbols, then the object returned is a table of the preferred sink type of typeof(X)
. If c
is a single integer or column, then an AbstractVector
is returned.
sourceMLJModelInterface.UnivariateFinite
— FunctionUnivariateFinite(
support,
probs;
pool=nothing,
@@ -182,4 +182,4 @@
UnivariateFinite{Multiclass{4}}(x=>0.727, y=>0.234, z=>0.0391)
UnivariateFinite{Multiclass{4}}(x=>0.674, y=>0.00535, z=>0.321)
⋮
- UnivariateFinite{Multiclass{4}}(x=>0.292, y=>0.339, z=>0.369)
Probability augmentation
If augment=true
the provided array is augmented by inserting appropriate elements ahead of those provided, along the last dimension of the array. This means the user only provides probabilities for the classes c2, c3, ..., cn
. The class c1
probabilities are chosen so that each UnivariateFinite
distribution in the returned array is a bona fide probability distribution.
UnivariateFinite(prob_given_class; pool=nothing, ordered=false)
Construct a discrete univariate distribution whose finite support is the set of keys of the provided dictionary, prob_given_class
, and whose values specify the corresponding probabilities.
The type requirements on the keys of the dictionary are the same as the elements of support
given above with this exception: if non-categorical elements (raw labels) are used as keys, then pool=...
must be specified and cannot be missing
.
If the values (probabilities) are arrays instead of scalars, then an abstract array of UnivariateFinite
elements is created, with the same size as the array.
sourceSettings
This document was generated with Documenter.jl version 1.5.0 on Monday 22 July 2024. Using Julia version 1.10.4.
+ UnivariateFinite{Multiclass{4}}(x=>0.292, y=>0.339, z=>0.369)
Probability augmentation
If augment=true
the provided array is augmented by inserting appropriate elements ahead of those provided, along the last dimension of the array. This means the user only provides probabilities for the classes c2, c3, ..., cn
. The class c1
probabilities are chosen so that each UnivariateFinite
distribution in the returned array is a bona fide probability distribution.
UnivariateFinite(prob_given_class; pool=nothing, ordered=false)
Construct a discrete univariate distribution whose finite support is the set of keys of the provided dictionary, prob_given_class
, and whose values specify the corresponding probabilities.
The type requirements on the keys of the dictionary are the same as the elements of support
given above with this exception: if non-categorical elements (raw labels) are used as keys, then pool=...
must be specified and cannot be missing
.
If the values (probabilities) are arrays instead of scalars, then an abstract array of UnivariateFinite
elements is created, with the same size as the array.