-
Notifications
You must be signed in to change notification settings - Fork 17
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
Sorting out issue with calling predict on matrix #219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pat-alt Thanks for looking at this.
Yes, I think your proposal ought to work: matrices can be provided not only to predict, but also to fit, which we should have for consistency.
What's left to do is:
- Add tests
- Update the scitype declarations
- Update the docstrings
For example, this code should be changed to
MLJModelInterface.metadata_model(NeuralNetworkClassifier,
input=Union{AbstractMatrix{Continuous}, Table(Continuous)},
target=AbstractVector{<:Finite},
path="MLJFlux.NeuralNetworkClassifier")
Similar changes can be made at regressor.jl
Thanks for persisting with this. This error usually means we're trying to grab the |
Thanks! I believe that's fixed now, though I did still get some warnings like this one: Warning: The number and/or types of data arguments do not match what the specified model
│ supports. Suppress this type check by specifying `scitype_check_level=0`.
│
│ Run `@doc MLJFlux.NeuralNetworkRegressor` to learn more about your model's requirements.
│
│ Commonly, but non exclusively, supervised models are constructed using the syntax
│ `machine(model, X, y)` or `machine(model, X, y, w)` while most other models are
│ constructed with `machine(model, X)`. Here `X` are features, `y` a target, and `w`
│ sample or class weights.
│
│ In general, data in `machine(model, data...)` is expected to satisfy
│
│ scitype(data) <: MLJ.fit_data_scitype(model)
│
│ In the present case:
│
│ scitype(data) = Tuple{Table{AbstractVector{Continuous}}, AbstractVector{Continuous}}
│
│ fit_data_scitype(model) = Tuple{Union{Table{<:AbstractVector{<:Continuous}}, AbstractMatrix{Continuous}}, AbstractVector{<:Finite}} Edit: As for docstrings, I've updated for the classifier and regressors as follows:
|
|
Sorry, rather the scitype declaration for the regressor is wrong. You need |
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## dev #219 +/- ##
==========================================
+ Coverage 92.73% 92.88% +0.14%
==========================================
Files 11 11
Lines 303 309 +6
==========================================
+ Hits 281 287 +6
Misses 22 22
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
You're right, thanks. Fixed that now, but I still get some broken tests (e.g. here. Is this expected? |
Yes. Some of the broken tests are because you are looking at CPU tests, where some tests are excluded and get marked as broken. The remaining broken tests are explained here #87 . So no further action on your part needed here. I will finish my review shortly, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this as is. Many thanks.
However, perhaps you would consider one additional enhancement, for consistency:
The MulitargetNeuralNetworkRegressor accepts the target as a table, but not as a matrix. It seems this would not be difficult to fix (but I haven't checked):
- In
fitresult(model::MultitargetNeuralNetworkRegressor, chain, y)
method returnnothing
instead ofTable.schema(y).names
ify
is a matrix. - In
shape
make the change for treatingy
you already have made forX
. - In
predict
return a matrix iftarget_column_names
isnothing
.
If you'd rather proceed as we are, then I'll just open an new issue and reference this comment.
Thanks, good idea! I've made the necessary adjustments and updated tests accordingly. Had to make one additional small modification to the |
src/core.jl
Outdated
@@ -224,6 +224,7 @@ by `model.batch_size`.) | |||
|
|||
""" | |||
function collate(model, X, y) | |||
y = y isa Matrix ? Tables.table(y) : y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to understand why this fix was needed. The nrows
function is supposed to work for matrices as well as tables:
using MLJBase
julia> y = rand(2, 6)
julia> nrows(y)
2
julia> nrows(y')
6
And line 230 below should already take care of the conversion of y
to a matrix, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was giving me an error previously, because the nrows
method defined in the same file expects a table (or else it throws an ArgumentError
. I've adjusted that and tests are passing.
Co-authored-by: Anthony Blaom, PhD <[email protected]>
@@ -141,6 +141,7 @@ function nrows(X) | |||
return length(cols[1]) | |||
end | |||
nrows(y::AbstractVector) = length(y) | |||
nrows(X::AbstractMatrix) = size(X, 1) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. We're not using nrows
from MLJBase.jl - I forgot. Thanks for humouring me with the explanation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to go.
Closes #218