How to use the xgboost.sklearn.XGBRegressor function in xgboost

To help you get started, we’ve selected a few xgboost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deephyper / deephyper / deephyper / search / ExtremeGradientBoostingQuantileRegressor.py View on Github external
def fit(self, X, y):
        self.clf_lower = XGBRegressor(objective=partial(quantile_loss,_alpha = self.quant_alpha_lower,_delta = self.quant_delta_lower,_threshold = self.quant_thres_lower,_var = self.quant_var_lower),
                                n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf_upper = XGBRegressor(objective=partial(quantile_loss,_alpha = self.quant_alpha_upper,_delta = self.quant_delta_upper,_threshold = self.quant_thres_upper,_var = self.quant_var_upper),
                                n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf = XGBRegressor(n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf_lower.fit(X,y)
        self.clf_upper.fit(X,y)
        self.clf.fit(X,y)
        return self
github binliwhu / ML-Quantamental / Codes / MainFile.py View on Github external
output(window[i],LinearRegression(),'OLS'+str(window[i]),riskfree[i], timeseries)
    FC(window[i], riskfree[i], timeseries, 96,'FC')
    output(window[i], PLSRegression(PLS_params[i]), 'PLS' + str(window[i]), riskfree[i], timeseries)
    output(window[i],Lasso(alpha=lasso_params[i]),'Lasso'+ str(window[i]), riskfree[i], timeseries)
    output(window[i],Ridge(alpha=ridge_params[i]),'Ridge'+str(window[i]),riskfree[i], timeseries)
    output(window[i],ElasticNet(alpha= elasticnet_params['alpha'] [i],l1_ratio= elasticnet_params['l1_ratio'][i]),'ElasticNet'+str(window[i]),riskfree[i], timeseries)
    output(window[i],SVR(kernel=SVR_params['kernel'][i],gamma= SVR_params ['gamma'][i],C= SVR_params ['C'][i] ),'SVR'+str(window[i]),riskfree[i], timeseries)
    output(window[i], GradientBoostingRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i],learning_rate=GBDT_params['learning_rate'][i]), 'GBDT' + str(window[i]),riskfree[i], timeseries)
    output(window[i], XGBRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i], learning_rate=GBDT_params['learning_rate'][i]), 'XGBOOST' + str(window[i]), riskfree[i], timeseries)
    output(window[i], ensemblenn(5,modeluse = MLPRegressor(solver = 'lbfgs', max_iter=ENANN_params['max_iter'][i]), pickpercent=ENANN_params['p'][i]), 'ENANN' + str(window[i]), riskfree[i], timeseries)
    output(window[i], DFN.DFN(outputdim=1, neuralset=[96, 50, 25, 10, 5, 2], ctx=gpu(0), epoch=10, batch_size=DFN_params['batch'][i], lr=DFN_params['learning_rate'][i]), 'DFN' + str(window[i]), riskfree[i], timeseries)
    output2(window[i], rm.lstmmodule(96, LSTM_params['hidden_number'][i], LSTM_params['depth'][i], 100, 3571, lr=LSTM_params['learning_rate'][i]), 'LSTM'+ str(window[i]) ,riskfree[i], timeseries2)
    output2(window[i], rm.lstmmodule(96,  RNN_params['hidden_number'][i], RNN_params['depth'][i], 100, 3571, lr=RNN_params['learning_rate'][i], ntype='RNN'), 'RNN'+ str(window[i]), riskfree[i], timeseries2)
    modellist = [DFN.DFN(outputdim=1, neuralset=[96, 50, 25, 10, 5, 2], ctx=gpu(0), epoch=10, batch_size=DFN_params['batch'][i], lr=DFN_params['learning_rate'][i]),
                 ensemblenn(5,modeluse = MLPRegressor(solver = 'lbfgs', max_iter=ENANN_params['max_iter'][i]), pickpercent=ENANN_params['p'][i]),
                 XGBRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i], learning_rate=GBDT_params['learning_rate'][i]),
                 GradientBoostingRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i],learning_rate=GBDT_params['learning_rate'][i]),
                 PLSRegression(PLS_params[i]),
                 Ridge(alpha=ridge_params[i]),
                 SVR(kernel=SVR_params['kernel'][i],gamma= SVR_params ['gamma'][i],C= SVR_params ['C'][i])]# PLS一定要放在倒数第三个
    nmolist = [rm.lstmmodule(96, LSTM_params['hidden_number'][i], LSTM_params['depth'][i], 100, 3571, lr=LSTM_params['learning_rate'][i]),
               rm.lstmmodule(96,  RNN_params['hidden_number'][i], RNN_params['depth'][i], 100, 3571, lr=RNN_params['learning_rate'][i], ntype='RNN')]# 循环神经网络模型
    modelname = ['DFN', 'En-ann', 'xgboost', 'GBDT', 'lasso', 'Elasticnet', 'pls', 'Ridge', 'svm', 'LSTM', 'RNN']
    ensemblemodel = ea.Ensemblelr(modellist, nmolist, modelname)
    comboutput(window[i],ensemblemodel, 'Ensemble'+str(window[i]),riskfree[i], timeseries2, index)
#*********************************3..各算法收益序列差异NW-t检验****************************************#

for i in window:
    returnseriestest(i)

#*********************************4.不同交易费率情形****************************************#
github deephyper / deephyper / deephyper / search / ExtremeGradientBoostingQuantileRegressor.py View on Github external
def fit(self, X, y):
        self.clf_lower = XGBRegressor(objective=partial(quantile_loss,_alpha = self.quant_alpha_lower,_delta = self.quant_delta_lower,_threshold = self.quant_thres_lower,_var = self.quant_var_lower),
                                n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf_upper = XGBRegressor(objective=partial(quantile_loss,_alpha = self.quant_alpha_upper,_delta = self.quant_delta_upper,_threshold = self.quant_thres_upper,_var = self.quant_var_upper),
                                n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf = XGBRegressor(n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf_lower.fit(X,y)
        self.clf_upper.fit(X,y)
        self.clf.fit(X,y)
        return self
github deephyper / deephyper / deephyper / search / ExtremeGradientBoostingQuantileRegressor.py View on Github external
def fit(self, X, y):
        self.clf_lower = XGBRegressor(objective=partial(quantile_loss,_alpha = self.quant_alpha_lower,_delta = self.quant_delta_lower,_threshold = self.quant_thres_lower,_var = self.quant_var_lower),
                                n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf_upper = XGBRegressor(objective=partial(quantile_loss,_alpha = self.quant_alpha_upper,_delta = self.quant_delta_upper,_threshold = self.quant_thres_upper,_var = self.quant_var_upper),
                                n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf = XGBRegressor(n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        self.clf_lower.fit(X,y)
        self.clf_upper.fit(X,y)
        self.clf.fit(X,y)
        return self
github deephyper / deephyper / deephyper / search / ExtremeGradientBoostingQuantileRegressor.py View on Github external
def fit(self, X, y):
        """Fit one regressor for each quantile.

        Args:
            X ([array-like, shape=(n_samples, n_features)]): Training vectors, where ``n_samples`` is the number of samples and ``n_features`` is the number of features.
            y ([array-like, shape=(n_samples,)]): Target values (real numbers in regression).
        """
        rng = check_random_state(self.random_state)

        if self.base_estimator is None:
            base_estimator = XGBRegressor(n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
        else:
            base_estimator = self.base_estimator

            if not isinstance(base_estimator, XGBRegressor):
                raise ValueError('base_estimator has to be of type'
                                 ' XGBRegressor.')
        # The predictions for different quantiles should be sorted.
        # Therefore each of the regressors need the same seed.
        #print(base_estimator.get_params().keys())
        #base_estimator.set_params(random_state=rng)
        regressors = []
        for q in self.quantiles:
            if q == 0.05 or q == 0.16:
                regressor = XGBRegressor(objective=partial(quantile_loss,_alpha = q,_delta = self.quant_delta_lower,_threshold = self.quant_thres_lower,_var = self.quant_var_lower),
                                         n_estimators = self.n_estimators, max_depth = self.max_depth, reg_alpha =self.reg_alpha, reg_lambda = self.reg_lambda, gamma = self.gamma)
            elif q == 0.84 or q == 0.95:
github ow2-proactive / proactive-examples / MachineLearningScripts / resources / catalog / Train_Model.py View on Github external
model = SVR(**alg.input_variables.__dict__)
    elif alg.name == 'BayesianRidgeRegression':
        from sklearn.linear_model import BayesianRidge
        model = BayesianRidge(**alg.input_variables.__dict__)
    elif alg.name == 'AdaBoost' and alg.type == 'regression':
        from sklearn.ensemble import AdaBoostRegressor
        model = AdaBoostRegressor(**alg.input_variables.__dict__)
    elif alg.name == 'GradientBoosting' and alg.type == 'regression':
        from sklearn.ensemble import GradientBoostingRegressor
        model = GradientBoostingRegressor(**alg.input_variables.__dict__)
    elif alg.name == 'RandomForest' and alg.type == 'regression':
        from sklearn.ensemble import RandomForestRegressor
        model = RandomForestRegressor(**alg.input_variables.__dict__)
    elif alg.name == 'XGBoost' and alg.type == 'regression':
        from xgboost.sklearn import XGBRegressor
        model = XGBRegressor(**alg.input_variables.__dict__)
    elif alg.name == 'CatBoost' and alg.type == 'regression':
        from catboost import CatBoostRegressor
        model = CatBoostRegressor(**alg.input_variables.__dict__)
else:
    # -------------------------------------------------------------
    # Anomaly detection algorithms
    #
    if alg.name == 'OneClassSVM':
        from sklearn import svm
        model = svm.OneClassSVM(**alg.input_variables.__dict__)
    elif alg.name == 'IsolationForest':
        from sklearn.ensemble import IsolationForest
        model = IsolationForest(**alg.input_variables.__dict__)
    # -------------------------------------------------------------
    # Clustering algorithms
    #
github binliwhu / ML-Quantamental / Codes / MainFile.py View on Github external
showtrasecfee(0.005)
showtrasecfee(0.0075)
showtrasecfee(0.01)

#****************************5.全样本12个月特征筛选过程************************************#

i = 1#选取12个月滑动窗口筛选因子
dropimportant(window[i] ,LinearRegression(), 'OLS'+str(window[i]), factorname, timeseries,0.0201)
FCselect(factorname, timeseries)
dropimportant(window[i], PLSRegression(PLS_params[i]), 'PLS', factorname, timeseries, 0.0230)
dropimportant(window[i], Lasso(alpha=lasso_params[i]), 'Lasso', factorname, timeseries, 0.0208)
dropimportant(window[i], Ridge(alpha=ridge_params[i]), 'Ridge', factorname, timeseries, 0.0208)
dropimportant(window[i], ElasticNet(alpha= elasticnet_params['alpha'] [i],l1_ratio= elasticnet_params['l1_ratio'][i]), 'ElasticNet', factorname, timeseries, 0.0212)
dropimportant(window[i], SVR(kernel=SVR_params['kernel'][i],gamma= SVR_params ['gamma'][i],C= SVR_params ['C'][i] ), 'SVR', factorname, timeseries, 0.0225)
dropimportant(window[i], GradientBoostingRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i],learning_rate=GBDT_params['learning_rate'][i]), 'GBDT', factorname, timeseries, 0.0268)
dropimportant(window[i], XGBRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i], learning_rate=GBDT_params['learning_rate'][i]), 'XGBOOST',  factorname, timeseries, 0.0273)
dropimportant(window[i], ensemblenn(5,modeluse = MLPRegressor(solver = 'lbfgs', max_iter=ENANN_params['max_iter'][i]), pickpercent=ENANN_params['p'][i]), 'ENANN', factorname, timeseries, 0.0234)
dropimportant(window[i], DFN.DFN(outputdim=1, neuralset=[96, 50, 25, 10, 5, 2], ctx=gpu(0), epoch=10, batch_size=DFN_params['batch'][i], lr=DFN_params['learning_rate'][i]), 'DFN', factorname, timeseries, 0.0278)
dropimportant2(window[i], rm.lstmmodule(95, LSTM_params['hidden_number'][i], LSTM_params['depth'][i], 100, 3571, lr=LSTM_params['learning_rate'][i]), 'LSTM', factorname, timeseries2, 0.0257)
dropimportant2(window[i], rm.lstmmodule(95,  RNN_params['hidden_number'][i], RNN_params['depth'][i], 100, 3571, lr=RNN_params['learning_rate'][i], ntype='RNN'), 'RNN', factorname, timeseries2, 0.0210)


#****************************6.特征筛选后16项因子12个月滑动窗口函数运行************************************#
path = r'..\DataBase\factorselect'#经过筛选后因子集合所在路径
riskfree,timeseries,factor,timeseries2=datatransfrom(path)[0],datatransfrom(path)[1],datatransfrom(path)[2],datatransfrom2(path,after=True)[0]
i=1 #选取12个月滑动窗口测试筛选后因子集合绩效表现
output(window[i],LinearRegression(),'OLS'+str(window[i]),riskfree[i], timeseries)
FC(window[i], riskfree[i], timeseries, 11,'FC')
output(window[i], PLSRegression(PLS_params[i]), 'PLS' + str(window[i]), riskfree[i], timeseries)
output(window[i],Lasso(alpha=lasso_params[i]),'Lasso'+ str(window[i]), riskfree[i], timeseries)
output(window[i],Ridge(alpha=ridge_params[i]),'Ridge'+str(window[i]),riskfree[i], timeseries)
output(window[i],ElasticNet(alpha= elasticnet_params['alpha'] [i],l1_ratio= elasticnet_params['l1_ratio'][i]),'ElasticNet'+str(window[i]),riskfree[i], timeseries)
github binliwhu / ML-Quantamental / Codes / MainFile.py View on Github external
dropimportant2(window[i], rm.lstmmodule(95,  RNN_params['hidden_number'][i], RNN_params['depth'][i], 100, 3571, lr=RNN_params['learning_rate'][i], ntype='RNN'), 'RNN', factorname, timeseries2, 0.0210)


#****************************6.特征筛选后16项因子12个月滑动窗口函数运行************************************#
path = r'..\DataBase\factorselect'#经过筛选后因子集合所在路径
riskfree,timeseries,factor,timeseries2=datatransfrom(path)[0],datatransfrom(path)[1],datatransfrom(path)[2],datatransfrom2(path,after=True)[0]
i=1 #选取12个月滑动窗口测试筛选后因子集合绩效表现
output(window[i],LinearRegression(),'OLS'+str(window[i]),riskfree[i], timeseries)
FC(window[i], riskfree[i], timeseries, 11,'FC')
output(window[i], PLSRegression(PLS_params[i]), 'PLS' + str(window[i]), riskfree[i], timeseries)
output(window[i],Lasso(alpha=lasso_params[i]),'Lasso'+ str(window[i]), riskfree[i], timeseries)
output(window[i],Ridge(alpha=ridge_params[i]),'Ridge'+str(window[i]),riskfree[i], timeseries)
output(window[i],ElasticNet(alpha= elasticnet_params['alpha'] [i],l1_ratio= elasticnet_params['l1_ratio'][i]),'ElasticNet'+str(window[i]),riskfree[i], timeseries)
output(window[i],SVR(kernel=SVR_params['kernel'][i],gamma= SVR_params ['gamma'][i],C= SVR_params ['C'][i] ),'SVR'+str(window[i]),riskfree[i], timeseries)
output(window[i], GradientBoostingRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i],learning_rate=GBDT_params['learning_rate'][i]), 'GBDT' + str(window[i]),riskfree[i], timeseries)
output(window[i], XGBRegressor(n_estimators=GBDT_params['n_estimators'][i],max_depth=GBDT_params['maxdepth'][i], learning_rate=GBDT_params['learning_rate'][i]), 'XGBOOST' + str(window[i]), riskfree[i], timeseries)
output(window[i], ensemblenn(5,modeluse = MLPRegressor(solver = 'lbfgs', max_iter=ENANN_params['max_iter'][i]), pickpercent=ENANN_params['p'][i]), 'ENANN' + str(window[i]), riskfree[i], timeseries)
output(window[i], DFN.DFN(outputdim=1, neuralset=[16, 50, 25, 10, 5, 2], ctx=gpu(0), epoch=10, batch_size=DFN_params['batch'][i], lr=DFN_params['learning_rate'][i]), 'DFN' + str(window[i]), riskfree[i], timeseries)
output2(window[i], rm.lstmmodule(11, LSTM_params['hidden_number'][i], LSTM_params['depth'][i], 100, 3571, lr=LSTM_params['learning_rate'][i]), 'LSTM'+ str(window[i]) ,riskfree[i], timeseries2)
output2(window[i], rm.lstmmodule(11,  RNN_params['hidden_number'][i], RNN_params['depth'][i], 100, 3571, lr=RNN_params['learning_rate'][i], ntype='RNN'), 'RNN'+ str(window[i]), riskfree[i], timeseries2)