Alina
Alina

Reputation: 2261

Tune parameters of the model on a validation set

Theory says to split the dataset into three sets: train set to train the model, validation set to tune the parameters and test set to evaluate the performance.

However, there is already GridSearchCV that does cross validation on training set to find the optimal parameters. But how do I use my own validation set to tune parameters ?

I have 10 classes and for the train data there are 1017 samples for each class. In validation and test sets I have 300 samples for each class.

I have trained my classified on train data.

clf = RandomForestClassifier(random_state=97)
clf.fit(train, np.array(train_lab)) 

How do I tune the parameters using my validation set? I have found examples only with GridSearchCV as cross-validation. However I would like to avoid it and tune the model on my own validation set. How can I do it?

Upvotes: 1

Views: 619

Answers (1)

Arya McCarthy
Arya McCarthy

Reputation: 8829

You can pass a cross-validation object into GridSearchCV. Pass in a PredefinedSplit object, which lets you decide what the training and validation sets are.

Upvotes: 1

Related Questions