Skip to content
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

More sophisticated example of learning networks #9

Open
tlienart opened this issue Oct 22, 2019 · 3 comments
Open

More sophisticated example of learning networks #9

tlienart opened this issue Oct 22, 2019 · 3 comments
Labels

Comments

@tlienart
Copy link
Collaborator

tlienart commented Oct 22, 2019

@ablaom it would be nice to have a quick example of something that can't be done with a pipeline; I was thinking something like

L1 : standardizer and boxcox
L2 : Ridge and DTR
L3 : hcat and feed to a LinearRegressor

It should look something like this

W = X |> Standardizer()
z = y |> UnivariateBoxCoxTransformer()
ẑ₁ = (W, z) |> RidgeRegressor()
ẑ₂ = (W, z) |> DecisionTreeRegressor()
R = hcat(ẑ₁, ẑ₂)
ẑ = (R, z) |> LinearRegressor()
ŷ =|> inverse_transform(z)

but it looks like there's an issue with fitting the R node, could you comment on it?

ERROR: MethodError: no method matching ridge(::Array{Any,2}, ::Array{Float64,1}, ::Float64)
@tlienart
Copy link
Collaborator Author

Hmm the KNNRidge blend example is actually just that. But I'd still be curious to understand what I did wrong above

@ablaom
Copy link
Member

ablaom commented Oct 23, 2019

  • Your problem: LinearRegressor() expects a table but it is getting a matrix here. So you need to insert an MLJTable.

  • Another problem: You can't apply the inverse_transform directly to because it makes probablisitic predictions. So you need to insert a mean. Sadly, mean is not overloaded for nodes, so you need to use the node method to do this yourself

The following code works:

using MLJ

Xr, yr = @load_boston
zr = rand(length(yr))

X = source(Xr)
y = source(yr)
z = source(zr)

W = X |> Standardizer()
z = y |> UnivariateBoxCoxTransformer()
ẑ₁ = (W, z) |> @load RidgeRegressor pkg=MultivariateStats
ẑ₂ = (W, z) |> @load DecisionTreeRegressor
R = MLJ.table(hcat(ẑ₁, ẑ₂))
ẑ_prob = (R, z) |> @load LinearRegressor pkg=GLM
ẑ = node(v->mean.(v), ẑ_prob)
ŷ =|> inverse_transform(z)
fit!(ŷ)
ŷ()

Side comment: A great non-trivial example is stacking, as suggested by the diagram on the MLJ Readme.

@ablaom
Copy link
Member

ablaom commented Oct 23, 2019

Or you could have used predict_mean but then you couldn't use the arrow syntax, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants