Ravindra BagaleCourses & study guides English Track your progress

52. Text Cleaning and TF-IDF in Python

Data Science

52.4 Inspect Vocabulary and Rows

52.4 Vocabulary आणि rows inspect करा

Sparse matrix + vocabulary बघितलं की debugging कमी scary.

हे का शिकायचं?

Why. Sparse matrix आणि vocabulary बघितलं की model “चुकीचे words बघतोय” तेव्हा debugging कमी scary.

हे काय आहे?

What. TfidfVectorizer sparse matrix देतो. Tiny demos वरच .toarray(). Bigrams आणि cleaning confirm करायला get_feature_names_out().

कसं करायचं?

How.

Model काय बघेल ते inspect

  1. Tiny train list वर fit.
  2. Feature names print.
  3. एका row चे weights print (rounded).
  4. Confirm test uses transform, not a second fit.
from sklearn.feature_extraction.text import TfidfVectorizer

train = ["fresh pedha good", "sour dahi bad", "fresh dahi good"]
test = ["fresh pedha bad"]
vec = TfidfVectorizer(ngram_range=(1, 2))
Xtr = vec.fit_transform(train)
Xte = vec.transform(test)
print(vec.get_feature_names_out())
print("test row:", Xte.toarray().round(2))