def transform(self, X, y=None):
"""Apply document term weighting and normalization on text features
Parameters
----------
X : sparse matrix, [n_samples, n_features]
a matrix of term/token counts
copy : boolean, default True
Whether to copy X and operate on the copy or perform in-place
operations.
"""
X = check_array(X, ['csr'], copy=self.copy)
check_is_fitted(self, 'dl_', 'vector is not fitted')
if X.shape[1] != self._n_features:
raise ValueError(('Model fitted with n_features={} '
'but X.shape={}')
.format(self._n_features, X.shape))
if self.df_ is not None:
df_n_samples = len(self.dl_)
else:
df_n_samples = None
return _smart_tfidf(X, self.weighting, self.df_,
df_n_samples,
norm_alpha=self.norm_alpha,
norm_pivot=self.norm_pivot)
评论列表
文章目录