Skip to content

Commit 68a0e24

Browse files
authored
Add target_scitype to unsupervised model traits (#16)
1 parent 66207bc commit 68a0e24

File tree

7 files changed

+43
-25
lines changed

7 files changed

+43
-25
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJModelInterface"
22
uuid = "e80e1ace-859a-464e-9ed9-23947d8ae3ea"
33
authors = ["Thibaut Lienart and Anthony Blaom"]
4-
version = "0.1.5"
4+
version = "0.1.6"
55

66
[deps]
77
ScientificTypes = "321657f4-b219-11e9-178b-2701a2544e81"
@@ -15,9 +15,9 @@ CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
1515
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
1616
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
1717
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
18+
MLJScientificTypes = "2e2323e0-db8b-457b-ae0d-bdfb3bc63afd"
1819
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
1920
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2021

2122
[targets]
22-
test = ["Test", "Tables", "Distances", "CategoricalArrays", "InteractiveUtils",
23-
"DataFrames"]
23+
test = ["Test", "Tables", "Distances", "CategoricalArrays", "InteractiveUtils", "DataFrames", "MLJScientificTypes"]

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# MLJModelInterface.jl
22

3+
A light-weight interface for developers wanting to integrate
4+
machine learning models into
5+
[MLJ](https://github.com/alan-turing-institute/MLJ.jl).
6+
7+
38
| [MacOS/Linux] | Coverage |
49
| :-----------: | :------: |
510
| [![Build Status](https://travis-ci.org/alan-turing-institute/MLJModelInterface.jl.svg?branch=master)](https://travis-ci.org/alan-turing-institute/MLJModelInterface.jl) | [![codecov.io](http://codecov.io/github/alan-turing-institute/MLJModelInterface.jl/coverage.svg?branch=master)](http://codecov.io/github/alan-turing-institute/MLJModelInterface.jl?branch=master) |
11+
12+
13+
[MLJ](https://github.com/alan-turing-institute/MLJ.jl) is a framework
14+
for evaluating, combining and optimizing machine learning models in
15+
Julia. A third party package wanting to integrate their supervised or
16+
unsupervised machine learning models must import the module
17+
`MLJModelInterface` defined in this package.
18+
19+
### Instructions
20+
21+
- [Quick-start guide](https://alan-turing-institute.github.io/MLJ.jl/dev/quick_start_guide_to_adding_models/) to adding models to MLJ
22+
23+
- [Detailed API
24+
specification](https://alan-turing-institute.github.io/MLJ.jl/dev/adding_models_for_general_use/)

src/data_utils.jl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int(::LightInterface, x) = errlight("int")
8383
"""
8484
classes(x)
8585
86-
All the categorical elements with in the same pool as `x` (including `x`),
86+
All the categorical elements with the same pool as `x` (including `x`),
8787
returned as a list, with an ordering consistent with the pool $REQUIRE.
8888
Here `x` has `CategoricalValue` or `CategoricalString` type, and `classes(x)`
8989
is a vector of the same eltype. Note that `x in classes(x)` is always true.
@@ -277,24 +277,22 @@ const UNIVARIATE_FINITE_DOCSTRING =
277277
"""
278278
UnivariateFinite(classes, p)
279279
280-
A discrete univariate distribution whose finite support is the elements of
281-
the vector `classes`, and whose corresponding probabilities are elements of
282-
the vector `p`, which must sum to one $REQUIRE. Here `classes` must have
283-
type `AbstractVector{<:CategoricalElement}` where
280+
A discrete univariate distribution whose finite support is the elements of the
281+
vector `classes`, and whose corresponding probabilities are elements of the
282+
vector `p`, which must sum to one $REQUIRE. Here `classes` must have type
283+
`AbstractVector{<:CategoricalElement}` where
284284
285285
CategoricalElement = Union{CategoricalValue,CategoricalString}
286286
287-
and all classes are assumed to share the same categorical pool.
287+
and all classes are assumed to share the same categorical pool.
288288
289289
UnivariateFinite(prob_given_class)
290290
291-
A discrete univariate distribution whose finite support is the set of keys
292-
of the provided dictionary, `prob_given_class` $REQUIRE. The dictionary
293-
keys must be of type `CategoricalElement` (see above) and the dictionary
294-
values specify the corresponding probabilities.
295-
"""
296-
297-
"""$UNIVARIATE_FINITE_DOCSTRING"""
291+
A discrete univariate distribution whose finite support is the set of keys of
292+
the provided dictionary, `prob_given_class` $REQUIRE. The dictionary keys must
293+
be of type `CategoricalElement` (see above) and the dictionary values specify
294+
the corresponding probabilities.
295+
"""
298296
UnivariateFinite(d::AbstractDict) = UnivariateFinite(get_interface_mode(), d)
299297
UnivariateFinite(c::AbstractVector, p) =
300298
UnivariateFinite(get_interface_mode(), c, p)

src/model_def.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
clean!(::Model) = ""
99

1010
"""
11-
_process_model_def(ex)
11+
_process_model_def(ex)
1212
1313
Take an expression defining a model (`mutable struct Model ...`) and unpack key
1414
elements for further processing:
@@ -88,7 +88,7 @@ function _process_model_def(ex)
8888
end
8989

9090
"""
91-
_unpack!(ex, rep)
91+
_unpack!(ex, rep)
9292
9393
Internal function to allow to read a constraint given after a default value for
9494
a parameter and transform it in an executable condition (which is returned to
@@ -111,7 +111,7 @@ _unpack!(ex, _) = ex # when it's been unpacked, it's not an expression anymore
111111

112112

113113
"""
114-
_model_constructor(modelname, params, defaults)
114+
_model_constructor(modelname, params, defaults)
115115
116116
Build the expression of the keyword constructor associated with a model
117117
definition. When the constructor is called, the `clean!` function is called
@@ -131,7 +131,7 @@ end
131131

132132

133133
"""
134-
_model_cleaner(modelname, defaults, constraints)
134+
_model_cleaner(modelname, defaults, constraints)
135135
136136
Build the expression of the cleaner associated with the constraints specified
137137
in a model def.
@@ -163,7 +163,7 @@ function _model_cleaner(modelname, defaults, constraints)
163163
end
164164

165165
"""
166-
@mlj_model
166+
@mlj_model
167167
168168
Macro to help define MLJ models with constraints on the default parameters.
169169
"""

src/model_traits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const MODEL_TRAITS = [
1313
const SUPERVISED_TRAITS = setdiff(MODEL_TRAITS, [:output_scitype])
1414

1515
const UNSUPERVISED_TRAITS = setdiff(MODEL_TRAITS,
16-
[:target_scitype, :prediction_type, :supports_weights])
16+
[:prediction_type, :supports_weights])
1717

1818
for trait in MODEL_TRAITS
1919
ex = quote

test/data_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
@testset "categorical-light" begin
1+
@testset "cat-light" begin
22
setlight()
33
x = 1:5
44
@test_throws M.InterfaceError M.categorical(x)
55
end
6-
@testset "categorical-full" begin
6+
@testset "cat-full" begin
77
setfull()
88
M.categorical(::FI, a...; kw...) = categorical(a...; kw...)
99
x = 1:5

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Test, MLJModelInterface, ScientificTypes
1+
using Test, MLJModelInterface
2+
using ScientificTypes, MLJScientificTypes
23
using Tables, Distances, CategoricalArrays, InteractiveUtils
34
import DataFrames: DataFrame
45

0 commit comments

Comments
 (0)