# Buggy code
def _get_affinity_matrix(self, X, Y=None):
    """Caclulate the affinity matrix from data
    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training vector, where n_samples in the number of samples
        and n_features is the number of features.

        If affinity is "precomputed"
        X : array-like, shape (n_samples, n_samples),
        Interpret X as precomputed adjacency graph computed from
        samples.

    Returns
    -------
    affinity_matrix, shape (n_samples, n_samples)
    """
    if self.affinity == "precomputed":
        self.affinity_matrix_ = X
        return self.affinity_matrix_
    if self.affinity == "nearest_neighbors":
        if sparse.issparse(X):
            warnings.warn(
                "Nearest neighbors affinity currently does "
                "not support sparse input, falling back to "
                "rbf affinity"
            )
            self.affinity = "rbf"
        else:
            self.n_neighbors_ = (
                self.n_neighbors
                if self.n_neighbors is not None
                else max(int(X.shape[0] / 10), 1)
            )
            self.affinity_matrix_ = kneighbors_graph(X, self.n_neighbors_)
            # currently only symmetric affinity_matrix supported
            self.affinity_matrix_ = 0.5 * (
                self.affinity_matrix_ + self.affinity_matrix_.T
            )
            return self.affinity_matrix_
    if self.affinity == "rbf":
        self.gamma_ = self.gamma if self.gamma is not None else 1.0 / X.shape[1]
        self.affinity_matrix_ = rbf_kernel(X, gamma=self.gamma_)
        return self.affinity_matrix_
    self.affinity_matrix_ = self.affinity(X)
    return self.affinity_matrix_


# Traceback (AssertionError)
======================================================================
FAIL: Tests that class_weight and sample_weight are multiplicative
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/buildd/scikit-learn-0.16.0~b1+git1-gab4d07d/debian/python-sklearn/usr/lib/python2.7/dist-packages/sklearn/linear_model/tests/test_sgd.py", line 633, in test_weights_multiplied
assert_array_equal(clf1.coef_, clf2.coef_)
File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 718, in assert_array_equal
verbose=verbose, header='Arrays are not equal')
File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 644, in assert_array_compare
raise AssertionError(msg)
AssertionError:
Arrays are not equal

(mismatch 16.6666666667%)
x: array([[-0.34681637, -0.32240913, -0.31335029,  0.34920789,  0.3658206 ,
0.38752489]])
y: array([[-0.34681637, -0.32240913, -0.31335029,  0.34920789,  0.3658206 ,
0.38752489]])

# Fixed code
def _get_affinity_matrix(self, X, Y=None):
    """Caclulate the affinity matrix from data
    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training vector, where n_samples in the number of samples
        and n_features is the number of features.

        If affinity is "precomputed"
        X : array-like, shape (n_samples, n_samples),
        Interpret X as precomputed adjacency graph computed from
        samples.

    Returns
    -------
    affinity_matrix, shape (n_samples, n_samples)
    """
    if self.affinity == "precomputed":
        self.affinity_matrix_ = X
        return self.affinity_matrix_
    if self.affinity == "nearest_neighbors":
        if sparse.issparse(X):
            warnings.warn(
                "Nearest neighbors affinity currently does "
                "not support sparse input, falling back to "
                "rbf affinity"
            )
            self.affinity = "rbf"
        else:
            self.n_neighbors_ = (
                self.n_neighbors
                if self.n_neighbors is not None
                else max(int(X.shape[0] / 10), 1)
            )
            self.affinity_matrix_ = kneighbors_graph(
                X, self.n_neighbors_, include_self=True
            )
            # currently only symmetric affinity_matrix supported
            self.affinity_matrix_ = 0.5 * (
                self.affinity_matrix_ + self.affinity_matrix_.T
            )
            return self.affinity_matrix_
    if self.affinity == "rbf":
        self.gamma_ = self.gamma if self.gamma is not None else 1.0 / X.shape[1]
        self.affinity_matrix_ = rbf_kernel(X, gamma=self.gamma_)
        return self.affinity_matrix_
    self.affinity_matrix_ = self.affinity(X)
    return self.affinity_matrix_