Skip to content

Commit

Permalink
adjust train_test_pairs fallbacks to allow (strategy, rows, y) args
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Nov 18, 2019
1 parent 5a7810f commit 7f9449b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ function ==(s1::S, s2::S) where S <: ResamplingStrategy
return all(getfield(s1, fld) == getfield(s2, fld) for fld in fieldnames(S))
end

# fallbacks:
train_test_pairs(s::ResamplingStrategy, rows, X, y, w) =
train_test_pairs(s, rows, X, y)
train_test_pairs(s::ResamplingStrategy, rows, X, y) =
train_test_pairs(s, rows, y)
train_test_pairs(s::ResamplingStrategy, rows, y) =
train_test_pairs(s, rows)

"""
Expand Down Expand Up @@ -137,13 +140,15 @@ function train_test_pairs(cv::CV, rows)
end

"""
stratified_cv = StratifiedCV(; nfolds=6, shuffle=false, rng=Random.GLOBAL_RNG)
stratified_cv = StratifiedCV(; nfolds=6,
shuffle=false,
rng=Random.GLOBAL_RNG)
Stratified cross-validation resampling strategy, for use in
`evaluate!`, `evaluate` and in tuning. Applies only to classification
problems (`OrderedFactor` or `Multiclass` targets).
train_test_pairs(stratified_cv, rows, X, y) # X is ignored
train_test_pairs(stratified_cv, rows, y)
Returns an `nfolds`-length iterator of `(train, test)` pairs of
vectors (row indices) where each `train` and `test` is a sub-vector of
Expand Down
4 changes: 2 additions & 2 deletions test/resampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ end
rows, nothing, y)

# check class distribution is preserved in a larger randomized example:
N = 3
N = 30
y = shuffle(vcat(fill(:a, N), fill(:b, 2N),
fill(:c, 3N), fill(:d, 4N))) |> categorical;
d = fit(UnivariateFinite, y)
pairs = MLJ.train_test_pairs(scv, 1:10N, nothing, y)
folds = vcat(first.(pairs), last.(pairs))
@test all([fit(UnivariateFinite, y[fold]) d for fold in folds])


end

@testset "weights" begin
Expand Down

0 comments on commit 7f9449b

Please sign in to comment.