本文整理汇总了Python中sklearn.ensemble.GradientBoostingRegressor.transform方法的典型用法代码示例。如果您正苦于以下问题:Python GradientBoostingRegressor.transform方法的具体用法?Python GradientBoostingRegressor.transform怎么用?Python GradientBoostingRegressor.transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.GradientBoostingRegressor
的用法示例。
在下文中一共展示了GradientBoostingRegressor.transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_feature_importances
# 需要导入模块: from sklearn.ensemble import GradientBoostingRegressor [as 别名]
# 或者: from sklearn.ensemble.GradientBoostingRegressor import transform [as 别名]
def test_feature_importances():
X = np.array(boston.data, dtype=np.float32)
y = np.array(boston.target, dtype=np.float32)
clf = GradientBoostingRegressor(n_estimators=100, max_depth=5, min_samples_split=1, random_state=1)
clf.fit(X, y)
# feature_importances = clf.feature_importances_
assert_true(hasattr(clf, "feature_importances_"))
X_new = clf.transform(X, threshold="mean")
assert_less(X_new.shape[1], X.shape[1])
feature_mask = clf.feature_importances_ > clf.feature_importances_.mean()
assert_array_almost_equal(X_new, X[:, feature_mask])
示例2: __init__
# 需要导入模块: from sklearn.ensemble import GradientBoostingRegressor [as 别名]
# 或者: from sklearn.ensemble.GradientBoostingRegressor import transform [as 别名]
class mixmodels:
def __init__(self,nest=10):
self.nest = nest
def fit(self,data_train,target):
self.target_train = target
self.catcol = data_train.filter(like='var').columns.tolist()
#start_gbr_tr = time.clock()
self.gbr = GradientBoostingRegressor(n_estimators =self.nest,max_depth=7)
self.gbr.fit(data_train,self.target_train)
self.transformed_train_gbr = self.gbr.transform(data_train,threshold="0.35*mean")
self.gbr_tr_fit = GradientBoostingRegressor(n_estimators =self.nest,max_depth=7)
self.gbr_tr_fit.fit(self.transformed_train_gbr,self.target_train)
#end_gbr_tr = time.clock()
#print >> log, "time_gbr_tr = ", end_gbr_tr-start_gbr_tr
#start_xfr_tr = time.clock()
self.xfr= ExtraTreesRegressor(n_estimators =self.nest,max_depth=7)
self.xfr.fit(data_train,self.target_train)
self.transformed_train_xfr = self.xfr.transform(data_train,threshold="0.35*mean")
self.xfr_tr_fit = ExtraTreesRegressor(n_estimators =self.nest,max_depth=7)
self.xfr_tr_fit.fit(self.transformed_train_xfr,self.target_train)
#end_xfr_tr = time.clock()
#print >> log, "time_xfr_tr = ", end_xfr_tr-start_xfr_tr
#start_gbr_cat = time.clock()
self.gbr_cat_fit = GradientBoostingRegressor(n_estimators =self.nest,max_depth=7)
self.gbr_cat_fit.fit(data_train[self.catcol],self.target_train)
#end_gbr_cat = time.clock()
#print >> log, "time_gbr_cat = ", end_gbr_cat-start_gbr_cat
#start_xfr_cat = time.clock()
self.xfr_cat_fit = ExtraTreesRegressor(n_estimators =self.nest,max_depth=7)
self.xfr_cat_fit.fit(data_train[self.catcol],self.target_train)
#end_xfr_cat = time.clock()
#print >> log, "time_xfr_cat = ", end_xfr_cat-start_xfr_cat
return self
def predict(self,data_test):
mix_test_list = []
transformed_test_gbr = self.gbr.transform(data_test,threshold="0.35*mean")
mix_test_list += [pd.Series(self.gbr_tr_fit.predict(transformed_test_gbr))]
transformed_test_xfr = self.xfr.transform(data_test,threshold="0.35*mean")
mix_test_list += [pd.Series(self.xfr_tr_fit.predict(transformed_test_xfr))]
mix_test_list += [pd.Series(self.gbr_cat_fit.predict(data_test[self.catcol]))]
mix_test_list += [pd.Series(self.xfr_cat_fit.predict(data_test[self.catcol]))]
mix_test = pd.concat(mix_test_list,1)
mix_ave = mix_test.mean(1)
mix_ave.name='target'
return mix_ave
def score(self,data_test,target_test):
total_score = []
transformed_test_gbr = self.gbr.transform(data_test,threshold="0.35*mean")
total_score += [ self.gbr_tr_fit.score(transformed_test_gbr,target_test) ]
transformed_test_xfr = self.xfr.transform(data_test,threshold="0.35*mean")
total_score += [ self.xfr_tr_fit.score(transformed_test_xfr,target_test) ]
total_score += [ self.gbr_cat_fit.score(data_test[self.catcol],target_test) ]
total_score += [ self.xfr_cat_fit.score(data_test[self.catcol],target_test) ]
return sum(total_score)/float(len(total_score))
def gini(self,data_test,target_test):
weight = data_test.var11
gns = []
transformed_test_gbr = self.gbr.transform(data_test,threshold="0.35*mean")
gns += [normalized_weighted_gini(target_test.tolist(),self.gbr_tr_fit.predict(transformed_test_gbr).tolist(),weight.tolist()) ]
transformed_test_xfr = self.xfr.transform(data_test,threshold="0.35*mean")
gns += [normalized_weighted_gini(target_test.tolist(),self.xfr_tr_fit.predict(transformed_test_xfr).tolist(),weight.tolist()) ]
gns += [normalized_weighted_gini(target_test.tolist(),self.gbr_cat_fit.predict(data_test[self.catcol]).tolist(),weight.tolist()) ]
gns += [normalized_weighted_gini(target_test.tolist(),self.xfr_cat_fit.predict(data_test[self.catcol]).tolist(),weight.tolist()) ]
return sum(gns)/float(len(gns))