beckstev / MachineLearningSeminar

MachineLearningSeminar SS19 TU Dortmund
MIT License
0 stars 0 forks source link

Grid_Search self-implemented #27

Closed FeGeyer closed 5 years ago

FeGeyer commented 5 years ago

This is a problem, which have some slightly different solutions, but the main problem is in my opinion, that we dont have the parameters x and y for fitting, but objects of type DataGenerator. Some Links with solutions

beckstev commented 5 years ago

So we have to change this line: https://github.com/scikit-learn/scikit-learn/blob/7813f7efb5b2012412888b69e73d76f2df2b50b6/sklearn/model_selection/_validation.py#L512

The function _fit_and_score' is called byGridSearch`: https://github.com/scikit-learn/scikit-learn/blob/7813f7efb5b2012412888b69e73d76f2df2b50b6/sklearn/model_selection/_search.py#L659

FeGeyer commented 5 years ago

Ideas:

beckstev commented 5 years ago

use loss_and_metrics with model.evaluate_generator, add this to predict-method?

To be more flexible I would create a new. However, if you have to copy paste code you should consider to outsource this code in a function to avoid unnecessary code.

use every combination with np.meshgrid, in special: np.stack(np.meshgrid([1, 2, 3], [4, 5], [6, 7]), -1).reshape(-1, - 3)

Why np.stack()?

save loss and accuracy plots and the value of loss_and_metrics in different folders

We should think about a handy naming convention

beckstev commented 5 years ago

Here a short suggestion on how to create the .json file. I am refering to the code starting here: https://github.com/beckstev/MachineLearningSeminar/blob/283e363ef69454e8ec26c94e6e16959db07d2eb9/dog_classifier/net/train.py#L51


BTW

Why do you use here .tolist()? https://github.com/beckstev/MachineLearningSeminar/blob/283e363ef69454e8ec26c94e6e16959db07d2eb9/dog_classifier/net/train.py#L58


My suggestion:

loss_dict = dict()
loss_dict['min_loss'] = min(df_history['loss'].values)
loss_dict['max_acc']= max(df_history['acc'].values)
loss_dict['min_val_loss'] = min(df_history['val_loss'].values)
los_dict['max_val_acc'] = max(df_history['val_acc'].values)

 # final values
loss_dict ['acc'] = df_history['acc'].tail(1).values
loss_dict['loss']= df_history['loss'].tail(1).values
loss_dict['val_acc'] = df_history['val_acc'].tail(1).values
loss_dict['val_loss'] = df_history['val_loss'].tail(1).values

with open(model_save_path + '/loss_acc.json', 'w') as json_file:
        json.dump(loss_dict , json_file)

DISCLAIMER: I did not test this code at all, however I optimistic that it will work. If not, please post the error.

FeGeyer commented 5 years ago

Habe für die final values noch [0] ergänzt, dann funktioniert es gut. Danke!

FeGeyer commented 5 years ago

The final version #30