cstjean / ScikitLearn.jl

Julia implementation of the scikit-learn API https://cstjean.github.io/ScikitLearn.jl/dev/
Other
547 stars 75 forks source link

Questions on importing #108

Open jzsfvss opened 2 years ago

jzsfvss commented 2 years ago

I have a couple of basic questions regarding the instructions on the page: ScikitLearn.jl > Python models.

(1) How do you run the following command from a .jl file? It throws me an error if I just paste it into a file, though runs fine in the REPL. @sk_import linear_model: LinearRegression

(2) The following command runs fine from a .jl file, but I get an error that LinearRegression is undefined when I try to use it. Conda.add("scikit-learn") Do I need to add more code to import a subroutine like LinearRegression?

cstjean commented 2 years ago

Can you please post the error messages too? eg.

julia> using ScikitLearn

julia> @sk_import linear_model: LinearRegression
ERROR: LoadError: UndefVarError: @sk_import not defined
in expression starting at REPL[9]:1
jzsfvss commented 2 years ago

(1) I'm only getting an error if @sk_import is within a try-catch statement:

ERROR: LoadError: syntax: unsupported const declaration on local variable around C:\Users\jvass.julia\packages\ScikitLearn\ssekP\src\Skcore.jl:197 Stacktrace: [1] top-level scope @ C:\Users\jvass\PATH\main.jl:43 [2] include(fname::String) @ Base.MainInclude .\client.jl:451 [3] top-level scope @ REPL[2]:1 in expression starting at...

If @sk_import is placed outside a try-catch, then I only get a warning (on a re-run). Note that I'm actually trying to load MLPClassifier and not LinearRegression (just wanted to be consistent with your webpage).

WARNING: redefinition of constant MLPClassifier. This may fail, cause incorrect answers, or produce other errors.

Btw, how do I silence such warnings?

(2) The error for my second question (again, when within a try-catch):

ERROR: LoadError: UndefVarError: MLPClassifier not defined Stacktrace: [1] top-level scope @ C:\Users\jvass\PATH\main.jl:172 [2] include(fname::String) @ Base.MainInclude .\client.jl:451 [3] top-level scope @ REPL[2]:1 in expression starting at...

cstjean commented 2 years ago

If try/catch is the problem, then I guess you'll have to avoid using them? Why do you use them?

Please post the full code + error message next time. To quote code, you can use ```

Btw, how do I silence such warnings?

Suppressor.jl, maybe?

jzsfvss commented 2 years ago

Ok, so @sk_import does not work within try-catch at all?

Yes, I've tried Suppressor.jl but it gives an error when around @sk_import. So no -silence mode or similar?

Could this be a general issue, @sk_import just doesn't work well in blocks?

cstjean commented 2 years ago

Could this be a general issue, @sk_import just doesn't work well in blocks?

Quite likely. It's not a typical use case. It could probably be fixed, but it would be complicated macro work, so I wouldn't count on it, and I would look for other ways of achieving the same outcome if I were you.