Skip to content

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.

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;

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

@relf relf mentioned this pull request Feb 1, 2025
@relf
Copy link
Member

relf commented Feb 3, 2025

Superseded by #373

@relf relf closed this Feb 3, 2025
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.

3 participants