# MLJ KNNRegressor BruteTree broken for predict-- load error brutetree has no field indices...?

**URL:** <https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837>\
**Category:** Machine Learning\
**Tags:** mlj\
**Created:** [January 18, 2022, 10:31pm UTC](https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837 "2022-01-18T22:31:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![diadora77](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diadora77/32/220469_2.png) [@diadora77](https://discourse.julialang.org/u/diadora77)\
**Post date:** [January 18, 2022, 10:31pm UTC](https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837/1 "2022-01-18T22:31:17Z")

</div>

Using MLJ’s NearestNeighbors KNNRegressor and attempted to use BruteTree algorithm. Get the following error when attempting to use predict: _ERROR: LoadError: type BruteTree has no field indices_ followed by usual stack trace.

Simple code showcasing the problem (same code example works fine for kdtree or balltree):

```julia
using DataFrames
using MLJ

X_rand = rand(50,3)
coef = [1; 0; 1]
y_rand = X_rand*coef + rand(50,1)

#convert to dataframe for MLJ inputs
X_rand_df = DataFrames.DataFrame(X_rand, :auto)
y_rand_df = DataFrames.DataFrame(y_rand, :auto)

train_idx, test_idx = partition(eachindex(y_rand_df[:,1]), 0.7, shuffle=true)

Tree = @load KNNRegressor
tree =Tree(algorithm=:brutetree)

mach = machine(tree, X_rand_df[train_idx, :], y_rand_df[train_idx, 1])

MLJ.fit!(mach)

MLJ.predict(mach, X_rand_df[test_idx,:])

```

I can provide the error stack I’m seeing if desired.

---

<div class="post-metadata">

**Author:** ![samuel\_okon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samuel_okon/32/10285_2.png) [@samuel\_okon](https://discourse.julialang.org/u/samuel_okon)\
**Post date:** [January 19, 2022, 9:47am UTC](https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837/2 "2022-01-19T09:47:53Z")

</div>

@diadora77 Sorry, its due to a bug. This will get fixed soon.

---

<div class="post-metadata">

**Author:** ![ablaom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ablaom/32/4889_2.png) [@ablaom](https://discourse.julialang.org/u/ablaom)\
**Post date:** [January 20, 2022, 12:05am UTC](https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837/3 "2022-01-20T00:05:51Z")

</div>

@diadora77 Thanks for reporting! Issue tracked [here](https://github.com/JuliaAI/NearestNeighborModels.jl/issues/45).

---

<div class="post-metadata">

**Author:** ![diadora77](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diadora77/32/220469_2.png) [@diadora77](https://discourse.julialang.org/u/diadora77)\
**Post date:** [January 20, 2022, 12:49am UTC](https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837/4 "2022-01-20T00:49:29Z")

</div>

Excellent! Thanks for taking a look!

---

<div class="post-metadata">

**Author:** ![diadora77](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/diadora77/32/220469_2.png) [@diadora77](https://discourse.julialang.org/u/diadora77)\
**Post date:** [January 22, 2022, 5:02pm UTC](https://discourse.julialang.org/t/mlj-knnregressor-brutetree-broken-for-predict-load-error-brutetree-has-no-field-indices/74837/5 "2022-01-22T17:02:51Z")

</div>

@samuel_okon Thanks for the fix!
