python - 与原生 sklearn 相比,Dask 性能较慢

标签 python scikit-learn dask

我是 Dask 的新手,但在尝试在 Dask 中重写 native sklearn 函数时遇到了令人痛苦的缓慢性能。我已经尽可能地简化了用例,希望能得到一些帮助。

使用标准的 sklearn/numpy/pandas 等我有以下内容:

df = pd.read_csv(location, index_col=False) # A ~75MB CSV
# Build feature list and dependent variables, code irrelevant

from sklearn import linear_model
model = linear_model.Lasso(alpha=0.1, normalize=False, max_iter=100, tol=Tol)
model.fit(features.values, dependent)
print(model.coef_)
print(model.intercept_)

这需要几秒钟的时间来计算。然后我在 Dask 中有以下内容:

# Read in CSV and prepare params like before but using dask arrays/dataframes instead

with joblib.parallel_backend('dask'):
    from dask_glm.estimators import LinearRegression
    # Coerce data
    X = self.features.to_dask_array(lengths=True)
    y = self.dependents

    # Build regression
    lr = LinearRegression(fit_intercept=True, solver='admm', tol=self.tolerance, regularizer='l1', max_iter=100, lamduh=0.1)
    lr.fit(X, y)

    print(lr.coef_)
    print(lr.intercept_)

这需要很长时间来计算(大约 30 分钟)。我的开发集群中只有 1 个 Dask worker,但它有 16GB 内存和无限 CPU。

有人知道为什么这么慢吗?

希望我的代码遗漏不是很大!

注意:这是在人们问为什么甚至使用 Dask 之前最简单的用例 - 这被用作概念验证练习以检查事物是否按预期运行。

最佳答案

您可能要考虑的文档引述:

For large arguments that are used by multiple tasks, it may be more efficient to pre-scatter the data to every worker, rather than serializing it once for every task. This can be done using the scatter keyword argument, which takes an iterable of objects to send to each worker.

但总的来说,Dask 有很多可用的诊断信息,尤其是调度程序的仪表板,可以帮助您了解您的员工在做什么以及时间是如何花费的——您最好调查一下。与任何计算一样,其他系统范围的因素也非常重要:例如,您离内存容量还有多远?

不过,总的来说,Dask 并不神奇,当数据适合内存时,肯定会出现 dask 增加大量开销的情况。仔细阅读有关您正在考虑的方法的预期用途的文档 - 它是否应该加快速度,或者仅仅允许您处理比系统通常适合的更多数据?

关于python - 与原生 sklearn 相比,Dask 性能较慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53320649/

相关文章:

python - Ubuntu Box 偶尔使用 Twitter API 浪费时间

python - PCA 用于分类特征?

python - dask 数据帧中 .join 的结果似乎取决于 dask 数据帧的生成方式

python - 关于永远只在本地运行 Flask 应用程序的建议

python - 检查 python azure 中是否存在 blob

python - Django 的 TinyMCE

python - 如何提前判断 CountVectorizer 是否会抛出 ValueError : empty vocabulary?

python - 为什么 scikit 学习分词器不能正确分词 utf-8(葡萄牙语)文本?

python - 并行化数百万次 Numpy 函数迭代

python - Dask DataFrame Groupby : Most frequent value of column in aggregate