Early stop when training a neural network in scikit-learn

These questions are very specific to the scikit-learn Python library. Please let me know if it is better to think about publishing elsewhere. Thank!

Now the question is ...

I have a ffnn direct link neural network class based on BaseEstimator that I train with SGD. It works fine, and I can also train it in parallel using GridSearchCV ().

Now I want to implement an early stop in the ffnn.fit () function, but for this I also need access to the crease validation data. One way to do this is to change the row in sklearn.grid_search.fit_grid_point (), which reads

clf.fit(X_train, y_train, **fit_params)

into something like

clf.fit(X_train, y_train, X_test, y_test, **fit_params)

and also modify ffnn.fit () to accept these arguments. This will also affect other classifiers in sklearn, which is a problem. I can avoid this by checking some flag in fit_grid_point (), which tells me when to call clf.fit () in one of two ways.

Can someone suggest another way to do this when I don't need to edit any code in the sklearn library?

Alternatively, would it be right to further split X_train and y_train in a build / validation sequence in random order and check for a good breakpoint and then rebuild the model on all X_train?

Thank!

+3
source share
2 answers

X_train y_train train_test_split, .

Edit:

, X_train y_train / , X_train?

, . , , , .

+7

:

-:

x_train x_test. 0,1 x_train x_dev:

x_train, x_test, y_train, y_test = train_test_split(data_x, data_y, test_size=0.25)

x_train, x_dev, y_train, y_dev = train_test_split(x_train, y_train, test_size=0.1)

clf = GridSearchCV(YourEstimator(), param_grid=param_grid,)
clf.fit(x_train, y_train, x_dev, y_dev)

x_dev, y_dev

class YourEstimator(BaseEstimator, ClassifierMixin):
    def __init__(self, param1, param2):
        # perform initialization
        #

    def fit(self, x, y, x_dev=None, y_dev=None):
        # perform training with early stopping
        #

x_train, dev set Estimator

x_train, x_test, y_train, y_test = train_test_split(data_x, data_y, test_size=0.25)

clf = GridSearchCV(YourEstimator(), param_grid=param_grid)
clf.fit(x_train, y_train)

:

class YourEstimator(BaseEstimator, ClassifierMixin):
    def __init__(self, param1, param2):
        # perform initialization
        #

    def fit(self, x, y):
        # perform training with early stopping
        x_train, x_dev, y_train, y_dev = train_test_split(x, y, 
                                                         test_size=0.1)
0

All Articles