# Predict not defined

**URL:** <https://discourse.julialang.org/t/predict-not-defined/77276>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [March 2, 2022, 7:46am UTC](https://discourse.julialang.org/t/predict-not-defined/77276 "2022-03-02T07:46:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zlq178](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zlq178/32/17952_2.png) [@zlq178](https://discourse.julialang.org/u/zlq178)\
**Post date:** [March 2, 2022, 7:46am UTC](https://discourse.julialang.org/t/predict-not-defined/77276/1 "2022-03-02T07:46:31Z")

</div>

I run the following example in [Common MLJ Workflows · MLJ (alan-turing-institute.github.io)](https://alan-turing-institute.github.io/MLJ.jl/dev/common_mlj_workflows/)

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/5/0/5053c4e0d5038a960cd6836de00f062bd38c50cc.png)  
Why can’t I call predict function.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 2, 2022, 8:04am UTC](https://discourse.julialang.org/t/predict-not-defined/77276/2 "2022-03-02T08:04:41Z")

</div>

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

```julia
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?

---

<div class="post-metadata">

**Author:** ![zlq178](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zlq178/32/17952_2.png) [@zlq178](https://discourse.julialang.org/u/zlq178)\
**Post date:** [March 2, 2022, 8:29am UTC](https://discourse.julialang.org/t/predict-not-defined/77276/4 "2022-03-02T08:29:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zlq178](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zlq178/32/17952_2.png) [@zlq178](https://discourse.julialang.org/u/zlq178)\
**Post date:** [March 2, 2022, 8:48am UTC](https://discourse.julialang.org/t/predict-not-defined/77276/5 "2022-03-02T08:48:24Z")

</div>

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