sklearnex(sklearn-intel-extension)真的支持线性回归吗?

huangapple go评论65阅读模式
英文:

Does sklearnex (sklearn-intel-extension) really support linear regression?

问题

我尝试使用 sklearnex/scikit-learn-intelex 来进行 GPU 加速。这是我的代码,学习自 'Patching several algorithms:':

try:
    from sklearnex import patch_sklearn
    patch_sklearn()
except:
    pass
patch_sklearn(['PCA','LinearRegression'])

根据官方文档,该包支持线性回归。然而,在我的机器上它返回以下错误:

> Intel(R) Extension for Scikit-learn* enabled (https://github.com/intel/scikit-learn-intelex)
> Traceback (most recent call last):
> File "/home/path/tmp_test.py", line 16, in <module>
> patch_sklearn(['PCA','LinearRegression'])
> File "/usr/local/lib/python3.9/site-packages/sklearnex/dispatcher.py", line 177, in patch_sklearn
> patch_sklearn_orig(algorithm, verbose=False, deprecation=False,
> File "/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py", line 127, in enable
> do_patch(name, get_map)
> File "/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py", line 111, in do_patch
> raise ValueError("Has no patch for: " + name)
> ValueError: Has no patch for: LinearRegression

我的代码有什么问题?该文档支持线性回归,并且我按照示例中的方式操作。

当我只对 PCA 进行补丁时,算法正常工作。我正在使用这个包的最新版本。如果我不导入 sklearnex,原始的 sklearn 正常工作。

英文:

I'm trying to use sklearnex/scikit-learn-intelex for GPU accelaration. This is my code, learnt from 'Patching several algorithms:':

try:
    from sklearnex import patch_sklearn
    patch_sklearn()
except:
    pass
patch_sklearn([&#39;PCA&#39;,&#39;LinearRegression&#39;])

Apparently the package suppports linear regression. However, it returns the following error on my machine:

&gt; Intel(R) Extension for Scikit-learn* enabled (https://github.com/intel/scikit-learn-intelex)
&gt; Traceback (most recent call last):
&gt; File &quot;/home/path/tmp_test.py&quot;, line 16, in &lt;module&gt;
&gt; patch_sklearn([&#39;PCA&#39;,&#39;LinearRegression&#39;])
&gt; File &quot;/usr/local/lib/python3.9/site-packages/sklearnex/dispatcher.py&quot;, line 177, in patch_sklearn
&gt; patch_sklearn_orig(algorithm, verbose=False, deprecation=False,
&gt; File &quot;/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py&quot;, line 127, in enable
&gt; do_patch(name, get_map)
&gt; File &quot;/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py&quot;, line 111, in do_patch
&gt; raise ValueError(&quot;Has no patch for: &quot; + name)
&gt; ValueError: Has no patch for: LinearRegression

What's wrong with my code? The package supports linear regression and I did exactly the way in the example

When I patch PCA only, the algo works normaly. I'm using the latest version of this package.. The original sklearn works fine if I don't import sklearnex.

答案1

得分: 0

修复代码本身 - 这会起作用,但这不是清晰的命名,需要修复 - https://github.com/intel/scikit-learn-intelex/pull/1343

patch_sklearn(['PCA', 'Linear'])

patch_sklearn() 仅会影响您的 CPU 代码 - 即常规的 scikit 代码。

在 GPU 的情况下,scikit-learn 本身没有 GPU 支持的概念。

要在 GPU 上运行(注意:仅支持英特尔 GPU ),您需要使用 config_context 进行显式定义,或将 GPU 数据(dpctl 张量)传递给算法
https://intel.github.io/scikit-learn-intelex/oneapi-gpu.html

英文:

Fix for code itself - this would work, but this is not clear naming that would be fixed - https://github.com/intel/scikit-learn-intelex/pull/1343

patch_sklearn(['PCA','Linear'])

patch_sklearn() would affect only your CPU code - i.e. regular scikit code.

In case of GPU there is no notion of GPU support in scikit-learn itself.

To run on GPU (note: only Intel GPUs support ) you ether have to use explicit definition with config_context or pass GPU data(dpctl tensor) to algorithm
https://intel.github.io/scikit-learn-intelex/oneapi-gpu.html

huangapple
  • 本文由 发表于 2023年6月8日 18:07:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430760.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定