fix: accept array of categories in classifier initialization#111
Merged
fix: accept array of categories in classifier initialization#111
Conversation
Bayes.new and LogisticRegression.new now accept either:
- Splat arguments: Bayes.new('Spam', 'Ham')
- Array argument: Bayes.new(['Spam', 'Ham'])
Both forms are now equivalent, fixing the issue where array
arguments were treated as a single category name.
Fixes #110
Contributor
Greptile SummaryThis PR adds support for array-based category initialization in Changes:
Implementation:
The fix is minimal, clean, and consistent with Ruby's splat argument handling. Tests confirm functionality works as expected. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Bayes
participant LogisticRegression
participant prepare_category_name
User->>Bayes: new(['Spam', 'Ham'])
Bayes->>Bayes: categories.flatten
Note over Bayes: ['Spam', 'Ham'] remains flat
loop each category
Bayes->>prepare_category_name: 'Spam'.prepare_category_name
prepare_category_name-->>Bayes: :Spam
Bayes->>Bayes: @categories[:Spam] = {}
end
Bayes-->>User: classifier instance
User->>LogisticRegression: new(['Positive', 'Negative', 'Neutral'])
LogisticRegression->>LogisticRegression: categories.flatten
Note over LogisticRegression: ['Positive', 'Negative', 'Neutral'] remains flat
LogisticRegression->>LogisticRegression: Check categories.size >= 2
loop each category
LogisticRegression->>prepare_category_name: 'Positive'.prepare_category_name
prepare_category_name-->>LogisticRegression: :Positive
end
LogisticRegression-->>User: classifier instance
|
Add checkmark and X emoji to the Why This Library comparison table for better visual scanning. Fix Logistic Regression guide URL to use correct path (logisticregression without hyphen).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bayes.new(['Spam', 'Ham'])is now equivalent toBayes.new('Spam', 'Ham').flattento category processing in both initializersTest plan
Fixes #110