MLJScikitLearn Interface Import Error


I am rather new to the forums, and I came across an interesting error in Pumas while trying to fit a model:

import MLJScikitLearnInterface[ Info: Installing sklearn via the Conda scikit-learn package...
[ Info: Running `conda install -y scikit-learn` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

ERROR: InitError: PyError (PyImport_ImportModule

The Python package sklearn could not be imported by pyimport. Usually this means
that you did not install sklearn in the Python version being used by PyCall.

PyCall is currently configured to use the Julia-specific Python distribution
installed by the Conda.jl package.  To install the sklearn module, you can
use `pyimport_conda("sklearn", PKG)`, where PKG is the Anaconda
package that contains the module sklearn, or alternatively you can use the
Conda package directly (via `using Conda` followed by `Conda.add` etcetera).

Alternatively, if you want to use a different Python distribution on your
system, such as a system-wide Python (as opposed to the Julia-specific Python),
you can re-configure PyCall with that Python.   As explained in the PyCall
documentation, set ENV["PYTHON"] to the path/name of the python executable
you want to use, run"PyCall"), and re-launch Julia.

Here is the stack trace for reference:

[1] pyimport(name::String)
    @ PyCall ~/data/.julia/packages/PyCall/7a7w0/src/PyCall.jl:550
  [2] pyimport_conda(modulename::String, condapkg::String, channel::String)
    @ PyCall ~/data/.julia/packages/PyCall/7a7w0/src/PyCall.jl:714
  [3] pyimport_conda
    @ ~/data/.julia/packages/PyCall/7a7w0/src/PyCall.jl:707 [inlined]
  [4] import_sklearn()
    @ ScikitLearn.Skcore ~/data/.julia/packages/ScikitLearn/ssekP/src/Skcore.jl:156
  [5] __init__()
    @ MLJScikitLearnInterface ~/data/.julia/packages/MLJScikitLearnInterface/I8FSe/src/MLJScikitLearnInterface.jl:11
  [6] _include_from_serialized(path::String, depmods::Vector{Any})
    @ Base ./loading.jl:768
  [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String)
    @ Base ./loading.jl:854
  [8] _require(pkg::Base.PkgId)
    @ Base ./loading.jl:1097
  [9] require(uuidkey::Base.PkgId)
    @ Base ./loading.jl:1013
 [10] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:997
 [11] eval
    @ ./boot.jl:373 [inlined]
 [12] eval(x::Expr)
    @ Base.MainInclude ./client.jl:453
 [13] _import(modl::Module, api_pkg::Symbol, pkg::Symbol, doprint::Bool)
    @ MLJModels /builds/PumasAI/PumasSystemImages-jl/.julia/packages/MLJModels/ZryaP/src/loading.jl:34
 [14] top-level scope
    @ /builds/PumasAI/PumasSystemImages-jl/.julia/packages/MLJModels/ZryaP/src/loading.jl:206
during initialization of module MLJScikitLearnInterface

caused by: PyError (PyImport_ImportModule

If anyone has any suggestions I would greatly appreciate it!

Hello Albert,

We don’t support Python dependencies in PumasIDE so I’d recommend trying one of the native Julia package for similar tasks.

Andreas Noack

I used to be able to run ML models from ScikitLearn in the 2.0 version. Was this removed in 2.1 ?

We have never shipped ScikitLearn. It might have been possible to install it in previous version of Pumas. As mentioned, it’s not supported but unsupported functionality might sometimes work anyway. But again, I’d recommend using a native Julia package for your machine learning tasks.

Thank you, Andreas. The native Julia packages I know are DecisionTree, XGBoost, and LIBSVM

Some algorithms I am interested in testing are AdaBoost, BayesianQDA, ExtraTrees, and KNN among others which I think are not available in the native Julia packages. Could you let me know any packages that might help with these algorithms?

NVM. I found them in native Julia packages. Thanks for your responses, Andreas!

  • AdaBoostStumpClassifier, DecisionTreeClassifier, RandomForestClassifier from DecisionTree
  • XGBoostClassifier from XGBoost
  • LDA, BayesianLDA from MultivariateStats
  • GaussianNBClassifier from NaiveBayes
  • KNNClassifier from NearestNeighborModels
  • LGBMClassifier from LightGBM
  • LogisticClassifier from MLJLinearModels
  • SVC, LinearSVC from LIBSVM
1 Like