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

Machine abstract type? #188

Closed
MilesCranmer opened this issue Jan 7, 2024 · 3 comments · Fixed by JuliaAI/MLJBase.jl#951
Closed

Machine abstract type? #188

MilesCranmer opened this issue Jan 7, 2024 · 3 comments · Fixed by JuliaAI/MLJBase.jl#951

Comments

@MilesCranmer
Copy link
Contributor

Hey all,

I want to create a default plot interface for a fitted regressor in SymbolicRegression.jl. However I'm not sure what type to write it for. Is there a good abstract type I can specialize to for creating plots?

e.g.,

julia> typeof(mach)
Machine{SRRegressor{DynamicQuantities.SymbolicDimensions{DynamicQuantities.FixedRational{Int32, 25200}}, DataType, false}, true}

I would like to create a method for

julia> plot(mach)

One way is by creating an extension to MLJBase but I'm wondering if there's just an abstract type for, say, AbstractMachine{SRRegressor}.

Cheers,
Miles

@ablaom
Copy link
Member

ablaom commented Jan 7, 2024

You raise a good question here. Currently we have a plot recipe for machines bound to TunedModels; see here, but this happens in MLJTuning which already has MLJBase as a dep. This was probably an unfortunate design.

I hadn't thought of adding an AbstractMachine type to MLJModelInterface. I tend to think of machines as a completely separate, higher level interface. Another idea is to implement your recipe for thefitresult returned by your implementation of MLJModelInterface.fit (in SymbolicRegression.jl) and we add a generic overloading of plot recipes for machines in MLJBase; something like:

PlotRecipes.plot(mach::Machine) = plot(machine.fitresult)

What do you think?

@MilesCranmer
Copy link
Contributor Author

I hadn't thought of adding an AbstractMachine type to MLJModelInterface. I tend to think of machines as a completely separate, higher level interface. Another idea is to implement your recipe for thefitresult returned by your implementation of MLJModelInterface.fit (in SymbolicRegression.jl) and we add a generic overloading of plot recipes for machines in MLJBase; something like:

PlotRecipes.plot(mach::Machine) = plot(machine.fitresult)

What do you think?

That’s a good way to do it! I would be quite content with this.

@MilesCranmer
Copy link
Contributor Author

MilesCranmer commented Jan 8, 2024

Quick addendum: I think it should instead be:

@recipe function default_machine_plot(mach::Machine)
    mach.fitresult
end

which is the idiomatic way to do it https://docs.juliaplots.org/latest/RecipesBase/syntax/ and will automatically forward all plotting information.

And it should be RecipesBase which is the interface package (rather than PlotRecipes)

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

Successfully merging a pull request may close this issue.

2 participants