I'm trying to fit my Logistic Regression model, but I'm running into an error that I don't understand. Looked around and haven't found a straight answer.

Shape of independent features (X): (495,30)

Shape of dependent feature (y): (495,)

The dependent feature holds binary values (0,1) and the values are currently of type "int". This is probably where the problem is occurring, but I don't understand what I need to do to fix the issue.

This is the error I'm getting when I try fitting to sklearn LogisticRegression():

c_param = [1,10,100,1000]

rand_grid = {'kbest__k':list(range(5,10)),

log_rand = RandomizedSearchCV(pipe_opt('log',LogisticRegression()),rand_grid,n_iter=100,cv=3,

enter image description here

  • $\begingroup$ What about if log_random_state = [42]? $\endgroup$ Sep 23, 2018 at 4:38
  • $\begingroup$ Wow that worked! Why did I need to put [ ] around the random_state? $\endgroup$
    – Glenn G.
    Sep 23, 2018 at 4:40
  • $\begingroup$ because RandomizedSearchCV demands list of values to seach on. $\endgroup$ Sep 23, 2018 at 7:15

1 Answer 1


RandomizedSearchCV expects you provide dictionary of parameters-values to try, like in your code above:

rand_grid = {'log__C':[1,10,100,1000],
             'log__random_state':42} # values should be in []

Since the idea is to search values which give the best performance, you are expected to provide several values, as a list of values. Though in your case you only provided only one value, it won't raise error as long as it was written as list (inside []).

However it's a bit weird if you only have one value to search. So better you fix those values when you initialize the estimator (i.e LogisticRegression())., e.g:

# you want to see which values perform best for params C and max_iter.
rand_grid = {'log__C':[1,10,100,1000]
             'log__max_iter': [100,200,300]}  

# you have fix value for params random_state, penalty and fit_intercept
logReg = LogisticRegression(random_state=42, penalty='l1', fit_intercept=False)

log_rand = RandomizedSearchCV(pipe_opt('log',logReg),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.