Skip to content

fix(cpp/random_forest): remove stray comment characters and check data::Load - #252

Open
dhirenmahajan11 wants to merge 2 commits into
mlpack:masterfrom
dhirenmahajan11:fix/covertype-rf-comments-and-load-check
Open

dhirenmahajan11 wants to merge 2 commits into
mlpack:masterfrom
dhirenmahajan11:fix/covertype-rf-comments-and-load-check

Conversation

@dhirenmahajan11

Copy link
Copy Markdown

Description of Change

Cleaned up cpp/random_forest/covertype-rf.cpp to improve readability, formatting, and error handling in the example:

  • Removed raw \n", escape sequences and stray trailing punctuation from inline comments.
  • Added a check on mlpack::data::Load(...) to log an error to std::cerr and exit cleanly if loading the dataset fails.
  • Wrapped lines cleanly and fixed the accuracy output formatting so the opening parenthesis is included before the percentage.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: Cleans up comment formatting artifacts and adds a load-failure check in the random forest covertype example.

@github-actions

Copy link
Copy Markdown

Binder 👈 Launch a binder notebook on branch dhirenmahajan11/examples/fix/covertype-rf-comments-and-load-check

@rcurtin rcurtin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cleanups look mostly fine to me, but I have a couple suggestions. If you can handle those we can get this merged.

<< 100.0 * correct / testLabels.n_elem
<< "%)." << std::endl;
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you restore the trailing newline at the end of the file?

Comment on lines +9 to +14
const bool loaded = data::Load("../../../data/covertype-small.csv", dataset);
if (!loaded)
{
std::cerr << "Failed to load ../../../data/covertype-small.csv" << std::endl;
return 1;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const bool loaded = data::Load("../../../data/covertype-small.csv", dataset);
if (!loaded)
{
std::cerr << "Failed to load ../../../data/covertype-small.csv" << std::endl;
return 1;
}
Load("../../../data/covertype-small.csv", dataset, Fatal);

This is a much easier way to do the same thing.

@@ -1,35 +1,45 @@
#include <iostream>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
#include <iostream>

This is already included by mlpack.hpp.

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.

2 participants