相关疑难解决方法(0)

LabelPropagation - 如何避免被零除?

当使用LabelPropagation时,我经常遇到这个警告(imho它应该是一个错误,因为它完全无法传播):

/usr/local/lib/python3.5/dist-packages/sklearn/semi_supervised/label_propagation.py:279:运行时警告:在true_divide self.label_distributions_/= normalizer中遇到无效值

因此,在几次尝试使用RBF内核之后,我发现参数gamma有影响.

编辑:

问题来自这些方面:

        if self._variant == 'propagation':
            normalizer = np.sum(
                self.label_distributions_, axis=1)[:, np.newaxis]
            self.label_distributions_ /= normalizer
Run Code Online (Sandbox Code Playgroud)

我不知道label_distributions_如何都是零,特别是当它的定义是:

self.label_distributions_ = safe_sparse_dot(
graph_matrix, self.label_distributions_)
Run Code Online (Sandbox Code Playgroud)

Gamma对graph_matrix有影响(因为graph_matrix是调用内核函数的_build_graph()的结果).好.但仍然.出了点问题

旧帖子(编辑前)

我提醒你如何计算传播的图权重:W = exp(-gamma*D),D是数据集所有点之间的成对距离矩阵.

问题是:np.exp(x) 如果x非常小,返回0.0.
让我们想象一下,我们有两点i也是j如此dist(i, j) = 10.

>>> np.exp(np.asarray(-10*40, dtype=float)) # gamma = 40 => OKAY
1.9151695967140057e-174
>>> np.exp(np.asarray(-10*120, dtype=float)) # gamma = 120 => NOT OKAY
0.0
Run Code Online (Sandbox Code Playgroud)

在实践中,我不是手动设置伽玛,而是使用本文中描述的方法(第2.4节).

那么,如何避免这种划分为零以获得适当的传播?

我能想到的唯一方法是在每个维度中规范化数据集 …

python numpy machine-learning scikit-learn

18
推荐指数
1
解决办法
585
查看次数

标签 统计

machine-learning ×1

numpy ×1

python ×1

scikit-learn ×1