Text countvectorizer getfeaturenames - 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
The term each column stands for, in column order.
public IReadOnlyList<string> GetFeatureNames()Returns — IReadOnlyList<string> of length ColumnCount, sorted by code point, where index i is the term
counted by column i.
Exceptions — InvalidOperationException when nothing has been fitted yet.
Example — the vocabulary is sorted, so the order depends on the terms and not the documents.
using Lodestar.Text.Vectorization;
var cv = new CountVectorizer();
cv.Fit(["the cat eats", "the dog eats", "the cat and the dog"]);
IReadOnlyList<string> names = cv.GetFeatureNames();
string first = names[0]; // => and
string last = names[4]; // => theRemarks — this is what makes a count matrix readable, and it is the thing
HashingVectorizer cannot offer: hashing throws the vocabulary away, so
there is no name to return and no method to return it. Choosing that vectorizer is choosing to
give this up.
The list is a read-only view of the vectorizer's own vocabulary, made at the first call and not
copied, so reading it allocates nothing after that; a cast back to an array fails rather than
editing the fitted model under a later Save
(#1670).
Applies to — net10.0, netstandard2.0.
See also — CountVectorizer, CsrMatrix.