在 matlab 中直接在 python 中使用 sklearn [英] Using sklearn directly in python from within matlab

查看:26
本文介绍了在 matlab 中直接在 python 中使用 sklearn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请不要将此标记为重复如何调用python和来自 matlab 的 sklearn? 因为在我看来这个问题并没有真正得到解答.
由于我认为 Matlab Release R2014b,可以直接使用来自 matlab 的 python.
简而言之,您只需要将 py 放在 python 调用的前面.
我的设置(在使用命令 pyversion('PATH_TO_PYTHON') 为 matlab 提供 python 路径后,运行良好.我什至可以使用 dask 多处理.非常酷.对于例如,执行 py.dask.distributed.Client 结果

Please do not mark this as a duplicate of how to call python and sklearn from matlab? as the question is in my opinion not really answered.
Since Matlab Release R2014b I think, it is possible to directly use python from matlab.
In short words, you only have to place py in front of the python call.
I my setup (after giving matlab the python path with the command pyversion('PATH_TO_PYTHON'), that is running fine. I can even use dask multiprocessing. Quite cool. For example, executing py.dask.distributed.Client results 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>

回到问题:我已经安装了 sklearn 并且可以从引用的 python 安装中使用它.它的工作方式与 dask 相同.但是MATLAB R2017a 找不到sklearn.
对上述 py.sklearn.cluster.dbscan 的类似调用导致

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

有没有python高手能解释一下?

Is there any python expert being able to explain?

推荐答案

我从 the mathworks Support.
它的读取方式可能是python环境没有完全设置好.我被要求从具有完整排列环境的 Anaconda Prompt 中启动 matlab.从那里运行 matlab 产生了想要的结果,因此能够使用例如 sklearn.
进一步比较与那里的差异显示,必须将更多来自 python 的目录添加到系统搜索路径中.

I got a solution from the mathworks Support.
It reads the way, that maybe the python environment is not completely setup. I was asked to start matlab from within the Anaconda Prompt which has that complete arranged environment. Running matlab from there yielded the wanted results thus being able to use for example sklearn.
Further comparing the diffenrences from there showed up, that some more directories from python have to be added to the systems search path.

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

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

这篇关于在 matlab 中直接在 python 中使用 sklearn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆