Sijun
November 11, 2019, 8:08am
1
module TestMod
using ScikitLearn: @sk_import
@sk_import linear_model: LogisticRegression
println(LogisticRegression)
export fun
function fun()
println(LogisticRegression)
end
end
When the above TestMod is imported, LogisticRegressionis imported and printed:
PyObject <class ‘sklearn.linear_model.logistic.LogisticRegression’>
But after that, strangely LogisticRegression becomes NULL:
julia> TestMod.LogisticRegression
PyObject NULL
julia> TestMod.fun()
PyObject NULL
Yeah that’s tricky, you need to place the import in the init function, see how I did it here
https://github.com/baggepinnen/HDBSCAN.jl/blob/master/src/HDBSCAN.jl
1 Like
Sijun
November 11, 2019, 1:15pm
3
@baggepinnen , it works very well! I don’t know what to say. Thank you so much!
Here is some small questions:
what benefit would the use of @eval give us? On the surface, all is fine without @eval .
How does the trick work?
You’ll find more info here
https://github.com/JuliaPy/PyCall.jl/blob/master/README.md#using-pycall-from-julia-modules
It seems there is a recommended approach slightly different from mine.
3 Likes
Sijun
November 11, 2019, 2:39pm
5
Aha, I understood what is happening now. Thank you!