cstjean / ScikitLearn.jl

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

mysterious error message #54

Open lewisl opened 5 years ago

lewisl commented 5 years ago

This is a fragment of the very long error message: expected return statement, got ($(QuoteNode(PyCall.pyimport)))("sklearn.tree")

This is the seemingly trivial code:


@sk_import ensemble: AdaBoostClassifier
@sk_import tree: DecisionTreeClassifier

function boost_tree(traindata)
    trainx = traindata[:,1:end-1]
    trainy = traindata[:,end]
    bdt = AdaBoostClassifier(base_estimator = DecisionTreeClassifier(max_depth=6), n_estimators=5)
    ScikitLearn.fit!(bdt, trainx, trainy)
    return bdt
end

No clue. Documentation is really tough to apply if you try anything slightly different than the examples. Translation from the Python doc to the Julia wrapper is definitely non-obvious.

lewisl commented 5 years ago

Somewhere I saw this little @macroexpand trick. It takes care of the problem with calling Python. Not clear why it's necessary and, if it is, why it's not documented explicitly:

using ScikitLearn

@macroexpand @sk_import ensemble: AdaBoostClassifier
@macroexpand @sk_import tree: DecisionTreeClassifier

function boost_tree(traindata)
    trainx = traindata[:,1:end-1]
    trainy = traindata[:,end]
    bdt = AdaBoostClassifier(DecisionTreeClassifier(max_depth=6), n_estimators=5) 
    ScikitLearn.fit!(bdt, trainx, trainy)
    return bdt
end

Now, I get the strange outcome that DecisionTreeClassifier is an undefined variable:

ERROR: UndefVarError: DecisionTreeClassifier not defined
lewisl commented 5 years ago

Further bizarreness. This all works when each line is entered in the REPL. So, this has to do with some namespace munging involving the macro expansion.

I'll note that there are a lot of deprecation warnings with this packages use of PyCall and the appropriate notation.

cstjean commented 5 years ago

Sorry, I haven't been able to put much time into this package recently. Contributions to the docs are welcome.

If you try the latest master, with ]add ScikitLearn#master, it should get rid of most of the deprecation warnings, at least. I'll try to look at the errors when I get a chance. You can always try to use PyCall (check its docs) directly to import the modules you want.

cstjean commented 5 years ago

Is this fixed on the latest version?