本文整理汇总了Python中sklearn.ensemble.AdaBoostRegressor.score方法的典型用法代码示例。如果您正苦于以下问题:Python AdaBoostRegressor.score方法的具体用法?Python AdaBoostRegressor.score怎么用?Python AdaBoostRegressor.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.AdaBoostRegressor
的用法示例。
在下文中一共展示了AdaBoostRegressor.score方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_boston
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
def test_boston():
# Check consistency on dataset boston house prices.
reg = AdaBoostRegressor(random_state=0)
reg.fit(boston.data, boston.target)
score = reg.score(boston.data, boston.target)
assert score > 0.85
# Check we used multiple estimators
assert len(reg.estimators_) > 1
# Check for distinct random states (see issue #7408)
assert_equal(len(set(est.random_state for est in reg.estimators_)),
len(reg.estimators_))
示例2: run_tree_regressor
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
def run_tree_regressor():
from sklearn.tree import DecisionTreeRegressor
from sklearn.cross_validation import cross_val_score
from sklearn.cross_validation import train_test_split
import numpy as np
from sklearn.ensemble import AdaBoostRegressor
print "running me"
X = np.genfromtxt("/home/john/Downloads/kaggle.X1.train.txt",delimiter=",") # load the text file
Y = np.genfromtxt("/home/john/Downloads/kaggle.Y.train.txt",delimiter=",")
x_train,x_test,y_train,y_test = train_test_split(X,Y,test_size=0.2)
rng = np.random.RandomState(1)
depth = 35 # current lowest
for estimators in [130,235,300,345,450]:
treeAdaBoost = AdaBoostRegressor(DecisionTreeRegressor(max_depth=depth),n_estimators=estimators, random_state=rng)
treeAdaBoost.fit(x_train, y_train)
print "adabost estimators @ " + str(estimators) + ":", treeAdaBoost.score(x_test, y_test)
示例3: test_boston
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
def test_boston():
# Check consistency on dataset boston house prices.
clf = AdaBoostRegressor(random_state=0)
clf.fit(boston.data, boston.target)
score = clf.score(boston.data, boston.target)
assert score > 0.85
示例4: test_boston
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
def test_boston():
"""Check consistency on dataset boston house prices."""
clf = AdaBoostRegressor()
clf.fit(boston.data, boston.target)
score = clf.score(boston.data, boston.target)
assert score > 0.85
示例5: AdaBoostRegressor
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
# Random Forest Regression
import numpy as np
from sklearn import datasets
from sklearn.ensemble import AdaBoostRegressor
# load the diabetes datasets
dataset = datasets.load_diabetes()
# fit an AdaBoost model to the data
model = AdaBoostRegressor()
model.fit(dataset.data, dataset.target)
print(model)
# make predictions
expected = dataset.target
predicted = model.predict(dataset.data)
# summarize the fit of the model
mse = np.mean((predicted-expected)**2)
print(mse)
print(model.score(dataset.data, dataset.target))
示例6: train_test_split
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
#trn2=train
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(trn2[feature_cols], trn2['Hazard'], random_state=1)
#fit the model and predict
# model = AdaBoostRegressor(base_estimator=RandomForestRegressor())
model = AdaBoostRegressor()
model.fit(X_train,y_train)
y_pred =model.predict(X_test)
coef = giniscore.Gini(y_pred,y_test)
print 'Gini coefficient is ', coef
model.score(X_train,y_train)
# score with 100 rows RF estimator is .92
# gini with default columns, default estimator is 0.12
# gini with 1000 rows all columns, default estimater is 0.188
# gini with 10000 rows all columns, default estimater is 0.1802
# gini with all rows all columns, default estimater is 0.12759
# gini with 100 rows RF esimator is .098
# gini with 1000 rows RF estimator is .0876
# ugh, using LassoCV 32 the score is only .19 to 21 so it must want all the columns
# benchmark is .20 , Kaggle public LB says .263387
# < 14 97.5% benchmark is .172
# < 10 90.5% benchmark is .1472
示例7: range
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
for i in index:
if scores2[i]<0.88:
list_index2.append(list_index[i])
n=len(list_index2)
b_train=True
b_test=True
for i in range(n):
b_train=b_train&(X_train[:,index_adt]==np.unique(X_train[:,index_adt])[list_index2[i]])
b_test=b_test&(X_test[:,index_adt]==np.unique(X_test[:,index_adt])[list_index2[i]])
reg2=AdaBoostRegressor(RandomForestRegressor())
reg2.fit(X_train[b_train],y_train[b_train])
reg2.score(X_test[b_test],y_test[b_test])
Qt[b_train]=Qt[b_train]-reg2.predict(X_train[b_train])
Q[b_test]=Q[b_test]-reg2.predict(X_test[b_test])
Q2[b_test]=reg2.predict(X_test[b_test])
for i in range(n):
s="Pred/fit_adt_"+str(list_index2[i]+1)+".pickle"
fid = open(s, 'wb')
pickle.dump(reg2,fid)
fid.close()
r=AdaBoostRegressor(RandomForestRegressor())
r.fit(X_train,Qt)
r.score(X_test,Q)
示例8: AdaBoostRegressor
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
trainlabel = pd.read_csv("Produce_Data/University_data_cluster.csv")
#use different regression methods
est = AdaBoostRegressor(DecisionTreeRegressor())
col_predic = ["UniversityNo","Topic","Year","Lowest","Last_Ranking","Average_Ranking"] # parameter use for label training
df2 = df.merge(trainlabel[col_predic],on=["UniversityNo","Topic","Year"])
df2 = df2[~np.isnan(df2.Lowest)]
df2 = df2[~(df2["Average_Ranking"] == 0)]
X = df2[["UniversityNo","Year","Topic","Lowest","Ranking_Scores","Last_Ranking","Average_Ranking"]] #The train parameters label
y = df2.Label
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3)
est.fit(X_train,y_train)
print "----------------"
print "Prediction score: " + str(round(est.score(X_test,y_test)*1000)/10) + "%"
print "----------------"
df2.New_Label = est.predict(X) #obtain the prediction label for future ranking prediction
#sum up the enroll student number equal to smaller than the label, the predicting ranking numbers are mainly base on this parameter
for y in range(2011,2016): #no 2010 because no average ranking in it
for t in range(2):
s = 0
while sum(df2.Label >= s):
df2.loc[(df2.Year == y) & (df2.Topic == t) & (df2.Label >= s),'Plan_Number_Total'] += sum(df2.loc[(df2.Year == y) & (df2.Topic == t) & (np.round(df2.Label) ==s),'Plan_Number'])
s += 1
dfsave = df2
dfsave.to_csv("Produce_Data/University.csv")
示例9: AdaBoostRegressor
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
if __name__ == '__main__':
np.set_printoptions(edgeitems=5)
# Read dataset
data = np.genfromtxt("shuffled.csv", delimiter=',', skip_header=1, usecols=range(1, 385))
reference = np.genfromtxt("shuffled.csv", delimiter=',', skip_header=1, usecols=(385))
testData = np.genfromtxt("test.csv", delimiter=',', skip_header=1, usecols=range(1, 385))
validationData = np.genfromtxt("train.csv", delimiter=',', skip_header=1, usecols=range(1, 385), max_rows=5000)
validationReference = np.genfromtxt("train.csv", delimiter=',', skip_header=1, usecols=(385), max_rows=5000)
numberOfTrainingData = data.shape[0]
numberOfFeatures = data.shape[1]
numberOfTestData = testData.shape[0]
numberOfVldtData = validationData.shape[0]
# http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.AdaBoostClassifier.html
bdt = AdaBoostRegressor(base_estimator=ExtraTreeRegressor(), n_estimators=1000)
#bdt = RandomForestRegressor(n_estimators=50)
#bdt = GradientBoostingRegressor()
bdt.fit(data, reference)
print("FINISH FITTING")
predict = bdt.predict(testData).reshape(numberOfTestData, 1)
score = bdt.score(validationData, validationReference)
print(score)
with open('adaboostResult.csv', 'w') as file:
file.write("id,reference\n")
for i in range(0, numberOfTestData):
file.write("%d,%f\n" %(i, predict[i]))
示例10: DecisionTreeRegressor
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
from sklearn.tree import DecisionTreeRegressor
##ARBRES DE DECISION
regressor = DecisionTreeRegressor(max_leaf_nodes=9072)
regressor.fit(X_train, Y_train)
#%%
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import AdaBoostRegressor
##BOOSTING
regBoost = AdaBoostRegressor(DecisionTreeRegressor(max_depth=300), loss='square')
regBoost.fit(X_train, Y_train)
Y_test = regBoost.predict(X_test)
regBoost.score(X_train,Y_train)
regBoost.score(X_test,Y_test)
Y_test = Y_test.astype(int)
#%%
regr_3 = AdaBoostRegressor(DecisionTreeRegressor(max_depth=200), n_estimators=300)
regr_3.fit(X_train,Y_train)
y_3 = regr_3.predict(X_test)
#%%
Y_test = regressor.predict(X_test)
示例11: AdaBoostRegressor
# 需要导入模块: from sklearn.ensemble import AdaBoostRegressor [as 别名]
# 或者: from sklearn.ensemble.AdaBoostRegressor import score [as 别名]
print "train score: ", dtr.score(data_0am_train_xx,data_0am_train_yy)
print "train error: " , np.sqrt(np.mean((data_0am_train_predy-data_0am_train_yy)**2))/nom_train
print "test error: ", np.sqrt(np.mean((data_0am_test_predy-data_0am_test_y)**2))/nom_test
rng = np.random.RandomState(1)
abr = AdaBoostRegressor(DecisionTreeRegressor(max_depth=5),
n_estimators=300, random_state=rng)
abr.fit(data_0am_train_xx,data_0am_train_yy)
data_0am_train_predy = abr.predict(data_0am_train_xx)
abr_train_predy = abr.predict(data_0am_train_xx)
data_0am_test_predy = abr.predict(data_0am_test_x)
abr_test_predy = abr.predict(data_0am_test_x)
print "ABR report"
print "train score: ", abr.score(data_0am_train_xx,data_0am_train_yy)
print "train error: " , np.sqrt(np.mean((data_0am_train_predy-data_0am_train_yy)**2))/nom_train
print "test error: ", np.sqrt(np.mean((data_0am_test_predy-data_0am_test_y)**2))/nom_test
# print lasso_train_predy.shape
combine_train_predy = np.concatenate((
np.atleast_2d(linear_train_predy),
np.atleast_2d(lasso_train_predy),
np.atleast_2d(DTR_train_predy),
np.atleast_2d(svr_train_predy),
np.atleast_2d(abr_train_predy)),axis=0)
# print combine_train_predy.shape
combine_train_predy= np.mean(combine_train_predy,axis=0)
# print combine_train_predy.shape