Predict not defined

I run the following example in Common MLJ Workflows · MLJ (alan-turing-institute.github.io)

using MLJ,DataFrames
crabs = load_crabs() |> DataFrames.DataFrame
schema(crabs)
y, X = unpack(crabs, ==(:sp), !in([:index, :sex]); rng=123)
Tree = @load DecisionTreeClassifier pkg=DecisionTree
tree=Tree()
mach = machine(tree, X, y)
train, test = partition(eachindex(y), 0.7); 
fit!(mach, rows=train)
yhat = predict(mach, X[test,:])
mean(LogLoss(tol=1e-4)(yhat, y[test]))

But it shows “predict not defined”
image
Why can’t I call predict function.

Works fine for me in a fresh environment on Julia 1.7.2 and I get

julia> mean(LogLoss(tol=1e-4)(yhat, y[test]))
1.8421480783955033

which means you most l likely have either

a) outdated package versions (probably less likely given predict has always been defined afaik; or
b) loaded another package which exports predict and conflicts with MLJ’s predict (e.g. GLM)

Can you run the code in a fresh REPL session and a temp environment to isolate the issue?

But I try another environment on Julia 1.7.1
It shows wrong: Failed to precompile MLJDecisionTreeInterface.
What’s the problem?

I rewrite the yhat = predict(mach, X[test,:]) as yhat = MLJ.predict(mach, X[test,:])
It works!

1 Like