0

I would like to use train, test, validate set for parameter tuning using randomsearchcv. I test with iris data and here is my code.

from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import RandomizedSearchCV
from scipy.stats import uniform

iris = load_iris()

train_idx = list(range(100))  # just make it simple without using randomization
val_idx = list(range(100, 125))  # just make it simple without using randomization
test_idx = list(range(125, 150))  # just make it simple without using randomization


logistic = LogisticRegression(solver='saga', tol=1e-2, max_iter=200,random_state=0)
distributions = dict(C=uniform(loc=0, scale=4),penalty=['l2', 'l1'])
clf = RandomizedSearchCV(logistic, distributions, random_state=0, 
                         cv=[train_idx, val_idx])
search = clf.fit(iris.data, iris.target)
search.best_params_

But I got ValueError: too many values to unpack (expected 2). May I have your suggestions of how to apply randomsearchcv for train, test, validate?

  • Your `cv` parameter is expecting an integer. Why would you want to use test and validate sets for parameter tuning? – krisograbek Aug 23 '21 at 08:22
  • According to the sklearn manual, cv can be iterable too. Since we have 2 ways to build a model: 1) cross validation (no problem i can use that) and 2) train test validate (as far as I know we tune model from train and validate then test it later. I just want to try whether sklearn supports that or not. Otherwise, I can manually write the code from scratch. – Ratchainant Thammasudjarit Aug 23 '21 at 08:24

0 Answers0