Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

TfidfVectorizer use

Text1 = “Natural Language Processing is a subfield of AI”
tag1 = "NLP"

Text2 = “Computer Vision is a subfield of AI”
tag2 = "CV"


from sklearn.feature_extraction.text import TfidfVectorizer as tf_idf
import pandas as pd
tfidf = tf_idf(norm = None)
tfidf.fit([Text1, Text2])
x= tfidf.transform([Text1]).toarray()
y= tfidf.transform([Text2]).toarray()
columns = tfidf.get_feature_names()
df1 = pd.DataFrame(x, columns= columns, index= ["Text1"])
df2 = pd.DataFrame(y, columns= columns, index= ["Text2"])
df = pd.concat([df1,df2])
df["tag"] = ["NLP", "CV"]
df
Comment

PREVIOUS NEXT
Code Example
Python :: python or 
Python :: how to get all the keys of a dictionary in python 
Python :: python check date between two dates 
Python :: Math Module log10() Function in python 
Python :: change tuple python 
Python :: 1*2*3*4*5*6* - print on console?by python 
Python :: boolien in python 
Python :: streamlit - Warning: NumberInput value below has type int so is displayed as int despite format string %.1f. 
Python :: add label to colorbar 
Python :: plotly scatter facet change labels 
Python :: sys module in python 
Python :: how to do merge sort in python 
Python :: append two 1d arrays python 
Python :: how to make reportlab table header bold in python 
Python :: from string to flaot python numpy 
Python :: ValueError: Please provide a TPU Name to connect to. site:stackoverflow.com 
Python :: pytorch dataloader to device 
Python :: mnist 
Python :: Change Separator Value When Printing 
Python :: autokeras import colab 
Python :: python remove vowels from string 
Python :: scipy.arange is deprecated and will be removed 
Python :: blender python get current filename 
Python :: scikit learn decision tree 
Python :: print index and value on each iteration of the for loop in Python 
Python :: how to get last element of list in python 
Python :: Python how to use __add__ 
Python :: sum of digits in python 
Python :: format binary string python 
Python :: Converting a HDFDataset to numpy array 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =