Example #1
0
    f_vals = [ True]                                 
    c_weights = ['auto']
    param_grid = tuple([c_vals,pen_vals,f_vals,c_weights])
    param_grid = list(product(*param_grid))

    # storage structure for forecasts
    mvalid = np.zeros((xtrain.shape[0],len(param_grid)))
    mfull = np.zeros((xtest.shape[0],len(param_grid)))
    
    ## build 2nd level forecasts
    for i in range(len(param_grid)):        
            print("processing parameter combo:", i)
            # configure model with j-th combo of parameters
            x = param_grid[i]
            model.loss = x[0]; model.penalty = x[1]; model.l1_ratio = x[2]; 
            model.alpha = x[3]            
            
            # loop over folds
            for j in range(0,n_folds):
                idx0 = np.where(fold_index != j)
                idx1 = np.where(fold_index == j)
                x0 = np.array(xtrain)[idx0,:][0]; x1 = np.array(xtrain)[idx1,:][0]
                y0 = np.array(ytrain)[idx0]; y1 = np.array(ytrain)[idx1]
			
                # fit the model on observations associated with subject whichSubject in this fold
                model.fit(x0, y0)
                mvalid[idx1,i] = model.predict_proba(x1)[:,1]
                print("finished fold:", j)
                
            # fit on complete dataset
            model.fit(xtrain, ytrain)
Example #2
0
    f1.write('\nparameter grid \n'); f1.write(str(param_grid)    )
    f1.close()


    # storage structure for forecasts
    mvalid = np.zeros((xtrain.shape[0],len(param_grid)))
    mfull = np.zeros((xtest.shape[0],len(param_grid)))
    
    ## build 2nd level forecasts
    for i in range(len(param_grid)): 
        
            print "processing parameter combo:", i
            # configure model with j-th combo of parameters
            x = param_grid[i]
            model.loss = x[0]; model.penalty = x[1]; model.l1_ratio = x[2]; 
            model.alpha = x[3]            
            
            # loop over folds
            for j in range(0,n_folds):
                idx0 = np.where(fold_index != j)
                idx1 = np.where(fold_index == j)
                x0 = np.array(xtrain)[idx0,:][0]; x1 = np.array(xtrain)[idx1,:][0]
                y0 = np.array(ytrain)[idx0]; y1 = np.array(ytrain)[idx1]
			
                # fit the model on observations associated with subject whichSubject in this fold
                model.fit(x0, y0)
                prx = model.predict_proba(x1)[:,1]
                mvalid[idx1,i] = prx
                print log_loss(y1, prx)
                print "finished fold:", j