AbtPst
AbtPst

Reputation: 8008

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?

Upvotes: 3

Views: 656

Answers (1)

maxymoo
maxymoo

Reputation: 36545

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)

Upvotes: 3

Related Questions