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

Questions on importing #108

Open
jzsfvss opened this issue Feb 18, 2022 · 5 comments
Open

Questions on importing #108

jzsfvss opened this issue Feb 18, 2022 · 5 comments

Comments

@jzsfvss
Copy link

jzsfvss commented Feb 18, 2022

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
Copy link
Owner

cstjean commented Feb 18, 2022

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
Copy link
Author

jzsfvss commented Feb 18, 2022

(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
Copy link
Owner

cstjean commented Feb 18, 2022

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
Copy link
Author

jzsfvss commented Feb 18, 2022

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
Copy link
Owner

cstjean commented Feb 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants