Skip to content

Text hashingvectorizer fittransform

github-actions[bot] edited this page Aug 26, 2026 · 24 revisions

Development build. This page describes main, not a released package. The latest published Lodestar.Text is 0.4.0 — read its documentation.

HashingVectorizer.FitTransform

The same as Transform — there is nothing to fit.

public CsrMatrix FitTransform(IEnumerable<string> documents)

Parametersdocuments is the corpus to vectorize.

ReturnsCsrMatrix, identical to what Transform returns for the same input.

ExceptionsArgumentNullException when documents is null.

Example — the two calls agree, which is the whole content of this member.

using Lodestar.Text.Vectorization;

string[] docs = ["the cat eats", "the dog eats"];
var hv = new HashingVectorizer(new HashingVectorizerOptions { NumFeatures = 16 });

CsrMatrix fitted = hv.FitTransform(docs);
CsrMatrix transformed = hv.Transform(docs);

bool same = fitted.NonZeroCount == transformed.NonZeroCount;  // => True

Remarks — it exists so that the three vectorizers can be swapped for one another without the calling code changing shape. Code written against FitTransform works with all three; code that also calls Fit does not, because this type has none.

scikit-learn's HashingVectorizer carries a fit for the same reason — its pipeline API requires one — and it likewise does nothing.

Applies to — net10.0, netstandard2.0.

See alsoHashingVectorizer.Transform, CountVectorizer.FitTransform.

Lodestar

Project

Clone this wiki locally