本文整理汇总了Python中sklearn.ensemble.GradientBoostingRegressor.nestimators方法的典型用法代码示例。如果您正苦于以下问题:Python GradientBoostingRegressor.nestimators方法的具体用法?Python GradientBoostingRegressor.nestimators怎么用?Python GradientBoostingRegressor.nestimators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.GradientBoostingRegressor
的用法示例。
在下文中一共展示了GradientBoostingRegressor.nestimators方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from sklearn.ensemble import GradientBoostingRegressor [as 别名]
# 或者: from sklearn.ensemble.GradientBoostingRegressor import nestimators [as 别名]
def main():
df_train = pd.read_csv("data/train.csv")
df_test = pd.read_csv("data/test.csv")
y = np.log(np.array(df_train["revenue"]))
# test_id=df_test["Id"]
df = pd.concat([df_train, df_test])
df = processing(df)
df_train = df[0:137, :]
df_test = df[137:, :]
X = df_train
print X.shape, y.shape
X_test = df_test
model = GradientBoostingRegressor(learning_rate=0.1, max_depth=1, random_state=0, loss="huber")
# samplesubmit.head()
if 1:
selector = SelectPercentile(f_regression, percentile=100)
selector.fit(X, y)
print selector.pvalues_
scores = -np.log10(selector.pvalues_)
scores /= scores.max()
print scores
feature_index_0 = scores > 0.1
# model.C=1.e4
# model.gamma=0.2
X = X[:, feature_index_0]
# print X.shape
# model.fit(X,y)
# y_pred=model.predict(X)
# meanres=np.median(y-y_pred)
# stdres=np.median(np.abs(y-y_pred-meanres))
# print meanres,stdres
# outlierindex=np.abs(y-y_pred-meanres)>5.*stdres
# print len(y[outlierindex])
# plt.plot(y-y_pred,'.')
# plt.plot((y-y_pred)[outlierindex],'r.')
# plt.show()
# return
# X=X[~outlierindex,:]
# y=y[~outlierindex]
# if(1):
# selector=SelectPercentile(f_regression,percentile=100)
# selector.fit(X,y)
# print selector.pvalues_
# scores=-np.log10(selector.pvalues_)
# scores/=scores.max()
# print scores
# feature_index_1=scores>0.1
##return
if 0:
# gammas=np.logspace(-7,7,50)
# gammas=[0.1]
# C_s=np.array([1])
# return
# model=SVR()
# X=X[:,feature_index_1]
nestimators = np.logspace(0, 4, 50)
# C_s=np.logspace(-7,2,50)
# C_s=np.logspace(0,5,50)
scores_mean = []
scores_std = []
best_score = 1.0e20
best_C = 1
best_gamma = 1
for ne in nestimators:
if 1:
# for gamma in gammas:
model.nestimators = ne
# model.gamma=gamma
scores = cross_val_score(model, X, y, cv=10, scoring="mean_squared_error")
scores_mean.append(np.sqrt(-np.mean(scores)))
print np.sqrt(-np.mean(scores))
# if np.sqrt(-np.mean(scores))<best_score:
# best_C=C
# best_gamma=gamma
# best_score=np.sqrt(-np.mean(scores))
scores_std.append(np.std(scores))
# plt.semilogx(gammas,scores_mean,'.')
# plt.plot(X[:,0],y-y_pred,'.')
# plt.plot(X[:,1],y-y_pred,'.')
# plt.plot(X[:,2],y-y_pred,'.')
# plt.plot(X[:,3],y-y_pred,'.')
plt.semilogx(nestimators, np.array(scores_mean) / 1.0e6, ".")
plt.show()
# print best_C,best_gamma,best_score
return
#
# model=SVR()
# X=X[:,feature_index_1]
# X=X[:,feature_index_0]
# model.gamma=0.1
# model.C=1.5e3
# model=SVR()
# model.C=1.38949549437
model.nestimators = 100
# model.gamma=0.193069772888
model.fit(X, y)
# y_pred=model.predict(X)
# plt.plot(y-y_pred,'.')
# plt.show()
#.........这里部分代码省略.........