'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.'

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

    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, y) = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr')
    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)
    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\nNote:    Sparse    matrices    cannot    be    indexed    w/boolean    masks    (use    `indices=True`    in    CV).' % (sample_weight.shape, X.shape)))
    if (self.gamma == 'auto'):
        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:
        print('[LibSVM]', end='')
    seed = rnd.randint(np.iinfo('i').max)
    fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)
    self.shape_fit_ = X.shape
    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
