ktrain icon indicating copy to clipboard operation
ktrain copied to clipboard

How to save testing data

Open ccrupp opened this issue 6 years ago • 3 comments

Is there a way to save the model's results on testing data after the final epoch? I only see options to save the model and the predictor but not how to save the actual results. I'm using K-fold validation testing but am having trouble saving the results. Thank you!

ccrupp avatar Sep 15 '20 00:09 ccrupp

In learner.evaluate, setting print_report=False will save results on validation or test data to CSV:


    def evaluate(self, test_data=None, print_report=True, save_path='ktrain_classification_report.csv', class_names=[]):

Otherwise, you can just get y_true with learner.ground_truth and y_pred with learner.predict and compute and save the metrics yourself.

amaiya avatar Sep 15 '20 01:09 amaiya

Hi amaiya, I've tried this but when I pass in print_report=False as well as a valid save path, it was the save path argument was unexpected and the program errors out. The only way I was able to save my results was by only passing in print_report=False but the file saves as an hdf5 file which I'm unfamiliar with. Any suggestions?

ccrupp avatar Oct 06 '20 12:10 ccrupp

@ccrupp There was a bug in learner.evaluate that caused the save_path argument to be ignored (meaning the CSV was always saved with default file path). It is fixed in ktrain>=0.22.0 (just released). The following has been verified to work using the latest version of ktrain (ktrain>=0.22.0) and scikit_learn==0.23.2:

learner.evaluate(class_names=t.get_classes(), print_report=False, save_path='/tmp/test.csv')

The file /tmp/test.csv is a CSV file containing the test results.

Note that learner.evaluate simply calls learner.validate (which was not affected by the bug).

amaiya avatar Oct 06 '20 16:10 amaiya