Skip to content
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

Target naming #256

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Target naming #256

wants to merge 9 commits into from

Conversation

oojo12
Copy link
Contributor

@oojo12 oojo12 commented Oct 31, 2022

An attempt to add target names per #70. Not really sure what to do with lines 83-98 in iter.rs. Any guidance there would be appreciated.

Line 83 was just added to see if it would build correctly.

src/dataset/mod.rs Outdated Show resolved Hide resolved
let mut records = self.dataset.records.view();
let mut targets = self.dataset.targets.as_targets();
let feature_names;
let mut target_names = vec!["class".to_string()];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just write let mut target_names;

src/dataset/iter.rs Outdated Show resolved Hide resolved
@@ -333,6 +335,13 @@ mod tests {
use ndarray::{array, Array1, Array2, Axis};
use rand::{rngs::SmallRng, SeedableRng};

#[test]
fn set_target_name() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add target name verification to one or two tests with target_iter just to verify that your iterator changes work correctly?

Copy link
Contributor Author

@oojo12 oojo12 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed lines 551-556 now test this.

Comment on lines 176 to 182
pub fn target_names(&self) -> Vec<String> {
if !self.target_names.is_empty() {
self.target_names.clone()
} else {
(0..self.ntargets())
.map(|idx| format!("class-{}", idx))
.collect()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no names, this method should instead just return empty list. The signature should be fn target_names(&self) -> &[String] to prevent cloning. Apply this change to feature_names as well for consistency.

Comment on lines +126 to +132
pub fn with_target_names<I: Into<String>>(mut self, names: Vec<I>) -> DatasetBase<R, S> {
let target_names = names.into_iter().map(|x| x.into()).collect();

self.target_names = target_names;

self
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should check the length of the input vector so that it's equal to number of targets. The input should be Vec so that it can be assigned directly. You can also try implementing this change for feature_names, but that might require more work to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the input for the function is already Vec(I) where I implements Into(String). Unless I am mistaken you want something like?

pub fn with_target_names(mut self, names: Vec<String>) -> DatasetBase<R, S> {
        if names.len() == self.ntargets() {
            self.target_names = names;
        } else {
            // raise some error to user stating the number of targets is X or default to class_{0..ntargets}?
        }
        self
    }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah pretty much. I don't mind panicking here, so you can just assert the condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha

@YuhanLiin
Copy link
Collaborator

This will close #248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants