Skip to content

Commit 65facf9

Browse files
authored
Merge pull request #18 from JuliaAI/dev
For a 0.2.4 release
2 parents 3bc4425 + 045363d commit 65facf9

File tree

6 files changed

+73
-17
lines changed

6 files changed

+73
-17
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJTestInterface"
22
uuid = "72560011-54dd-4dc2-94f3-c5de45b75ecd"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "0.2.3"
4+
version = "0.2.4"
55

66
[deps]
77
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
@@ -10,4 +10,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1010

1111
[compat]
1212
MLJBase = "0.20, 0.21, 1"
13+
Test = "<0.0.1, 1"
1314
julia = "1.6"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ failures, summary = MLJTestInterface.test(
5454
The following commands generate small datasets of the form `(X, y)` suitable for interface
5555
tests:
5656

57-
- `MLJTestInterface.make_binary`
57+
- `MLJTestInterface.make_binary(; row_table=false)`
5858

59-
- `MLJTestInterface.make_multiclass`
59+
- `MLJTestInterface.make_multiclass(; row_table=false)` `
6060

61-
- `MLJTestInterface.make_regression`
61+
- `MLJTestInterface.make_regression(; row_table=false)` `
6262

63-
- `MLJTestInterface.make_count`
63+
- `MLJTestInterface.make_count(; row_table=false)` `
6464

src/attemptors.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function operations(fitted_machine, data...; throw=false, verbosity=1)
9595
methods = MLJBase.implemented_methods(fitted_machine.model)
9696
if model isa Static && !(:transform in methods)
9797
push!(methods, :transform)
98-
end
98+
end
9999
_, test = MLJBase.partition(1:MLJBase.nrows(first(data)), 0.5)
100100
if :predict in methods
101101
predict(fitted_machine, first(data))

src/datasets.jl

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,59 @@
11
"""
2-
make_binary()
2+
make_binary(; row_table=false)
33
44
Return data `(X, y)` for the crabs dataset, restricted to the two features `:FL`,
55
`:RW`. Target is `Multiclass{2}`.
66
7+
The table `X` is a named tuple of vectors. For a vector of named tuples, set
8+
`row_table=true`.
9+
710
"""
8-
function make_binary()
11+
function make_binary(; row_table=false)
912
data = MLJBase.load_crabs()
1013
y_, X = unpack(data, ==(:sp), col->col in [:FL, :RW])
1114
y = coerce(y_, MLJBase.OrderedFactor)
12-
return X, y
15+
row_table ? (MLJBase.Tables.rowtable(X), y) : (X, y)
1316
end
1417

1518
"""
16-
make_multiclass()
19+
make_multiclass(; row_table=false)
1720
1821
Return data `(X, y)` for the unshuffled iris dataset. Target is `Multiclass{3}`.
1922
2023
"""
21-
make_multiclass() = MLJBase.@load_iris
24+
function make_multiclass(; row_table=false)
25+
X, y = MLJBase.@load_iris
26+
row_table ? (MLJBase.Tables.rowtable(X), y) : (X, y)
27+
end
2228

2329
"""
24-
make_regression()
30+
make_regression(; row_table=false)
2531
2632
Return data `(X, y)` for the Boston dataset, restricted to the two features `:LStat`,
2733
`:Rm`. Target is `Continuous`.
2834
35+
The table `X` is a named tuple of vectors. For a vector of named tuples, set
36+
`row_table=true`.
37+
2938
"""
30-
function make_regression()
39+
function make_regression(; row_table=false)
3140
data = MLJBase.load_boston()
3241
y, X = unpack(data, ==(:MedV), col->col in [:LStat, :Rm])
33-
return X, y
42+
row_table ? (MLJBase.Tables.rowtable(X), y) : (X, y)
3443
end
3544

3645
"""
37-
make_count()
46+
make_count(; row_table=false)
3847
3948
Return data `(X, y)` for the Boston dataset, restricted to the two features `:LStat`,
4049
`:Rm`, with the `Continuous` target converted to `Count` (integer).
4150
51+
The table `X` is a named tuple of vectors. For a vector of named tuples, set
52+
`row_table=true`.
53+
4254
"""
43-
function make_count()
55+
function make_count(; row_table=false)
4456
X, y_ = make_regression()
4557
y = map-> round(Int, η), y_)
46-
return X, y
58+
row_table ? (MLJBase.Tables.rowtable(X), y) : (X, y)
4759
end

test/datasets.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@testset "loading of datasets" begin
2+
X, y = MTI.make_binary()
3+
@test X isa NamedTuple
4+
@test first(X) isa AbstractVector{Float64}
5+
@test MLJBase.scitype(y) == AbstractVector{MLJBase.OrderedFactor{2}}
6+
Xr, yr = MTI.make_binary(row_table=true)
7+
@test Xr isa AbstractVector
8+
@test MLJBase.Tables.rowtable(X) == Xr
9+
@test yr == y
10+
11+
X, y = MTI.make_multiclass()
12+
@test X isa NamedTuple
13+
@test first(X) isa AbstractVector{Float64}
14+
@test MLJBase.scitype(y) == AbstractVector{MLJBase.Multiclass{3}}
15+
Xr, yr = MTI.make_multiclass(row_table=true)
16+
@test Xr isa AbstractVector
17+
@test MLJBase.Tables.rowtable(X) == Xr
18+
@test yr == y
19+
20+
X, y = MTI.make_regression()
21+
@test X isa NamedTuple
22+
@test first(X) isa AbstractVector{Float64}
23+
@test MLJBase.scitype(y) == AbstractVector{MLJBase.Continuous}
24+
Xr, yr = MTI.make_regression(row_table=true)
25+
@test Xr isa AbstractVector
26+
@test MLJBase.Tables.rowtable(X) == Xr
27+
@test yr == y
28+
29+
X, y = MTI.make_count()
30+
@test X isa NamedTuple
31+
@test first(X) isa AbstractVector{Float64}
32+
@test MLJBase.scitype(y) == AbstractVector{MLJBase.Count}
33+
Xr, yr = MTI.make_count(row_table=true)
34+
@test Xr isa AbstractVector
35+
@test MLJBase.Tables.rowtable(X) == Xr
36+
@test yr == y
37+
end
38+
39+
true

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ macro conditional_testset(name, expr)
2020
end)
2121
end
2222

23+
@conditional_testset "datasets" begin
24+
include("datasets.jl")
25+
end
26+
2327
@conditional_testset "attemptors" begin
2428
include("attemptors.jl")
2529
end

0 commit comments

Comments
 (0)