Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Sklearn : Dynamically set parameters for TfIdfVectorizer

so normally we create a TfIdfVectorizer as

TfidfVectorizer(stop_words='english',sublinear_tf=True,use_idf=True)

what if the parameters were in a map? is there a way to dynamically set the parameters for the TfIdfVectorizer?

like image 436
AbtPst Avatar asked Apr 16 '26 13:04

AbtPst


1 Answers

You could store your parameters in a dictionary and set them from there:

params = {'stop_words':'english','sublinear_tf':True,'use_idf'=True}
TfidfVectorizer(stop_words=params['stop_words'],sublinear_tf=params['sublinear_tf'],use_idf=params['use_idf']).

However Python also has a special syntax that allows you to pass paramaters in using a dict, which will achieve the same result as the above:

TfidfVectorizer(**params)
like image 148
maxymoo Avatar answered Apr 18 '26 06:04

maxymoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!