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

Taking maximum of R2 to choose hyperparameters causes an error if the maximum is not unique #1

Open
lucasschn opened this issue Apr 4, 2022 · 0 comments

Comments

@lucasschn
Copy link

lucasschn commented Apr 4, 2022

With the given data, taking the hyperparameters yielding the best R2 score as in:
index = numpy.where(param_results[:, 0] == numpy.amax(param_results[:, 0])) # Maximum des R2

will cause the following line to raise an error on conversion to float:
best_out = model_energy_demand(wz_out, float(param_results[index, 1]), float(param_results[index, 2]), float(param_results[index, 3]), dfAnwend, True, True, 0.25)

The error is:
TypeError: only size-1 arrays can be converted to Python scalars

Indeed, index is not a scalar, causing param_results[index, 1] not to be a scalar either:

print(index)
(array([  66,   67,   68,   69,   70,   71,   72,   73,   74,   75,   76,
         187,  188,  189,  190,  191,  192,  193,  194,  195,  196,  197,
         308,  309,  310,  311,  312,  313,  314,  315,  316,  317,  318,
         429,  430,  431,  432,  433,  434,  435,  436,  437,  438,  439,
         550,  551,  552,  553,  554,  555,  556,  557,  558,  559,  560,
         671,  672,  673,  674,  675,  676,  677,  678,  679,  680,  681,
         792,  793,  794,  795,  796,  797,  798,  799,  800,  801,  802,
         913,  914,  915,  916,  917,  918,  919,  920,  921,  922,  923,
        1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044,
        1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165,
        1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286]),)

Suggested solution
Take the first index only

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

1 participant