In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use Tf-idf in Python, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Description
1. TF-IDF is that if the probability of words or phrases appearing in articles is high, but rarely in other articles, then it is considered to have a good ability to distinguish categories and is suitable for classification.
2. Extract text features to evaluate the importance of words to files in a file set or a corpus.
Example
Def tfidf_demo (): "" using tfidf method for text feature extraction: return: "" # 1. Segmenting the Chinese text into words data = "Today is cruel, tomorrow is crueler, the day after tomorrow is beautiful, but absolutely most of them die tomorrow night, so everyone should not give up today." The light we see from distant galaxies was emitted millions of years ago so that when we look at the universe we are looking at its past. " If you know something in only one way, you won't really understand it. The secret of knowing what things really mean depends on how you relate them to what we know. "] Data_new = [] for sent in data: data_new.append (cut_word (sent)) # print (data_new) # 2. Instantiate a converter class transfer = TfidfVectorizer (stop_words= ["one", 'because']) # 3. Call fit_transform data_final = transfer.fit_transform (data_new) print ("data_new:\ n", data_final.toarray ()) print ("feature name:\ n", transfer.get_feature_names ()) return None to thank you for reading this article carefully. I hope the article "how to use Tf-idf in Python" shared by the editor will be helpful to you, and I also hope you will support it. Pay attention to the industry information channel, more related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.