如何查看 tfidf_vectorizer 中的 TF-IDF 值?

How can I see TF-IDF values from tfidf_vectorizer?

我正在使用 Python

我有这个分析文本文档的代码

tfidf_vectorizer = TfidfVectorizer(max_df=0.8, max_features=10000)


# split dataset into training and validation set
xtrain, xval, ytrain, yval = train_test_split(movies_new['clean_plot'], y, test_size=0.2, random_state=9)


# create TF-IDF features
xtrain_tfidf = tfidf_vectorizer.fit_transform(xtrain)
xval_tfidf = tfidf_vectorizer.transform(xval)

我知道 TF-IDF 会为每个单词赋值。

有什么方法可以让我看看 xtrain_tfidf 里面的值是多少?

这是一个例子

from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd

vect = TfidfVectorizer()
tfidf_matrix = vect.fit_transform(documents)
df = pd.DataFrame(tfidf_matrix.toarray(), columns = vect.get_feature_names())
print(df)