Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For a 1.4 release #981

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLJBase"
uuid = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
authors = ["Anthony D. Blaom <[email protected]>"]
version = "1.3"
version = "1.4.0"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down Expand Up @@ -47,7 +47,7 @@ DelimitedFiles = "1"
Distributions = "0.25.3"
InvertedIndices = "1"
LearnAPI = "0.1"
MLJModelInterface = "1.7"
MLJModelInterface = "1.10"
Missings = "0.4, 1"
OrderedCollections = "1.1"
Parameters = "0.12"
Expand All @@ -58,7 +58,7 @@ Reexport = "1.2"
ScientificTypes = "3"
StatisticalMeasures = "0.1.1"
StatisticalMeasuresBase = "0.1.1"
StatisticalTraits = "3.2"
StatisticalTraits = "3.3"
Statistics = "1"
StatsBase = "0.32, 0.33, 0.34"
Tables = "0.2, 1.0"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## MLJBase

Repository for developers that provides core functionality for the
[MLJ](https:/alan-turing-institute/MLJ.jl) machine
[MLJ](https:/JuliaAI/MLJ.jl) machine
learning framework.

| Branch | Julia | Build | Coverage |
Expand All @@ -20,7 +20,7 @@ learning framework.

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaai.github.io/MLJBase.jl/stable/)

[MLJ](https:/alan-turing-institute/MLJ.jl) is a Julia
[MLJ](https:/JuliaAI/MLJ.jl) is a Julia
framework for combining and tuning machine learning models. This
repository provides core functionality for MLJ, including:

Expand All @@ -37,7 +37,7 @@ repository provides core functionality for MLJ, including:
- basic utilities for **manipulating datasets** and for **synthesizing datasets** (src/data)

- a [small
interface](https://alan-turing-institute.github.io/MLJ.jl/dev/evaluating_model_performance/#Custom-resampling-strategies-1)
interface](https://JuliaAI.github.io/MLJ.jl/dev/evaluating_model_performance/#Custom-resampling-strategies-1)
for **resampling strategies** and implementations, including `CV()`, `StratifiedCV` and
`Holdout` (src/resampling.jl). Actual performance evaluation measures (aka metrics), which previously
were provided by MLJBase.jl, now live in [StatisticalMeasures.jl](https://juliaai.github.io/StatisticalMeasures.jl/dev/).
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

These docs are bare-bones and auto-generated. Complete MLJ
documentation is
[here](https://alan-turing-institute.github.io/MLJ.jl/dev/).
[here](https://JuliaAI.github.io/MLJ.jl/dev/).

For MLJBase-specific developer information, see also the [README.md
file](https:/JuliaAI/MLJBase.jl#readme).
2 changes: 1 addition & 1 deletion src/composition/learning_networks/nodes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function ScientificTypes.elscitype(
end

# TODO after
# https:/alan-turing-institute/ScientificTypesBase.jl/issues/102 :
# https:/JuliaAI/ScientificTypesBase.jl/issues/102 :
# Add Probabilistic case to above

ScientificTypes.scitype(N::Node) = CallableReturning{elscitype(N)}
Expand Down
5 changes: 4 additions & 1 deletion src/composition/models/pipelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ end

# # LEARNING NETWORK INTERFACE

# https://alan-turing-institute.github.io/MLJ.jl/dev/composing_models/#Learning-network-machines
# https://JuliaAI.github.io/MLJ.jl/dev/composing_models/#Learning-network-machines


# ## Methods to extend a pipeline learning network
Expand Down Expand Up @@ -599,6 +599,9 @@ end

MMI.target_scitype(p::SupervisedPipeline) = target_scitype(supervised_component(p))

MMI.package_name(::Type{<:SomePipeline}) = "MLJBase"
MMI.load_path(::Type{<:SomePipeline}) = "MLJBase.Pipeline"
MMI.constructor(::Type{<:SomePipeline}) = Pipeline

# ## Training losses

Expand Down
9 changes: 5 additions & 4 deletions src/composition/models/stacking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,20 @@ function Base.setproperty!(stack::Stack{modelnames}, _name::Symbol, val) where m
end


# # TRAITS

MMI.target_scitype(::Type{<:Stack{modelnames, input_scitype, target_scitype}}) where
{modelnames, input_scitype, target_scitype} = target_scitype


MMI.input_scitype(::Type{<:Stack{modelnames, input_scitype, target_scitype}}) where
{modelnames, input_scitype, target_scitype} = input_scitype


MLJBase.load_path(::Type{<:ProbabilisticStack}) = "MLJBase.ProbabilisticStack"
MLJBase.load_path(::Type{<:DeterministicStack}) = "MLJBase.DeterministicStack"
MMI.constructor(::Type{<:Stack}) = Stack
MLJBase.load_path(::Type{<:Stack}) = "MLJBase.Stack"
MLJBase.package_name(::Type{<:Stack}) = "MLJBase"
MLJBase.package_uuid(::Type{<:Stack}) = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
MLJBase.package_url(::Type{<:Stack}) = "https:/alan-turing-institute/MLJBase.jl"
MLJBase.package_url(::Type{<:Stack}) = "https:/JuliaAI/MLJBase.jl"
MLJBase.package_license(::Type{<:Stack}) = "MIT"

###########################################################
Expand Down
7 changes: 6 additions & 1 deletion src/composition/models/transformed_target_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const TT_SUPPORTED_ATOMS = (
:Deterministic,
:DeterministicUnsupervisedDetector,
:DeterministicSupervisedDetector,
:Interval)
:Interval,
)

# Each supported atomic type gets its own wrapper:

Expand Down Expand Up @@ -265,6 +266,10 @@ MMI.package_uuid(::Type{<:SomeTT}) = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
MMI.is_wrapper(::Type{<:SomeTT}) = true
MMI.package_url(::Type{<:SomeTT}) = "https:/JuliaAI/MLJBase.jl"

MMI.load_path(::Type{<:SomeTT}) = "MLJBase.TransformedTargetModel"
MMI.constructor(::Type{<:SomeTT}) = TransformedTargetModel


for New in TT_TYPE_EXS
quote
MMI.iteration_parameter(::Type{<:$New{M}}) where M =
Expand Down
2 changes: 1 addition & 1 deletion src/interface/data_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ MMI.selectcols(::FI, ::Val{:table}, X, ::Colon) = X
function MMI.selectrows(::FI, ::Val{:table}, X, r)
r = r isa Integer ? (r:r) : r
# next uncommented line is a hack; see
# https:/alan-turing-institute/MLJBase.jl/issues/151
# https:/JuliaAI/MLJBase.jl/issues/151
isdataframe(X) && return X[r, :]
cols = Tables.columntable(X)
new_cols = NamedTuple{keys(cols)}(tuple((c[r] for c in values(cols))...))
Expand Down
27 changes: 12 additions & 15 deletions src/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1548,9 +1548,11 @@ end
compact=false,
)

*Private method.* Use at own risk.

Resampling model wrapper, used internally by the `fit` method of `TunedModel` instances
and `IteratedModel` instances. See [`evaluate!](@ref) for options. Not intended for use by
general user, who will ordinarily use [`evaluate!`](@ref) directly.
and `IteratedModel` instances. See [`evaluate!`](@ref) for meaning of the options. Not
intended for use by general user, who will ordinarily use [`evaluate!`](@ref) directly.

Given a machine `mach = machine(resampler, args...)` one obtains a performance evaluation
of the specified `model`, performed according to the prescribed `resampling` strategy and
Expand Down Expand Up @@ -1592,16 +1594,6 @@ mutable struct Resampler{S, L} <: Model
compact::Bool
end

# Some traits are markded as `missing` because we cannot determine
# them from from the type because we have removed `M` (for "model"} as
# a `Resampler` type parameter. See
# https:/JuliaAI/MLJTuning.jl/issues/141#issue-951221466

StatisticalTraits.is_wrapper(::Type{<:Resampler}) = true
StatisticalTraits.supports_weights(::Type{<:Resampler}) = missing
StatisticalTraits.supports_class_weights(::Type{<:Resampler}) = missing
StatisticalTraits.is_pure_julia(::Type{<:Resampler}) = true

function MLJModelInterface.clean!(resampler::Resampler)
warning = ""
if resampler.measure === nothing && resampler.model !== nothing
Expand Down Expand Up @@ -1787,11 +1779,16 @@ function MLJModelInterface.update(

end

# The input and target scitypes cannot be determined from the type
# because we have removed `M` (for "model") as a `Resampler` type
# parameter. See
# Some traits are marked as `missing` because we cannot determine
# them from from the type because we have removed `M` (for "model"} as
# a `Resampler` type parameter. See
# https:/JuliaAI/MLJTuning.jl/issues/141#issue-951221466

StatisticalTraits.is_wrapper(::Type{<:Resampler}) = true
StatisticalTraits.supports_weights(::Type{<:Resampler}) = missing
StatisticalTraits.supports_class_weights(::Type{<:Resampler}) = missing
StatisticalTraits.is_pure_julia(::Type{<:Resampler}) = true
StatisticalTraits.constructor(::Type{<:Resampler}) = Resampler
StatisticalTraits.input_scitype(::Type{<:Resampler}) = Unknown
StatisticalTraits.target_scitype(::Type{<:Resampler}) = Unknown
StatisticalTraits.package_name(::Type{<:Resampler}) = "MLJBase"
Expand Down
2 changes: 1 addition & 1 deletion test/_models/Constant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ metadata_pkg.((ConstantRegressor, ConstantClassifier,
DeterministicConstantRegressor, DeterministicConstantClassifier),
name="MLJModels",
uuid="d491faf4-2d78-11e9-2867-c94bc002c0b7",
url="https:/alan-turing-institute/MLJModels.jl",
url="https:/JuliaAI/MLJModels.jl",
julia=true,
license="MIT",
is_wrapper=false)
Expand Down
2 changes: 1 addition & 1 deletion test/_models/simple_composite_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ for model in COMPOSITE_MODELS

MLJBase.metadata_pkg(
$(model);
package_url = "https:/alan-turing-institute/MLJBase.jl",
package_url = "https:/JuliaAI/MLJBase.jl",
is_pure_julia = true,
is_wrapper = true
)
Expand Down
4 changes: 3 additions & 1 deletion test/composition/models/pipelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ end

@testset "public constructor" begin
# un-named components:
@test Pipeline(m, t, u) isa UnsupervisedPipeline
flute = Pipeline(m, t, u)
@test flute isa UnsupervisedPipeline
@test MLJBase.constructor(flute) == Pipeline
@test Pipeline(m, t, u, p) isa ProbabilisticPipeline
@test Pipeline(m, t, u, p, operation=predict_mean) isa DeterministicPipeline
@test Pipeline(u, p, u, operation=predict_mean) isa DeterministicPipeline
Expand Down
3 changes: 3 additions & 0 deletions test/composition/models/stacking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ end
measures=rmse,
resampling=CV(;nfolds=3),
models...)

@test MLJBase.constructor(mystack) == Stack

@test mystack.ridge_lambda.lambda == 0.1
@test mystack.metalearner isa FooBarRegressor
@test mystack.resampling isa CV
Expand Down
1 change: 1 addition & 0 deletions test/composition/models/transformed_target_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ avg_nonlinear = g(mean(f(y))) # = g(mean(z))

# Test wrapping using f and g:
model = TransformedTargetModel(atom, transformer=f, inverse=g)
@test MLJBase.constructor(model) == TransformedTargetModel
fr1, _, _ = MMI.fit(model, 0, X, y)
@test first(predict(model, fr1, X)) ≈ fill(avg_nonlinear, 5)

Expand Down
3 changes: 3 additions & 0 deletions test/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ end
holdout = Holdout(fraction_train=0.75)
resampler = Resampler(resampling=holdout, model=ridge_model, measure=mae,
acceleration=accel)
@test constructor(resampler) == Resampler
@test package_name(resampler) == "MLJBase"
@test load_path(resampler) == "MLJBase.Resampler"
resampling_machine = machine(resampler, X, y)
@test_logs((:info, r"^Training"), fit!(resampling_machine))
e1=evaluate(resampling_machine).measurement[1]
Expand Down
Loading