2

I'm trying to use scikits-learn to fit a linear model using Ridge regression. What I'd like to do is use cross validation to fit many different models, and then look at the parameter coefficients to see how stable they are across different CV splits. (or perhaps to average them all together).

When I try to fit the model with a cross-validation routine (e.g., using an instance of KFold and the cross_val_score function), I get back a list of the scores for each CV split, but I don't get back the fitted coefficient values that were calculated on each split. Is there a way for me to access this information? It's clearly being calculated on each iteration, so I assume there must be a way to report this back but I haven't been able to figure it out...

Edit: to clarify, I'm not looking for the parameters that I specified in the fitting (e.g., alpha values), I'm looking for the fitted coefficient values in the regression.

choldgraf
  • 3,539
  • 4
  • 22
  • 27

1 Answers1

2
clf = linear_model.RidgeCV(...) # your own parameters setting
param = clf.get_params(deep=True)

See the document for more details.

To get the weight vector coefficient, use clf.coef_. Besides, cv_values_ and alpha_ are two other attributes of clf returns MSEs and estimated regularization parameter respectively.

lennon310
  • 12,503
  • 11
  • 43
  • 61
  • Sorry for being unclear - I'm not talking about the pre-specified model parameters, but the fitted coefficient values. – choldgraf Dec 10 '13 at 01:28
  • 1
    Doesn't clf.coef_ just return a single vector of ceofficients? What I'm interested in would be a matrix of shape [n_cvs, n_features]. I tried looking into the docs for how exactly RidgeCV arrives at a final set of coefficients, but it was unclear to me. It seems that this class is used more for finding an optimal regularization parameter, not assessing coefficient stability across CV splits. By the way, thanks very much for your help, I appreciate it :) – choldgraf Dec 10 '13 at 20:15