def fit(self, X):
    '\n        Parameters\n        ----------\n        X : sparse matrix, [n_samples, n_features] document-term matrix\n        '
    if (not sp.sparse.issparse(X)):
        X = sp.sparse.csc_matrix(X)
    if self.use_idf:
        (n_samples, n_features) = X.shape
        df = _document_frequency(X)
        idf = np.log((((n_samples - df) + 0.5) / (df + 0.5)))
        self._idf_diag = sp.sparse.spdiags(idf, diags=0, m=n_features, n=n_features)
    doc_len = X.sum(axis=1)
    self._average_document_len = np.average(doc_len)
    return self
Parameters
----------
X : sparse matrix, [n_samples, n_features] document-term matrix
def fit(self, X):
    '\n        Parameters\n        ----------\n        X : sparse matrix, [n_samples, n_features] document-term matrix\n        '
    if (not sp.sparse.issparse(X)):
        X = sp.sparse.csc_matrix(X)
    if self.use_idf:
        (n_samples, n_features) = X.shape
        df = _document_frequency(X)
        idf = np.log((((n_samples - df) + 0.5) / (df + 0.5)))
        self._idf_diag = sp.sparse.spdiags(idf, diags=0, m=n_features, n=n_features)
    doc_len = X.sum(axis=1)
    self._average_document_len = np.average(doc_len)
    return self