Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict errors for KNNRegressor when algorithm = :brutetree . #45

Closed
OkonSamuel opened this issue Jan 19, 2022 · 1 comment · Fixed by #47
Closed

predict errors for KNNRegressor when algorithm = :brutetree . #45

OkonSamuel opened this issue Jan 19, 2022 · 1 comment · Fixed by #47
Labels
bug Something isn't working

Comments

@OkonSamuel
Copy link
Member

A user on julia discourse, recently reported that the code below fails during the prediction phase.

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,:])
@OkonSamuel
Copy link
Member Author

OkonSamuel commented Jan 19, 2022

Further investigation shows that the above code also fails if KNNRegressor is replaced with any of the other exported KNN models, with algorithm=:brutetree.
This bug is because, although from the NearestNeighbors package, the :brutetree(BruteTree) constructor supports reorder and leafsize kwargs, they don't make sense in the predict phase. This is expected as BruteTree isn't actually a tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant