Using sklearn directly in python from inside matlab

Please do not mark this as a duplicate, how to call python and sklearn from matlab? , since the question, in my opinion, did not answer.
Since Matlab Release R2014b, I think you can directly use python from matlab .
In short, you need to place py before calling python.
I installed (after giving matlab a python path using the pyversion('PATH_TO_PYTHON') , which works fine. I can even use dask multiprocessing. dask . For example, executing py.dask.distributed.Client result in

  Python Client with properties: asynchronous: 0 cluster: [1×1 py.distributed.deploy.local.LocalCluster] get_futures_error: [1×1 py.method] coroutines: [1×1 py.list] scheduler_file: [1×1 py.NoneType] loop: [1×1 py.tornado.platform.select.SelectIOLoop] recreate_error_locally: [1×1 py.method] refcount: [1×1 py.collections.defaultdict] extensions: [1×1 py.dict] scheduler: [1×1 py.distributed.core.rpc] rpc: [1×1 py.distributed.core.ConnectionPool] futures: [1×1 py.dict] scheduler_comm: [1×1 py.distributed.batched.BatchedSend] status: [1×7 py.str] connection_args: [1×1 py.dict] id: [1×43 py.str] generation: [1×1 py.int] io_loop: [1×1 py.tornado.platform.select.SelectIOLoop] security: [1×1 py.distributed.security.Security] <Client: scheduler='tcp://127.0.0.1:59795' processes=4 cores=4> 

Returning to the question: I installed sklearn and can use it from the specified python installation. It works the same as dask. But MATLAB R2017a cannot find sklearn.
A similar call to the above py.sklearn.cluster.dbscan leads to

 Undefined variable "py" or class "py.sklearn.cluster.dbscan". 

Is there any python expert able to explain?

+5
python scikit-learn matlab
Aug 30 '17 at 5:30
source share
1 answer

I got a solution from mathworks support .
He reads that perhaps the python environment is not fully configured. I was asked to start matlab from Anaconda Prompt , which has this finished environment. Starting Matlab from there gave the desired results, which allowed the use of, for example, sklearn.
A further comparison of the differences between them showed that several more directories from python need to be added to the system search path.

Next I learned that running py.importlib.import_module(<MODULENAME>) will show the details if this python module and its dependencies are available or not.

+3
Aug 31 '17 at 12:48 on
source share



All Articles