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

    y : array-like, shape (n_samples,)
        Target vector relative to X.

    sample_weight : array-like, shape (n_samples,)
        Weight given to each sample.

    Returns
    -------
    self : object
    """
    X, y = check_X_y(X, y, copy=False, accept_sparse=["csr"], y_numeric=True)
    if sample_weight is not None:
        sample_weight = np.array(sample_weight)
        check_consistent_length(y, sample_weight)
    else:
        sample_weight = np.ones_like(y)

    if self.epsilon < 1.0:
        raise ValueError(
            "epsilon should be greater than or equal to 1.0, got %f" % self.epsilon
        )

    if self.warm_start and hasattr(self, "coef_"):
        parameters = np.concatenate((self.coef_, [self.intercept_, self.scale_]))
    else:
        if self.fit_intercept:
            parameters = np.zeros(X.shape[1] + 2)
        else:
            parameters = np.zeros(X.shape[1] + 1)
        # Make sure to initialize the scale parameter to a strictly
        # positive value:
        parameters[-1] = 1

    # Sigma or the scale factor should be non-negative.
    # Setting it to be zero might cause undefined bounds hence we set it
    # to a value close to zero.
    bounds = np.tile([-np.inf, np.inf], (parameters.shape[0], 1))
    bounds[-1][0] = np.finfo(np.float64).eps * 10

    parameters, f, dict_ = optimize.fmin_l_bfgs_b(
        _huber_loss_and_gradient,
        parameters,
        args=(X, y, self.epsilon, self.alpha, sample_weight),
        maxiter=self.max_iter,
        pgtol=self.tol,
        bounds=bounds,
        iprint=0,
    )
    if dict_["warnflag"] == 2:
        raise ValueError(
            "HuberRegressor convergence failed:"
            " l-BFGS-b solver terminated with %s" % dict_["task"].decode("ascii")
        )
    self.n_iter_ = dict_["nit"]
    self.scale_ = parameters[-1]
    if self.fit_intercept:
        self.intercept_ = parameters[-2]
    else:
        self.intercept_ = 0.0
    self.coef_ = parameters[: X.shape[1]]

    residual = np.abs(y - safe_sparse_dot(X, self.coef_) - self.intercept_)
    self.outliers_ = residual > self.scale_ * self.epsilon
    return self


# Traceback (AssertionError)
=================================== FAILURES ===================================
________________________________ test_max_iter _________________________________
@ignore_warnings
def test_max_iter():
# Test that the maximum number of iteration is reached
X, y_bin = iris.data, iris.target.copy()
y_bin[y_bin == 2] = 0

solvers = ['newton-cg', 'liblinear', 'sag', 'saga', 'lbfgs']

for max_iter in range(1, 5):
for solver in solvers:
for multi_class in ['ovr', 'multinomial']:
if solver == 'liblinear' and multi_class == 'multinomial':
continue
lr = LogisticRegression(max_iter=max_iter, tol=1e-15,
multi_class=multi_class,
random_state=0, solver=solver)
lr.fit(X, y_bin)
assert_equal(lr.n_iter_[0], max_iter)
X          = array([[ 5.1,  3.5,  1.4,  0.2],
[ 4.9,  3. ,  1.4,  0.2],
[ 4.7,  3.2,  1.3,  0.2],
[ 4.6,  3.1,...  2.5,  5. ,  1.9],
[ 6.5,  3. ,  5.2,  2. ],
[ 6.2,  3.4,  5.4,  2.3],
[ 5.9,  3. ,  5.1,  1.8]])
lr         = LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, max_iter=1...r', n_jobs=1,
penalty='l2', random_state=0, solver='lbfgs', tol=1e-15,
verbose=0, warm_start=False)
max_iter   = 1
multi_class = 'ovr'
solver     = 'lbfgs'
solvers    = ['newton-cg', 'liblinear', 'sag', 'saga', 'lbfgs']
y_bin      = array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
/home/travis/build/scikit-learn/scikit-learn/sklearn/linear_model/tests/test_logistic.py:1053:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/python/3.6.3/lib/python3.6/unittest/case.py:829: in assertEqual
assertion_func(first, second, msg=msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <sklearn.utils._unittest_backport.TestCase testMethod=__init__>
first = 0, second = 1, msg = '0 != 1'
def _baseAssertEqual(self, first, second, msg=None):
"""The default assertEqual implementation, not type specific."""
if not first == second:
standardMsg = '%s != %s' % _common_shorten_repr(first, second)
msg = self._formatMessage(msg, standardMsg)
raise self.failureException(msg)
E           AssertionError: 0 != 1
first      = 0
msg        = '0 != 1'
second     = 1
self       = <sklearn.utils._unittest_backport.TestCase testMethod=__init__>
standardMsg = '0 != 1'
/opt/python/3.6.3/lib/python3.6/unittest/case.py:822: AssertionError

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

    y : array-like, shape (n_samples,)
        Target vector relative to X.

    sample_weight : array-like, shape (n_samples,)
        Weight given to each sample.

    Returns
    -------
    self : object
    """
    X, y = check_X_y(X, y, copy=False, accept_sparse=["csr"], y_numeric=True)
    if sample_weight is not None:
        sample_weight = np.array(sample_weight)
        check_consistent_length(y, sample_weight)
    else:
        sample_weight = np.ones_like(y)

    if self.epsilon < 1.0:
        raise ValueError(
            "epsilon should be greater than or equal to 1.0, got %f" % self.epsilon
        )

    if self.warm_start and hasattr(self, "coef_"):
        parameters = np.concatenate((self.coef_, [self.intercept_, self.scale_]))
    else:
        if self.fit_intercept:
            parameters = np.zeros(X.shape[1] + 2)
        else:
            parameters = np.zeros(X.shape[1] + 1)
        # Make sure to initialize the scale parameter to a strictly
        # positive value:
        parameters[-1] = 1

    # Sigma or the scale factor should be non-negative.
    # Setting it to be zero might cause undefined bounds hence we set it
    # to a value close to zero.
    bounds = np.tile([-np.inf, np.inf], (parameters.shape[0], 1))
    bounds[-1][0] = np.finfo(np.float64).eps * 10

    parameters, f, dict_ = optimize.fmin_l_bfgs_b(
        _huber_loss_and_gradient,
        parameters,
        args=(X, y, self.epsilon, self.alpha, sample_weight),
        maxiter=self.max_iter,
        pgtol=self.tol,
        bounds=bounds,
        iprint=0,
    )
    if dict_["warnflag"] == 2:
        raise ValueError(
            "HuberRegressor convergence failed:"
            " l-BFGS-b solver terminated with %s" % dict_["task"].decode("ascii")
        )
    # In scipy <= 1.0.0, nit may exceed maxiter.
    # See https://github.com/scipy/scipy/issues/7854.
    self.n_iter_ = min(dict_["nit"], self.max_iter)
    self.scale_ = parameters[-1]
    if self.fit_intercept:
        self.intercept_ = parameters[-2]
    else:
        self.intercept_ = 0.0
    self.coef_ = parameters[: X.shape[1]]

    residual = np.abs(y - safe_sparse_dot(X, self.coef_) - self.intercept_)
    self.outliers_ = residual > self.scale_ * self.epsilon
    return self