<jupyter_start><jupyter_text>NLP - 3 - TfidfVectorizer<jupyter_code>import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
import numpy as np
corpus = ["Joe went to the store",
         "Joe wants to buy a dining set",
         "Joe met John at the store",
         "Joe and John are best friends",
         ]
vectorizer = TfidfVectorizer(use_idf=True)

vectorizer_vectors = vectorizer.fit_transform(corpus)
vectorizer_vectors.toarray()
feature_names = vectorizer.get_feature_names_out()

feature_names
df = pd.DataFrame(vectorizer_vectors.toarray(), columns = feature_names)

df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.083596214511041, 'fraction_numerical': 0.0015772870662460567, 'mean_word_length': 4.825688073394495, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '363264', 'license': 'MIT', 'n_tokens_mistral': 218, 'n_tokens_neox': 208, 'n_words': 52, 'path': 'code_files/NLP - 3 - TfidfVectorizer.ipynb', 'repo_name': 'cj-asimov12/machine_learning', 'size': '634'}