Skip to content

Text 0.4.0 tfidfvectorizer fittransform

github-actions[bot] edited this page Aug 21, 2026 · 1 revision

Lodestar.Text 0.4.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

TfidfVectorizer.FitTransform

Learn the vocabulary and frequencies, and weight the same corpus.

public CsrMatrix FitTransform(IEnumerable<string> documents)

Parametersdocuments is the corpus, both learned from and weighted.

ReturnsCsrMatrix, one row per document, weighted and normalized by TfidfOptions.Norm.

ExceptionsArgumentNullException when documents is null. A corpus that leaves no terms does not throw: it yields a model of zero columns, which every later transform will produce empty rows against.

Example — the whole corpus in one call, which is the usual way in.

using Lodestar.Text.Vectorization;

string[] docs = ["the cat eats", "the dog eats", "the cat and the dog"];

CsrMatrix weighted = new TfidfVectorizer().FitTransform(docs);

int rows = weighted.RowCount;         // => 3
int columns = weighted.ColumnCount;   // => 5

Remarks — equivalent to Fit then Transform on the same corpus, in one enumeration rather than two. It is not equivalent to fitting one corpus and transforming another, and the difference is not cosmetic here: the document frequencies would come from the wrong corpus.

Applies to — net10.0, netstandard2.0.

See alsoTfidfVectorizer.Fit, TfidfTransformer.FitTransform, CsrMatrix.

Lodestar

Project

Clone this wiki locally