在matlab中直接在python中使用sklearn

Bas*_*ing 6 python matlab scikit-learn

请不要将此标记为如何从matlab调用python和sklearn的副本?因为我认为这个问题没有真正回答.
自从Matlab Release R2014b我认为,可以直接使用matlab中的python.
简而言之,您只需要放在pypython调用前面.
我的设置(在使用命令为matlab提供python路径之后pyversion('PATH_TO_PYTHON'),运行正常.我甚至可以使用dask多处理.非常酷.例如,执行py.dask.distributed.Client结果

  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>
Run Code Online (Sandbox Code Playgroud)

回到这个问题:我已经安装了sklearn,可以从引用的python安装中使用它.它的工作方式与dask相同.但MATLAB R2017a无法找到sklearn.
对上面给出的类似调用py.sklearn.cluster.dbscan导致

Undefined variable "py" or class "py.sklearn.cluster.dbscan".
Run Code Online (Sandbox Code Playgroud)

有没有python专家能够解释?

Bas*_*ing 5

我从mathworks支持处获得了解决方案。
它读取的方式可能是python环境尚未完全设置。我被要求从Anaconda Prompt具有完全安排好的环境的内部启动matlab 。从那里运行matlab产生了想要的结果,因此可以使用例如sklearn。
进一步比较显示的差异,必须将来自python的更多目录添加到系统搜索路径。

我进一步了解到,运行该命令py.importlib.import_module(<MODULENAME>)将显示该python模块及其依赖项是否可用的详细信息。