Package parsimony :: Package datasets :: Package classification :: Module dice5
[hide private]
[frames] | no frames]

Source Code for Module parsimony.datasets.classification.dice5

 1  # -*- coding: utf-8 -*- 
 2  """ 
 3  Created on Tue Mar 18 10:56:04 2014 
 4   
 5  Copyright (c) 2013-2014, CEA/DSV/I2BM/Neurospin. All rights reserved. 
 6   
 7  @author:  Edouard Duchesnay 
 8  @email:   edouard.duchesnay@cea.fr 
 9  @license: BSD 3-clause. 
10  """ 
11  import numpy as np 
12  from ..regression import dice5 as dice5regression 
13   
14   
15  ############################################################################ 
16 -def load(n_samples=100, shape=(30, 30, 1), 17 snr=2., sigma_logit=5., random_seed=None, 18 **kwargs):
19 """Generate classification samples (images + target variable) and beta. 20 Call make_regression_struct then apply the logistic function: 21 proba = 1. / (1 + exp(-(X * beta + noise)), then 22 y = 1 if proba >= 0.5 else 0 23 24 Parameters 25 ---------- 26 See datasets.regression.dice5. 27 28 Returns 29 ------- 30 X3d : Numpy array of shape [n_sample, shape]. The input features. 31 32 y : Numpy array of shape [n_sample, 1]. The target variable. 33 34 beta3d : Float array of shape [shape]. It is the beta such that 35 y = 1. / (1 + exp(-(X * beta + noise)). 36 37 proba : Numpy array of shape [n_sample, 1]. Samples posterior 38 probabilities. 39 40 See also 41 -------- 42 regression.dice5.load() 43 44 Examples 45 -------- 46 >>> import numpy as np 47 >>> np.random.seed(42) 48 >>> import matplotlib.pyplot as plot 49 >>> from parsimony import datasets 50 >>> X3d, y, beta3d, proba = datasets.classification.dice5.load( 51 ... n_samples=100, shape=(11, 11, 1), random_seed=1) 52 """ 53 X3d, y, beta3d = dice5regression.load(n_samples=n_samples, shape=shape, 54 random_seed=random_seed, 55 **kwargs) 56 logit = y 57 proba = np.reciprocal(1.0 + np.exp(-logit)) 58 y = np.ones(y.shape) 59 y[proba < 0.5] = 0 60 61 return X3d, y, beta3d, proba
62