numobs
function defined in module
MLUtils
numobs(data)
Return the total number of observations contained in
data.
If
data does not have
numobs defined, then in the case of
Tables.table(data) == true returns the number of rows, otherwise returns
length(data).
Authors of custom data containers should implement
Base.length for their type instead of
numobs.
numobs should only be implemented for types where there is a difference between
numobs and
Base.length (such as multi-dimensional arrays).
getobs supports by default nested combinations of array, tuple, named tuples, and dictionaries.
See also
getobs.
# named tuples
x = (a = [1, 2, 3], b = rand(6, 3))
numobs(x) == 3
# dictionaries
x = Dict(:a => [1, 2, 3], :b => rand(6, 3))
numobs(x) == 3
All internal containers must have the same number of observations:
julia> x = (a = [1, 2, 3, 4], b = rand(6, 3));
julia> numobs(x)
ERROR: DimensionMismatch: All data containers must have the same number of observations.
Stacktrace:
[1] _check_numobs_error()
@ MLUtils ~/.julia/dev/MLUtils/src/observation.jl:163
[2] _check_numobs
@ ~/.julia/dev/MLUtils/src/observation.jl:130 [inlined]
[3] numobs(data::NamedTuple{(:a, :b), Tuple{Vector{Int64}, Matrix{Float64}}})
@ MLUtils ~/.julia/dev/MLUtils/src/observation.jl:177
[4] top-level scope
@ REPL[35]:1
There are
7
methods for MLUtils.numobs:
The following pages link back here:
Data containers, How to visualize data, Keypoint regression, Performant data pipelines, Presizing vision datasets for performance, Saving and loading models for inference, Siamese image similarity, Variational autoencoders
FastAI.jl , datasets/Datasets.jl , tasks/taskdata.jl , FastTabular.jl , FastVision.jl , encodings/imagepreprocessing.jl , recipes.jl , MLUtils.jl , batchview.jl , eachobs.jl , folds.jl , observation.jl , obstransform.jl , obsview.jl , parallel.jl , randobs.jl , resample.jl , splitobs.jl , utils.jl