请不要将此标记为如何从Matlab调用Python和sklearn?,因为我认为该问题并没有得到真正的回答。
自Matlab Release R2014b以来,我认为可以直接从Matlab中使用Python。简而言之,您只需要在Python调用前加上
在我的设置中(在使用
自Matlab Release R2014b以来,我认为可以直接从Matlab中使用Python。简而言之,您只需要在Python调用前加上
py
。在我的设置中(在使用
pyversion('PATH_TO_PYTHON')
命令给Matlab提供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>
回到问题本身:我已经安装了sklearn并且可以从引用的Python安装中使用它。它的工作方式与dask相同。但是MATLAB R2017a无法找到sklearn。
类似于上述给出的py.sklearn.cluster.dbscan
的调用结果为:
Undefined variable "py" or class "py.sklearn.cluster.dbscan".
有没有python专家能够解释一下?
pyversion
即可。您是否百分之百确定在控制台和 MATLAB 中使用了相同的 Python 版本?您可以尝试创建一个新的虚拟环境,并在 MATLAB 中使用该环境中的 sklearn。 - hbaderts