Skip to content

Commit d5f3398

Browse files
authored
Merge pull request #977 from JuliaAI/dev
For a 1.3 release
2 parents 5046989 + af10ff2 commit d5f3398

20 files changed

+533
-305
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
env:
5050
JULIA_NUM_THREADS: 2
5151
- uses: julia-actions/julia-processcoverage@v1
52-
- uses: codecov/codecov-action@v1
52+
- uses: codecov/codecov-action@v3
5353
with:
5454
file: lcov.info
5555
docs:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJBase"
22
uuid = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "1.2.1"
4+
version = "1.3"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"

src/MLJBase.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ export machines, sources, Stack,
291291
export TransformedTargetModel
292292

293293
# resampling.jl:
294-
export ResamplingStrategy, Holdout, CV, StratifiedCV, TimeSeriesCV,
295-
evaluate!, Resampler, PerformanceEvaluation
294+
export ResamplingStrategy, InSample, Holdout, CV, StratifiedCV, TimeSeriesCV,
295+
evaluate!, Resampler, PerformanceEvaluation, CompactPerformanceEvaluation
296296

297297
# `MLJType` and the abstract `Model` subtypes are exported from within
298298
# src/composition/abstract_types.jl

src/composition/learning_networks/nodes.jl

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ See also [`node`](@ref), [`Source`](@ref), [`origins`](@ref),
2727
[`sources`](@ref), [`fit!`](@ref).
2828
2929
"""
30-
struct Node{T<:Union{Machine, Nothing}} <: AbstractNode
30+
struct Node{T<:Union{Machine, Nothing},Oper} <: AbstractNode
3131

32-
operation # eg, `predict` or a static operation, such as `exp`
32+
operation::Oper # eg, `predict` or a static operation, such as `exp`
3333
machine::T # is `nothing` for static operations
3434

3535
# nodes called to get args for `operation(model, ...) ` or
@@ -43,9 +43,11 @@ struct Node{T<:Union{Machine, Nothing}} <: AbstractNode
4343
# order consistent with extended graph, excluding self
4444
nodes::Vector{AbstractNode}
4545

46-
function Node(operation,
47-
machine::T,
48-
args::AbstractNode...) where T<:Union{Machine, Nothing}
46+
function Node(
47+
operation::Oper,
48+
machine::T,
49+
args::AbstractNode...,
50+
) where {T<:Union{Machine, Nothing}, Oper}
4951

5052
# check the number of arguments:
5153
# if machine === nothing && isempty(args)
@@ -70,7 +72,7 @@ struct Node{T<:Union{Machine, Nothing}} <: AbstractNode
7072
vcat(nodes_, (nodes(n) for n in machine.args)...) |> unique
7173
end
7274

73-
return new{T}(operation, machine, args, origins_, nodes_)
75+
return new{T,Oper}(operation, machine, args, origins_, nodes_)
7476
end
7577
end
7678

@@ -407,14 +409,14 @@ of nodes, sources and other arguments.
407409
408410
### Examples
409411
410-
```
411-
X = source(π)
412-
W = @node sin(X)
412+
```julia-repl
413+
julia> X = source(π)
414+
julia> W = @node sin(X)
413415
julia> W()
414416
0
415417
416-
X = source(1:10)
417-
Y = @node selectrows(X, 3:4)
418+
julia> X = source(1:10)
419+
julia> Y = @node selectrows(X, 3:4)
418420
julia> Y()
419421
3:4
420422
@@ -423,10 +425,10 @@ julia> Y(["one", "two", "three", "four"])
423425
"three"
424426
"four"
425427
426-
X1 = source(4)
427-
X2 = source(5)
428-
add(a, b, c) = a + b + c
429-
N = @node add(X1, 1, X2)
428+
julia> X1 = source(4)
429+
julia> X2 = source(5)
430+
julia> add(a, b, c) = a + b + c
431+
julia> N = @node add(X1, 1, X2)
430432
julia> N()
431433
10
432434

src/composition/learning_networks/signatures.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
99
**Private method.**
1010
11-
Return a dictionary of machines, keyed on model, for the all machines in the completed
12-
learning network for which `node` is the greatest lower bound. Only machines bound to
13-
symbolic models are included. Values are always vectors, even if they contain only a
14-
single machine.
11+
Return a dictionary of machines, keyed on model, for the all machines in the
12+
completed learning network for which `node` is the greatest lower bound. Only
13+
machines bound to symbolic models are included. Values are always vectors,
14+
even if they contain only a single machine.
1515
1616
"""
1717
function machines_given_model(node::AbstractNode)
@@ -35,14 +35,14 @@ attempt_scalarize(v) = length(v) == 1 ? v[1] : v
3535
3636
**Private method.**
3737
38-
Given a dictionary of machine vectors, keyed on model names (symbols), broadcast `f` over
39-
each vector, and make the result, in the returned named tuple, the value associated with
40-
the corresponding model name as key.
38+
Given a dictionary of machine vectors, keyed on model names (symbols), broadcast
39+
`f` over each vector, and make the result, in the returned named tuple, the
40+
value associated with the corresponding model name as key.
4141
4242
Singleton vector values are scalarized, unless `scalarize = false`.
4343
44-
If a value in the computed named tuple is `nothing`, or a vector of `nothing`s, then the
45-
entry is dropped from the tuple, unless `drop_nothings=false`.
44+
If a value in the computed named tuple is `nothing`, or a vector of `nothing`s,
45+
then the entry is dropped from the tuple, unless `drop_nothings=false`.
4646
4747
"""
4848
function tuple_keyed_on_model(f, machines_given_model; scalarize=true, drop_nothings=true)

src/composition/models/stacking.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ internal_stack_report(
337337
) = NamedTuple{}()
338338

339339
"""
340-
internal_stack_report(
341-
m::Stack,
342-
verbosity::Int,
343-
y::AbstractNode,
344-
folds_evaluations::Vararg{AbstractNode},
345-
)
340+
internal_stack_report(
341+
m::Stack,
342+
verbosity::Int,
343+
y::AbstractNode,
344+
folds_evaluations::Vararg{AbstractNode},
345+
)
346346
347347
When measure/measures is provided, the folds_evaluation will have been filled by
348348
`store_for_evaluation`. This function is not doing any heavy work (not constructing nodes
@@ -518,7 +518,7 @@ function oos_set(m::Stack{modelnames}, Xs::Source, ys::Source, tt_pairs) where m
518518
end
519519

520520
#######################################
521-
################# Prefit #################
521+
################# Prefit ##############
522522
#######################################
523523

524524
function prefit(m::Stack{modelnames}, verbosity::Int, X, y) where modelnames
@@ -564,8 +564,7 @@ const DOC_STACK =
564564
Stack(; metalearner=nothing, name1=model1, name2=model2, ..., keyword_options...)
565565
566566
Implements the two-layer generalized stack algorithm introduced by
567-
[Wolpert
568-
(1992)](https://www.sciencedirect.com/science/article/abs/pii/S0893608005800231)
567+
[Wolpert (1992)](https://www.sciencedirect.com/science/article/abs/pii/S0893608005800231)
569568
and generalized by [Van der Laan et al
570569
(2007)](https://biostats.bepress.com/ucbbiostat/paper222/). Returns an
571570
instance of type `ProbabilisticStack` or `DeterministicStack`,

src/composition/models/transformed_target_model.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ERR_MODEL_UNSPECIFIED = ArgumentError(
6161
"Expecting atomic model as argument. None specified. "
6262
)
6363
const ERR_TRANSFORMER_UNSPECIFIED = ArgumentError(
64-
"You must specify `transformer=...`. ."
64+
"You must specify `transformer=...`. ."
6565
)
6666
const ERR_TOO_MANY_ARGUMENTS = ArgumentError(
6767
"At most one non-keyword argument, a model, allowed. "
@@ -123,7 +123,7 @@ y -> mode.(y))`.
123123
A model that normalizes the target before applying ridge regression,
124124
with predictions returned on the original scale:
125125
126-
```
126+
```julia
127127
@load RidgeRegressor pkg=MLJLinearModels
128128
model = RidgeRegressor()
129129
tmodel = TransformedTargetModel(model, transformer=Standardizer())
@@ -132,7 +132,7 @@ tmodel = TransformedTargetModel(model, transformer=Standardizer())
132132
A model that applies a static `log` transformation to the data, again
133133
returning predictions to the original scale:
134134
135-
```
135+
```julia
136136
tmodel2 = TransformedTargetModel(model, transformer=y->log.(y), inverse=z->exp.(y))
137137
```
138138

src/data/data.jl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,28 @@ corresponding `fractions` of `length(nrows(X))`, where valid fractions
104104
are floats between 0 and 1 whose sum is less than one. The last
105105
fraction is not provided, as it is inferred from the preceding ones.
106106
107-
For "synchronized" partitioning of multiple objects, use the
108-
`multi=true` option described below.
107+
For synchronized partitioning of multiple objects, use the
108+
`multi=true` option.
109109
110-
julia> partition(1:1000, 0.8)
111-
([1,...,800], [801,...,1000])
110+
```julia-repl
111+
julia> partition(1:1000, 0.8)
112+
([1,...,800], [801,...,1000])
112113
113-
julia> partition(1:1000, 0.2, 0.7)
114-
([1,...,200], [201,...,900], [901,...,1000])
114+
julia> partition(1:1000, 0.2, 0.7)
115+
([1,...,200], [201,...,900], [901,...,1000])
115116
116-
julia> partition(reshape(1:10, 5, 2), 0.2, 0.4)
117-
([1 6], [2 7; 3 8], [4 9; 5 10])
117+
julia> partition(reshape(1:10, 5, 2), 0.2, 0.4)
118+
([1 6], [2 7; 3 8], [4 9; 5 10])
118119
119-
X, y = make_blobs() # a table and vector
120-
Xtrain, Xtest = partition(X, 0.8, stratify=y)
120+
julia> X, y = make_blobs() # a table and vector
121+
julia> Xtrain, Xtest = partition(X, 0.8, stratify=y)
122+
```
121123
122-
(Xtrain, Xtest), (ytrain, ytest) = partition((X, y), 0.8, rng=123, multi=true)
124+
Here's an example of synchronized partitioning of multiple objects:
123125
126+
```julia-repl
127+
julia> (Xtrain, Xtest), (ytrain, ytest) = partition((X, y), 0.8, rng=123, multi=true)
128+
```
124129
125130
## Keywords
126131
@@ -209,7 +214,7 @@ Returns a tuple of tables/vectors with length one greater than the
209214
number of supplied predicates, with the last component including all
210215
previously unselected columns.
211216
212-
```
217+
```julia-repl
213218
julia> table = DataFrame(x=[1,2], y=['a', 'b'], z=[10.0, 20.0], w=["A", "B"])
214219
2×4 DataFrame
215220
Row │ x y z w
@@ -218,7 +223,7 @@ julia> table = DataFrame(x=[1,2], y=['a', 'b'], z=[10.0, 20.0], w=["A", "B"])
218223
1 │ 1 a 10.0 A
219224
2 │ 2 b 20.0 B
220225
221-
Z, XY, W = unpack(table, ==(:z), !=(:w))
226+
julia> Z, XY, W = unpack(table, ==(:z), !=(:w));
222227
julia> Z
223228
2-element Vector{Float64}:
224229
10.0
@@ -300,9 +305,11 @@ The method is curried, so that `restrict(folds, i)` is the operator
300305
on data defined by `restrict(folds, i)(X) = restrict(X, folds, i)`.
301306
302307
### Example
303-
304-
folds = ([1, 2], [3, 4, 5], [6,])
305-
restrict([:x1, :x2, :x3, :x4, :x5, :x6], folds, 2) # [:x3, :x4, :x5]
308+
#
309+
```julia
310+
folds = ([1, 2], [3, 4, 5], [6,])
311+
restrict([:x1, :x2, :x3, :x4, :x5, :x6], folds, 2) # [:x3, :x4, :x5]
312+
```
306313
307314
See also [`corestrict`](@ref)
308315
@@ -322,7 +329,9 @@ all elements of `folds`. Here `folds` is a vector or tuple of integer
322329
vectors, typically representing row indices or a vector, matrix or
323330
table.
324331
325-
complement(([1,2], [3,], [4, 5]), 2) # [1 ,2, 4, 5]
332+
```julia
333+
complement(([1,2], [3,], [4, 5]), 2) # [1 ,2, 4, 5]
334+
```
326335
327336
"""
328337
complement(f, i) = reduce(vcat, collect(f)[Not(i)])
@@ -345,8 +354,10 @@ on data defined by `corestrict(folds, i)(X) = corestrict(X, folds, i)`.
345354
346355
### Example
347356
348-
folds = ([1, 2], [3, 4, 5], [6,])
349-
corestrict([:x1, :x2, :x3, :x4, :x5, :x6], folds, 2) # [:x1, :x2, :x6]
357+
```julia
358+
folds = ([1, 2], [3, 4, 5], [6,])
359+
corestrict([:x1, :x2, :x3, :x4, :x5, :x6], folds, 2) # [:x1, :x2, :x6]
360+
```
350361
351362
"""
352363
corestrict(f::NTuple{N}, i) where N = FoldComplementRestrictor{i,N}(f)

src/data/datasets.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const COERCE_SUNSPOTS = (
158158
(:sunspot_number=>Continuous),)
159159

160160
"""
161-
load_dataset(fpath, coercions)
161+
load_dataset(fpath, coercions)
162162
163163
Load one of standard dataset like Boston etc assuming the file is a
164164
comma separated file with a header.

0 commit comments

Comments
 (0)