def train_regress (self, train, trainlabel, seed, Cmin, Cmax, numC, rmin, rmax, numr, degree=3, method = 'rrmse', rad_stat =2):
        C_range=np.logspace(Cmin, Cmax, num=numC, base=2,endpoint= True)
        gamma_range=np.logspace(rmin, rmax, num=numr, base=2,endpoint= True)
        
        svc = SVR(kernel=seed)
#        mean_score=[]
        df_C_gamma= DataFrame({'gamma_range':gamma_range})
#        df_this = DataFrame({'gamma_range':gamma_range})
        count = 0 
        for C in C_range:    
            score_C=[]    
#            score_C_this = []
            count=count+1
            for gamma in gamma_range: 
                svc.epsilon = 0.00001                 
     
                svc.C = C
                svc.gamma = gamma
                svc.degree = degree
                svc.random_state = rad_stat
                this_scores = cross_val_score(svc, train, trainlabel, scoring=method, cv=10, n_jobs=-1 \
                                              )
                
                score_C.append(np.mean(this_scores))                                      

               #score_C_this.append(np.mean(this_scores))
            print (np.mean(score_C) )
            print ("%r cycle finished, %r left" %(count, numC-count))
            df_C_gamma[C]= score_C
            #df_this[C] = score_C_this        
        
        return df_C_gamma 
예제 #2
0
    def trainsvr (self, train, trainlabel, seed, Cmin, Cmax, numC, rmin, rmax, numr, degree=3,\
                  verbose = 1, method = 'roc_auc', rad_stat =2):
        C_range = np.logspace(Cmin, Cmax, num=numC, base=2, endpoint=True)
        gamma_range = np.logspace(rmin, rmax, num=numr, base=2, endpoint=True)

        scr = SVR(kernel=seed)
        #        mean_score=[]
        df_C_gamma = pd.DataFrame({'gamma_range': gamma_range})
        #        df_this = DataFrame({'gamma_range':gamma_range})
        count = 0
        for C in C_range:
            score_C = []
            #            score_C_this = []
            count = count + 1
            for gamma in gamma_range:

                scr.C = C
                scr.gamma = gamma
                scr.degree = degree
                scr.random_state = rad_stat
                this_scores = cross_val_score(scr, train, trainlabel, scoring=method, cv=10, n_jobs=-1 \
                                              )

                score_C.append(np.mean(this_scores))

            #score_C_this.append(np.mean(this_scores))
            if verbose == 1:
                print(np.mean(score_C))
                print("%r cycle finished, %r left" % (count, numC - count))
            df_C_gamma[C] = score_C
            #df_this[C] = score_C_this

        return df_C_gamma
def objective_svr(params):
    clf = SVR(C=params[0], epsilon=params[1])
    clf.random_state = 12345

    #clf.fit(X_train, y_train)
    #mae = mean_absolute_error(y_test, clf.predict(X_test))

    clf.fit(X, y)
    mae = mean_absolute_error(y, clf.predict(X))

    print("SVR(C={}, epsilon={}) => Score {}".format(params[0], params[1],
                                                     mae))

    return mae
    def train_regress(self,
                      train,
                      trainlabel,
                      seed,
                      Cmin,
                      Cmax,
                      numC,
                      rmin,
                      rmax,
                      numr,
                      degree=3,
                      method='rrmse',
                      rad_stat=2):
        C_range = np.logspace(Cmin, Cmax, num=numC, base=2, endpoint=True)
        gamma_range = np.logspace(rmin, rmax, num=numr, base=2, endpoint=True)

        svc = SVR(kernel=seed)
        #        mean_score=[]
        df_C_gamma = DataFrame({'gamma_range': gamma_range})
        #        df_this = DataFrame({'gamma_range':gamma_range})
        count = 0
        for C in C_range:
            score_C = []
            #            score_C_this = []
            count = count + 1
            for gamma in gamma_range:
                svc.epsilon = 0.00001

                svc.C = C
                svc.gamma = gamma
                svc.degree = degree
                svc.random_state = rad_stat
                this_scores = cross_val_score(svc, train, trainlabel, scoring=method, cv=10, n_jobs=-1 \
                                              )

                score_C.append(np.mean(this_scores))

            #score_C_this.append(np.mean(this_scores))
            print(np.mean(score_C))
            print("%r cycle finished, %r left" % (count, numC - count))
            df_C_gamma[C] = score_C
            #df_this[C] = score_C_this

        return df_C_gamma