<jupyter_start><jupyter_text>examples of nested_cv_ridge() usage- used when a separate test dataset is not available<jupyter_code>from __future__ import print_function

import numpy as np

from regression_code.storm import ridge
from regression_code.storm.tests import test_datasets
from regression_code.storm.tests import test_utils<jupyter_output><empty_output><jupyter_text>load data<jupyter_code>datasets = test_datasets.load_all()
dataset = datasets['qa_skinny']

Xtrain = dataset['Xtrain']
Ytrain = dataset['Ytrain']

print('Xtrain:', Xtrain.shape)
print('Ytrain:', Ytrain.shape)<jupyter_output>/auto/k1/storm/python_path/storm/storm/utils/stats.py:34: RuntimeWarning: invalid value encountered in divide
  return array / array.std(axis, keepdims=True)
/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py:2043: RuntimeWarning: invalid value encountered in true_divide
  return (a - mns) / sstd<jupyter_text>perform nested cv<jupyter_code>parameters = {
    'weights': True,
    'predictions': True,
    'performance': True,
    'ridges': np.logspace(0, 4, 5),
    'outer_fold_params': {
        'n_folds': 3,
    },
    'verbose': 1,
}

results = ridge.nested_cv_ridge(Xtrain, Ytrain, **parameters)

print()
print()
test_utils.rprint(results, 'results')
debug<jupyter_output>ERROR:root:No traceback has been produced, nothing to debug.<jupyter_text>use cluster<jupyter_code>parameters = {
    'weights': True,
    'predictions': True,
    'performance': True,
    'ridges': np.logspace(0, 4, 5),
    'outer_fold_params': {
        'n_folds': 3,
    },
    'cluster': True,
}

results = ridge.nested_cv_ridge(Xtrain, Ytrain, **parameters)

print()
print()
test_utils.rprint(results, 'results')<jupyter_output>Fitting cross-validated ridge model...
- (train, validate): (0.667, 0.333)
- n_folds: 3
- using cluster: True
- globally optimal parameters: True
- locally optimal parameters: True
- n_ridges: 5
- n_regressors: 116
- n_regressands: 92970
- n_train_samples: 1832
- n_test_samples: None
- inputs: Xtrain, Ytrain
- outputs: weights, predictions, performance
- dtype: float64
- additional kwargs: None


Outer folds complete, combining results


[results]: dict [8]
- 'global_optimal_ridge': ndarray (3,)
    [  1.00000000e+04   1.00000000e+01   1.00000000e+00]
- 'global_performance': ndarray (92970,)
- 'global_predictions': ndarray (1832, 92970)
- 'global_weights': ndarray (116, 92970)
- 'local_optimal_ridge': ndarray (278910,)
- 'local_performance': ndarray (92970,)
- 'local_predictions': ndarray (1832, 92970)
- 'local_weights': ndarray (116, 92970)<jupyter_text>verbose output<jupyter_code>parameters = {
    'weights': True,
    'predictions': True,
    'performance': True,
    'ridges': np.logspace(0, 4, 5),
    'outer_fold_params': {
        'n_folds': 3,
    },
    'verbose': 2,
}

results = ridge.nested_cv_ridge(Xtrain, Ytrain, **parameters)

print()
print()
test_utils.rprint(results, 'results')<jupyter_output>Fitting cross-validated ridge model...
- (train, validate): (0.667, 0.333)
- n_folds: 3
- using cluster: False
- globally optimal parameters: True
- locally optimal parameters: True
- n_ridges: 5
- n_regressors: 116
- n_regressands: 92970
- n_train_samples: 1832
- n_test_samples: None
- inputs: Xtrain, Ytrain
- outputs: weights, predictions, performance
- dtype: float64
- additional kwargs: None


Outer Fold 1/3, (train, validate)=(1221, 611)=(0.666, 0.334)
Fitting cross-validated ridge model...
- (train, validate, test): (0.533, 0.133, 0.334)
- n_folds: 5
- using cluster: False
- globally optimal parameters: True
- locally optimal parameters: True
- n_ridges: 5
- n_regressors: 116
- n_regressands: 92970
- n_train_samples: 1221
- n_test_samples: 611
- inputs: Xtrain, Ytrain, Xtest, Ytest
- outputs: weights, predictions
- dtype: float64
- additional kwargs:
    - rescale: True

Fold 1/5, (train, validate)=(976, 245)=(0.799, 0.201)
1:     1.0  (5%, 25%, 50%, 75%, 95%)=(-0.088, -0.017, +0[...]
{'fraction_non_alphanumeric': 0.13786997217303315, 'fraction_numerical': 0.06096635466734126, 'mean_word_length': 4.713872832369942, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '147243', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1398, 'n_words': 338, 'path': 'notebooks/ridge_examples/nested_cv_ridge_examples.ipynb', 'repo_name': 'sslivkoff/regression_code', 'size': '3953'}