-
Notifications
You must be signed in to change notification settings - Fork 202
Expose "vocabulary" parameter to "StringEncoder" #1819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
128ca03
86595ea
9cddeff
39aa02a
b10d7d7
40fed52
f96389b
90540a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,6 +61,11 @@ class StringEncoder(TransformerMixin, SingleColumnTransformer): | |||||
| Used during randomized svd. Pass an int for reproducible results across | ||||||
| multiple function calls. | ||||||
|
|
||||||
| vocabulary : Mapping or iterable, default=None | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The scikit-learn convention requires to have an underscore at the end of attributes that are derived from the data
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||||||
| In case of "tfidf" vectorizer, the vocabulary mapping passed to the vectorizer. | ||||||
| Either a Mapping (e.g., a dict) where keys are terms and values are | ||||||
| indices in the feature matrix, or an iterable over terms. | ||||||
|
|
||||||
| Attributes | ||||||
| ---------- | ||||||
| input_name_ : str | ||||||
|
|
@@ -131,13 +136,15 @@ def __init__( | |||||
| analyzer="char_wb", | ||||||
| stop_words=None, | ||||||
| random_state=None, | ||||||
| vocabulary=None, | ||||||
| ): | ||||||
| self.n_components = n_components | ||||||
| self.vectorizer = vectorizer | ||||||
| self.ngram_range = ngram_range | ||||||
| self.analyzer = analyzer | ||||||
| self.stop_words = stop_words | ||||||
| self.random_state = random_state | ||||||
| self.vocabulary = vocabulary | ||||||
|
|
||||||
| def fit_transform(self, X, y=None): | ||||||
| """Fit the encoder and transform a column. | ||||||
|
|
@@ -165,21 +172,28 @@ def fit_transform(self, X, y=None): | |||||
| ngram_range=self.ngram_range, | ||||||
| analyzer=self.analyzer, | ||||||
| stop_words=self.stop_words, | ||||||
| vocabulary=self.vocabulary, | ||||||
| ) | ||||||
| elif self.vectorizer == "hashing": | ||||||
| self.vectorizer_ = Pipeline( | ||||||
| [ | ||||||
| ( | ||||||
| "hashing", | ||||||
| HashingVectorizer( | ||||||
| ngram_range=self.ngram_range, | ||||||
| analyzer=self.analyzer, | ||||||
| stop_words=self.stop_words, | ||||||
| if self.vocabulary is None: | ||||||
|
||||||
| self.vectorizer_ = Pipeline( | ||||||
| [ | ||||||
| ( | ||||||
| "hashing", | ||||||
| HashingVectorizer( | ||||||
| ngram_range=self.ngram_range, | ||||||
| analyzer=self.analyzer, | ||||||
| stop_words=self.stop_words, | ||||||
| ), | ||||||
| ), | ||||||
| ), | ||||||
| ("tfidf", TfidfTransformer()), | ||||||
| ] | ||||||
| ) | ||||||
| ("tfidf", TfidfTransformer()), | ||||||
| ] | ||||||
| ) | ||||||
| else: | ||||||
| raise ValueError( | ||||||
| "Custom vocabulary passed to StringEncoder, unsupported by" | ||||||
| "HashingVectorizer. Rerun without a 'vocabulary' parameter." | ||||||
| ) | ||||||
| else: | ||||||
| raise ValueError( | ||||||
| f"Unknown vectorizer {self.vectorizer}. Options are 'tfidf' or" | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entry was added in the wrong place, it should be at the top of the file in the proper section