MLJ.jl icon indicating copy to clipboard operation
MLJ.jl copied to clipboard

Wrap a simple R model

Open azev77 opened this issue 4 years ago • 1 comments

Hey guys, I'd like to wrap sprintr. Can you point me to an example of wrapping an R model in MLJ?

Here is the code for fit and predict

X = randn(100,5)
y = 7.0 .+ X[:,1] .+ 2.0 .* X[:,2] .* X[:,3] + 3*randn(100)
using RCall

function fitsprintr(X, y)
    @rput y X # put data from Julia to R.
    R"""
    library(sprintr);
     m <- cv.sprinter(x = X, y = y)
    """
    @rget m
    delete!(m, :call)
    delete!(m[:fit], :call)
    m
end
function predictsprintr(m, XH)
    @rput m XH # put data from Julia to R.
    R"""
    library(sprintr);
    class(m) <- 'cv.sprinter'
    pred <- predict(m, newdata = XH)
    """
    return @rget pred
end

m = fitsprintr(X, y)
yhat = predictsprintr(m, XH)

azev77 avatar Feb 16 '21 00:02 azev77

There are no R models currently wrapped. However, it seems you have already sorted out the R-jl interface.

It seems to me the next step is to understand the MLJ model interface, which is pretty well-documented, with lots of examples (pick any supervised learner): https://alan-turing-institute.github.io/MLJ.jl/dev/quick_start_guide_to_adding_models/

Let me know if you have questions about the documentation.

ablaom avatar Feb 17 '21 00:02 ablaom