Text hashingvectorizer fittransform - CyrilB1531/lodestar GitHub Wiki

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

Home › Text › Vectorization

HashingVectorizer.FitTransform

The same as Transform — there is nothing to fit.

public CsrMatrix FitTransform(IEnumerable<string> documents)

Parameters — documents is the corpus to vectorize.

Returns — CsrMatrix, identical to what Transform returns for the same input.

Exceptions — ArgumentNullException when documents is null. ArgumentException when documents holds a null document.

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

using Lodestar.Abstractions;
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 also — HashingVectorizer.Transform, CountVectorizer.FitTransform.

⚠️ **GitHub.com Fallback** ⚠️