zlq178
March 2, 2022, 7:46am
1
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”
Why can’t I call predict function.
nilshg
March 2, 2022, 8:04am
2
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?
zlq178
March 2, 2022, 8:29am
4
But I try another environment on Julia 1.7.1
It shows wrong: Failed to precompile MLJDecisionTreeInterface.
What’s the problem?
zlq178
March 2, 2022, 8:48am
5
I rewrite the yhat = predict(mach, X[test,:])
as yhat = MLJ.predict(mach, X[test,:])
It works!
1 Like