Text hashingvectorizer fittransform - CyrilB1531/lodestar GitHub Wiki

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

HomeTextVectorization

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. 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 alsoHashingVectorizer.Transform, CountVectorizer.FitTransform.

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