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

Classification crossval results key error #126

Open
bluetyson opened this issue Sep 24, 2020 · 2 comments
Open

Classification crossval results key error #126

bluetyson opened this issue Sep 24, 2020 · 2 comments

Comments

@bluetyson
Copy link
Contributor

bluetyson commented Sep 24, 2020

I get an error

File "c:\users\rscott\appdata\local\continuum\anaconda3\envs\gdaltest\lib\site-packages\uncoverml\validate.py", line 237, in export_crossval
    to_text = [self.y_true, self.y_pred['Prediction'], self.positions[:,0], self.positions[:,1]]
KeyError: 'Prediction'

Looking at that dictionary (for a 24 class problem)

dict_keys(['most_likely', '0.0_0', '1.0_1', '2.0_2', '3.0_3', '4.0_4', '5.0_5', '6.0_6', '7.0_7', '8.0_8', '9.0_9', '10.0_10', '11.0_11', '12.0_12', '13.0_13', '14.0_14', '15.0_15', '16.0_16', '17.0_17', '18.0_18', '19.0_19', '20.0_20', '21.0_21', '22.0_22', '23.0_23'])

is the most_likely supposed to go there in the case of classification, if going to look the same as regression? e.g. using self.classification?

@RichardScottOZ
Copy link
Contributor

RichardScottOZ commented Feb 10, 2021

        # Make sure we convert numpy arrays to lists
        scores = {s: v if np.isscalar(v) else v.tolist()
                  for s, v in self.scores.items()}

        with open(config.crossval_scores_file, 'w') as f:
            json.dump(scores, f, sort_keys=True, indent=4)

        if self.classification:
            to_text = [self.y_true, self.y_pred['most_likely'], self.positions[:,0], self.positions[:,1]]
        else:
            to_text = [self.y_true, self.y_pred['Prediction'], self.positions[:,0], self.positions[:,1]]
        #print(self.y_pred.keys())
        #print("classification flag", self.classification)
        #to_text = [self.y_true, self.y_pred, self.positions[:,0], self.positions[:,1]]

        np.savetxt(config.crossval_results_file, X=np.vstack(to_text).T, 
                   delimiter=',', fmt='%.4f', header='y_true,y_pred,x,y')

        if os.path.exists(config.raw_covariates) and os.path.exists(config.raw_covariates_mask):
            # Also add prediction values to rawcovariates.csv - yes this file 
            # is very overloaded and we need to fix the output situation.
            # Get indicies sorted by location so we can insert the 
            # prediction in the correct row.
            inds = np.lexsort(self.positions.T)
            #sorted_predictions = self.y_pred['Prediction'][inds]
            if self.classification:
                sorted_predictions = self.y_pred['most_likely'][inds]
            else:
                sorted_predictions = self.y_pred['Prediction'][inds]

@RichardScottOZ
Copy link
Contributor

This is still a problem it would seem?

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

No branches or pull requests

2 participants