# Buggy code
def fit(self, X, y, sample_weight=None):
    """Fit the SVM model according to the given training data.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        Training vectors, where n_samples is the number of samples
        and n_features is the number of features.

    y : array-like, shape (n_samples,)
        Target values (class labels in classification, real numbers in
        regression)

    sample_weight : array-like, shape (n_samples,)
        Per-sample weights. Rescale C per sample. Higher weights
        force the classifier to put more emphasis on these points.

    Returns
    -------
    self : object
        Returns self.

    Notes
    ------
    If X and y are not C-ordered and contiguous arrays of np.float64 and
    X is not a scipy.sparse.csr_matrix, X and/or y may be copied.

    If X is a dense array, then the other methods will not support sparse
    matrices as input.
    """

    rnd = check_random_state(self.random_state)

    sparse = sp.isspmatrix(X)
    if sparse and self.kernel == "precomputed":
        raise TypeError("Sparse precomputed kernels are not supported.")
    self._sparse = sparse and not callable(self.kernel)

    X = check_array(X, accept_sparse="csr", dtype=np.float64, order="C")
    y = self._validate_targets(y)

    sample_weight = np.asarray(
        [] if sample_weight is None else sample_weight, dtype=np.float64
    )
    solver_type = LIBSVM_IMPL.index(self._impl)

    # input validation
    if solver_type != 2 and X.shape[0] != y.shape[0]:
        raise ValueError(
            "X and y have incompatible shapes.\n"
            + "X has %s samples, but y has %s." % (X.shape[0], y.shape[0])
        )

    if self.kernel == "precomputed" and X.shape[0] != X.shape[1]:
        raise ValueError("X.shape[0] should be equal to X.shape[1]")

    if sample_weight.shape[0] > 0 and sample_weight.shape[0] != X.shape[0]:
        raise ValueError(
            "sample_weight and X have incompatible shapes: "
            "%r vs %r\n"
            "Note: Sparse matrices cannot be indexed w/"
            "boolean masks (use `indices=True` in CV)." % (sample_weight.shape, X.shape)
        )

    if (self.kernel in ["poly", "rbf"]) and (self.gamma == 0):
        # if custom gamma is not provided ...
        self._gamma = 1.0 / X.shape[1]
    else:
        self._gamma = self.gamma

    kernel = self.kernel
    if callable(kernel):
        kernel = "precomputed"

    fit = self._sparse_fit if self._sparse else self._dense_fit
    if self.verbose:  # pragma: no cover
        print("[LibSVM]", end="")

    seed = rnd.randint(np.iinfo("i").max)
    fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)
    # see comment on the other call to np.iinfo in this file

    self.shape_fit_ = X.shape

    # In binary case, we need to flip the sign of coef, intercept and
    # decision function. Use self._intercept_ and self._dual_coef_ internally.
    self._intercept_ = self.intercept_.copy()
    self._dual_coef_ = self.dual_coef_
    if self._impl in ["c_svc", "nu_svc"] and len(self.classes_) == 2:
        self.intercept_ *= -1
        self.dual_coef_ = -self.dual_coef_

    return self


# 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 fit(self, X, y, sample_weight=None):
    """Fit the SVM model according to the given training data.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        Training vectors, where n_samples is the number of samples
        and n_features is the number of features.
        For kernel="precomputed", the expected shape of X is
        (n_samples, n_samples).

    y : array-like, shape (n_samples,)
        Target values (class labels in classification, real numbers in
        regression)

    sample_weight : array-like, shape (n_samples,)
        Per-sample weights. Rescale C per sample. Higher weights
        force the classifier to put more emphasis on these points.

    Returns
    -------
    self : object
        Returns self.

    Notes
    ------
    If X and y are not C-ordered and contiguous arrays of np.float64 and
    X is not a scipy.sparse.csr_matrix, X and/or y may be copied.

    If X is a dense array, then the other methods will not support sparse
    matrices as input.
    """

    rnd = check_random_state(self.random_state)

    sparse = sp.isspmatrix(X)
    if sparse and self.kernel == "precomputed":
        raise TypeError("Sparse precomputed kernels are not supported.")
    self._sparse = sparse and not callable(self.kernel)

    X = check_array(X, accept_sparse="csr", dtype=np.float64, order="C")
    y = self._validate_targets(y)

    sample_weight = np.asarray(
        [] if sample_weight is None else sample_weight, dtype=np.float64
    )
    solver_type = LIBSVM_IMPL.index(self._impl)

    # input validation
    if solver_type != 2 and X.shape[0] != y.shape[0]:
        raise ValueError(
            "X and y have incompatible shapes.\n"
            + "X has %s samples, but y has %s." % (X.shape[0], y.shape[0])
        )

    if self.kernel == "precomputed" and X.shape[0] != X.shape[1]:
        raise ValueError("X.shape[0] should be equal to X.shape[1]")

    if sample_weight.shape[0] > 0 and sample_weight.shape[0] != X.shape[0]:
        raise ValueError(
            "sample_weight and X have incompatible shapes: "
            "%r vs %r\n"
            "Note: Sparse matrices cannot be indexed w/"
            "boolean masks (use `indices=True` in CV)." % (sample_weight.shape, X.shape)
        )

    if (self.kernel in ["poly", "rbf"]) and (self.gamma == 0):
        # if custom gamma is not provided ...
        self._gamma = 1.0 / X.shape[1]
    else:
        self._gamma = self.gamma

    kernel = self.kernel
    if callable(kernel):
        kernel = "precomputed"

    fit = self._sparse_fit if self._sparse else self._dense_fit
    if self.verbose:  # pragma: no cover
        print("[LibSVM]", end="")

    seed = rnd.randint(np.iinfo("i").max)
    fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)
    # see comment on the other call to np.iinfo in this file

    self.shape_fit_ = X.shape

    # In binary case, we need to flip the sign of coef, intercept and
    # decision function. Use self._intercept_ and self._dual_coef_ internally.
    self._intercept_ = self.intercept_.copy()
    self._dual_coef_ = self.dual_coef_
    if self._impl in ["c_svc", "nu_svc"] and len(self.classes_) == 2:
        self.intercept_ *= -1
        self.dual_coef_ = -self.dual_coef_

    return self