'Fit the model according to the given training data.
Parameters
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training vector, where n_samples is 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,) optional
Array of weights that are assigned to individual samples.
If not provided, then each sample is given unit weight.
.. versionadded:: 0.17
*sample_weight* support to LogisticRegression.
Returns
self : object
Returns self.'

def fit(self, X, y, sample_weight=None):

    if ((not isinstance(self.C, numbers.Number)) or (self.C < 0)):
        raise ValueError(('Penalty    term    must    be    positive;    got    (C=%r)' % self.C))
    if ((not isinstance(self.max_iter, numbers.Number)) or (self.max_iter < 0)):
        raise ValueError(('Maximum    number    of    iteration    must    be    positive;    got    (max_iter=%r)' % self.max_iter))
    if ((not isinstance(self.tol, numbers.Number)) or (self.tol < 0)):
        raise ValueError(('Tolerance    for    stopping    criteria    must    be    positive;    got    (tol=%r)' % self.tol))
    if (self.solver in ['newton-cg']):
        _dtype = [np.float64, np.float32]
    else:
        _dtype = np.float64
    (X, y) = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order='C')
    check_classification_targets(y)
    self.classes_ = np.unique(y)
    (n_samples, n_features) = X.shape
    _check_solver_option(self.solver, self.multi_class, self.penalty, self.dual)
    if (self.solver == 'liblinear'):
        if (self.n_jobs != 1):
            warnings.warn("'n_jobs'    >    1    does    not    have    any    effect    when    'solver'    is    set    to    'liblinear'.    Got    'n_jobs'    =    {}.".format(self.n_jobs))
        (self.coef_, self.intercept_, n_iter_) = _fit_liblinear(X, y, self.C, self.fit_intercept, self.intercept_scaling, self.class_weight, self.penalty, self.dual, self.verbose, self.max_iter, self.tol, self.random_state, sample_weight=sample_weight)
        self.n_iter_ = np.array([n_iter_])
        return self
    if (self.solver in ['sag', 'saga']):
        max_squared_sum = row_norms(X, squared=True).max()
    else:
        max_squared_sum = None
    n_classes = len(self.classes_)
    classes_ = self.classes_
    if (n_classes < 2):
        raise ValueError(('This    solver    needs    samples    of    at    least    2    classes    in    the    data,    but    the    data    contains    only    one    class:    %r' % classes_[0]))
    if (len(self.classes_) == 2):
        n_classes = 1
        classes_ = classes_[1:]
    if self.warm_start:
        warm_start_coef = getattr(self, 'coef_', None)
    else:
        warm_start_coef = None
    if ((warm_start_coef is not None) and self.fit_intercept):
        warm_start_coef = np.append(warm_start_coef, self.intercept_[:, np.newaxis], axis=1)
    self.coef_ = list()
    self.intercept_ = np.zeros(n_classes)
    if (self.multi_class == 'multinomial'):
        classes_ = [None]
        warm_start_coef = [warm_start_coef]
    if (warm_start_coef is None):
        warm_start_coef = ([None] * n_classes)
    path_func = delayed(logistic_regression_path)
    if (self.solver in ['sag', 'saga']):
        backend = 'threading'
    else:
        backend = 'multiprocessing'
    fold_coefs_ = Parallel(n_jobs=self.n_jobs, verbose=self.verbose, backend=backend)((path_func(X, y, pos_class=class_, Cs=[self.C], fit_intercept=self.fit_intercept, tol=self.tol, verbose=self.verbose, solver=self.solver, multi_class=self.multi_class, max_iter=self.max_iter, class_weight=self.class_weight, check_input=False, random_state=self.random_state, coef=warm_start_coef_, penalty=self.penalty, max_squared_sum=max_squared_sum, sample_weight=sample_weight) for (class_, warm_start_coef_) in zip(classes_, warm_start_coef)))
    (fold_coefs_, _, n_iter_) = zip(*fold_coefs_)
    self.n_iter_ = np.asarray(n_iter_, dtype=np.int32)[:, 0]
    if (self.multi_class == 'multinomial'):
        self.coef_ = fold_coefs_[0][0]
    else:
        self.coef_ = np.asarray(fold_coefs_)
        self.coef_ = self.coef_.reshape(n_classes, (n_features + int(self.fit_intercept)))
    if self.fit_intercept:
        self.intercept_ = self.coef_[:, (-1)]
        self.coef_ = self.coef_[:, :(-1)]
    return self
