Reputation: 295
I am using R and I want to use a function I wrote in Python which needs to import:
from sklearn.neighbors.kde import KernelDensity
I am trying to use the following code:
library(reticulate)
py_install("scikit-learn.neighbors.kde")
I have already installed sklearn with:
py_install("scikit-learn")
Also trying
py_install("sklearn.neighbors.kde")
does not work.
I get the following error/log:
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- scikit-learn.neighbors.kde
Current channels:
- https://conda.anaconda.org/conda-forge/win-64
- https://conda.anaconda.org/conda-forge/noarch
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
Error: one or more Python packages failed to install [error code 1]
Any suggestion on how to fix this?
Upvotes: 0
Views: 803
Reputation: 46908
The module is KernelDensity
not kde
. If sklearn is installed, below should work:
library(reticulate)
sklearn = import("sklearn")
kde = sklearn$neighbors$KernelDensity
kde
<class 'sklearn.neighbors._kde.KernelDensity'>
X = matrix(rnorm(20),10,1)
kde = kde(kernel="gaussian")$fit(X)
kde$score_samples(X)
[1] -1.479458 -1.603451 -1.338018 -1.465263 -1.655933 -1.463628 -1.340137
[8] -1.856085 -1.374666 -1.478621
Upvotes: 1