Untitled
unknown
plain_text
a year ago
2.0 kB
2
Indexable
Never
## #################################################### import numpy as np from sklearn.datasets import load_breast_cancer from sklearn.model_selection import KFold from sklearn.metrics import roc_auc_score ## ################################################### ## ################################################### def main(iworkmode): iscenario = 0 ## =0 step size enumration Question 3, ## =1 iteration number enumeration, Question 4 # load the data X, y = load_breast_cancer(return_X_y=True) ## X input, y output print(X.shape, y.shape) mdata,ndim = X.shape ## to convert the {0,1} output into {-1,+1} y = 2*y - 1 ## hyperparameters of the learning problem if iscenario == 0: ## Question 3, step size enumeration ## list of eta, the stepsize or learning rate is enumerated neta = 10 ## number of different step size eta0 = 0.1 ## first setp size leta = [ eta0*(i+1) for i in range(neta)] ## list of step sizes ## number of iteration iteration =50 elif iscenario == 1: ## Question 4, iteration number enumeration ## list of iteration numbers niteration = 10 ## number of different iteration iteration0 = 10 ## first iteration number literation = [ iteration0*(i+1) for i in range(niteration)] ## step size eta = 0.1 nfold = 5 ## number of folds np.random.seed(12345) ## split the data into 5-folds cselection = KFold(n_splits=nfold, random_state=None, shuffle=False) ## normalization ## scaling the rows by maximum absolute value, L infinite norm of columns X /= np.outer(np.ones(mdata),np.max(np.abs(X),0)) ## run the cross-validation ## #################################################### ## ################################################### if __name__ == "__main__": if len(sys.argv)==1: iworkmode=0 elif len(sys.argv)>=2: iworkmode=eval(sys.argv[1]) main(iworkmode)