当前位置: 首页>>代码示例>>Python>>正文


Python ExtraTreesRegressor.predict方法代码示例

本文整理汇总了Python中sklearn.ensemble.ExtraTreesRegressor.predict方法的典型用法代码示例。如果您正苦于以下问题:Python ExtraTreesRegressor.predict方法的具体用法?Python ExtraTreesRegressor.predict怎么用?Python ExtraTreesRegressor.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.ensemble.ExtraTreesRegressor的用法示例。


在下文中一共展示了ExtraTreesRegressor.predict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mul_dtree

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def mul_dtree(X, Y2):
    forest = ExtraTreesRegressor(n_estimators=5,
                             compute_importances=True,
                             random_state=0)
    forest.fit(X[:200], Y2[:200])
    forest.predict(X[200:])
    print Y2[200:]
开发者ID:Catentropy,项目名称:mylab,代码行数:9,代码来源:t_dtree.py

示例2: train

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
    def train(self, verbose=False, training_data=None):
        n_estimators = 50
        n_samples = 5000

        trainingDataDict = self._getTrainingData(numSamples=n_samples)

        X = np.array(trainingDataDict['rot_line_test_deriv'], dtype=np.float32)
        y = np.array(trainingDataDict['solution_data'][0], dtype=np.float32)
        dtr0 = ExtraTreesRegressor(n_estimators=n_estimators)
        dtr0 = dtr0.fit(X, y)

        X = np.array(trainingDataDict['rot_line_test_deriv'], dtype=np.float32)
        y = np.array(trainingDataDict['solution_data'][1], dtype=np.float32)
        dtr1 = ExtraTreesRegressor(n_estimators=n_estimators)
        dtr1 = dtr1.fit(X, y)

        X = np.array(trainingDataDict['scaled_img'], dtype=np.float32)
        y = np.array(trainingDataDict['solution_data'][0], dtype=np.float32)
        str0 = ExtraTreesRegressor(n_estimators=n_estimators)
        str0 = str0.fit(X, y)

        X = np.array(trainingDataDict['scaled_img'], dtype=np.float32)
        y = np.array(trainingDataDict['solution_data'][1], dtype=np.float32)
        str1 = ExtraTreesRegressor(n_estimators=n_estimators)
        str1 = str1.fit(X, y)


        trainingDataDict = self._getTrainingData(startPos=n_samples+1, numSamples=n_samples)

        dtr0Pred = [dtr0.predict(trainingDataDict['rot_line_test_deriv'][i]) for i in range(len(trainingDataDict['rot_line_test_deriv']))]
        dtr1Pred = [dtr1.predict(trainingDataDict['rot_line_test_deriv'][i]) for i in range(len(trainingDataDict['rot_line_test_deriv']))]
        str0Pred = [str0.predict(trainingDataDict['scaled_img'][i]) for i in range(len(trainingDataDict['scaled_img']))]
        str1Pred = [str1.predict(trainingDataDict['scaled_img'][i]) for i in range(len(trainingDataDict['scaled_img']))]

        X = np.array([[dtr0Pred[i][0], str0Pred[i][0]] for i in xrange(len(dtr0Pred))], dtype=np.float32)
        y = np.array(trainingDataDict['solution_data'][0], dtype=np.float32)
        ftr0 = ExtraTreesRegressor(n_estimators=n_estimators)
        ftr0 = ftr0.fit(X, y)

        X = np.array([(dtr1Pred[i][0], str1Pred[i][0]) for i in xrange(len(dtr1Pred))], dtype=np.float32)
        y = np.array(trainingDataDict['solution_data'][1], dtype=np.float32)
        ftr1 = ExtraTreesRegressor(n_estimators=n_estimators)
        ftr1 = ftr1.fit(X, y)

        self.dtr0 = dtr0
        self.dtr1 = dtr1
        self.str0 = str0
        self.str1 = str1
        self.ftr0 = ftr0
        self.ftr1 = ftr1

        self.areModelsTrained = True
开发者ID:rmclaren,项目名称:Kaggle-GalaxyZoo,代码行数:54,代码来源:Class4.py

示例3: estimate

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def estimate():
    from loadData import loadSets
    from helper import splitDataset, separateTargetFromTrain
    from sklearn.ensemble import ExtraTreesRegressor
    import numpy as np
    import math

    best_rmsle = 2
    best_i = 0
    
    trainingSet, testingSet = loadSets()
    testingSet = None

    trainingData, testingData = splitDataset(trainingSet, 0.6)
    testingData, validationData = splitDataset(testingData, 0.5)
    trainingSet = None
    
    trainingTarget, trainingFeatures = separateTargetFromTrain(trainingData)
    testingTarget, testingFeatures = separateTargetFromTrain(testingData)
    validationTarget, validationFeatures = separateTargetFromTrain(validationData)

    testingTarget = testingTarget.values
    validationTarget = validationTarget.values
    
    trainingData = None
    testingData = None
    validationData = None    
    
    for i in range(2000, 3001, 1000):
        model = ExtraTreesRegressor(n_estimators = i, n_jobs = -1)
        model.fit(trainingFeatures, trainingTarget)
        
        predictions = model.predict(testingFeatures)
                
        cost = pow(np.log(predictions + 1) - np.log(testingTarget + 1), 2)
        rmsle = math.sqrt(np.mean(cost))
        print i, " estimators: ", rmsle
        
        if rmsle < best_rmsle:
            best_rmsle = rmsle
            best_i = i
            
    print "Best: ", best_i, " estimators with rmsle: ", best_rmsle
    
    model = ExtraTreesRegressor(n_estimators = best_i, n_jobs = -1)
    model.fit(trainingFeatures, trainingTarget)
    predictions = model.predict(validationFeatures)
            
    cost = pow(np.log(predictions + 1) - np.log(validationTarget + 1), 2)
    rmsle = math.sqrt(np.mean(cost))
    
    print "Final model cost: ", rmsle
开发者ID:tcoatale,项目名称:Caterpillar-tube-Pricing,代码行数:54,代码来源:extraRandomForest.py

示例4: do_etrees

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def do_etrees(filename):
    df, Y = create_merged_dataset(filename)
    etree = ExtraTreesRegressor(n_estimators=200, n_jobs=-1, min_samples_leaf=5, random_state=SEED)
    X = df.drop(['driver', 'trip'], 1)
    etree.fit(X, Y)
    probs = etree.predict(X[:200])
    return pd.DataFrame({'driver': df['driver'][:200], 'trip': df['trip'][:200], 'probs': probs})
开发者ID:fabiogm,项目名称:kaggle-driver-telematics,代码行数:9,代码来源:main.py

示例5: predict_with_one

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def predict_with_one(X, out_file_name):
    n_samples, n_features = X.shape
    iter_num = 3
    div = ShuffleSplit(n_samples, n_iter=iter_num, test_size=0.2, random_state=0)
    model = ExtraTreesRegressor(n_estimators=5)
    score_matrix = np.zeros((n_features, n_features))

    t = time()
    round_num = 0
    for train, test in div:
        round_num += 1
        train_samples = X[np.array(train)]
        test_samples = X[np.array(test)]
        for i in range(n_features):
            for j in range(n_features):
                X_train = train_samples[:, i:i+1]
                X_test = test_samples[:, i:i+1]
                y_train = train_samples[:, j]
                y_test = test_samples[:, j]
        # for i in range(len(fl)):
        #     for j in range(len(fl)):
        #         if fl[j][1]-fl[j][0] != 1:
        #             continue
        #         X_train = train_samples[:, fl[i][0]:fl[i][1]]
        #         X_test = test_samples[:, fl[i][0]:fl[i][1]]
        #         y_train = train_samples[:, fl[j][0]]
        #         y_test = test_samples[:, fl[j][0]]
                model.fit(X_train, y_train)
                y_pred = model.predict(X_test)
                mae = mean_absolute_error(y_test, y_pred)
                score_matrix[i, j] += mae
                print('Round', round_num, '|', i, j, mae, time()-t)
    np.savetxt(os.path.join(CODE_PATH, out_file_name),
               score_matrix/iter_num, fmt='%.3f', delimiter=',')
开发者ID:Jewelryland,项目名称:YelpRecSys,代码行数:36,代码来源:feature_covariance.py

示例6: build_extra_tree_regressor

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def build_extra_tree_regressor(X_test, X_train_full, y_train_full):


    print "Building ExtraTrees regressor..."
    etr = ExtraTreesRegressor(n_estimators=500)
    etr.fit(X_train_full, y_train_full)
    etr_predict = etr.predict(X_test)

    return etr_predict
开发者ID:DarioBernardo,项目名称:Kaggle,代码行数:11,代码来源:BlendedRegressorsCV.py

示例7: classify

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
 def classify(self):
     """Perform classification"""
     clf = ETRegressor(n_estimators=500, min_samples_split=5, min_samples_leaf=2)
     #pca = PCA(n_components = 400)
     #self._ClassifyDriver__traindata = pca.fit_transform(self._ClassifyDriver__traindata)
     #self._ClassifyDriver__testdata = pca.transform(self._ClassifyDriver__testdata)
     #print self._ClassifyDriver__traindata.shape
     clf.fit(self._ClassifyDriver__traindata, self._ClassifyDriver__trainlabels)
     self._ClassifyDriver__y = clf.predict(self._ClassifyDriver__testdata)
开发者ID:thekannman,项目名称:kaggle,代码行数:11,代码来源:ClassifyDriver.py

示例8: extra_trees_regressor

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def extra_trees_regressor(x, y, n_estimators, max_depth):
    kf = KFold(len(x), n_folds=3)
    scores = []
    for train_index, test_index in kf:
        X_train, X_test = x[train_index], x[test_index]
        y_train, y_test = y[train_index], y[test_index]
        clf = ExtraTreesRegressor(n_estimators=n_estimators, max_depth=max_depth, random_state=0)
        clf.fit(X_train, y_train)
        scores.append(mean_squared_error(clf.predict(X_test), y_test) ** 0.5)
    return np.mean(scores)
开发者ID:milton0825,项目名称:yelp-lr,代码行数:12,代码来源:baseline_rating.py

示例9: reg_skl_etr

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def reg_skl_etr(param, data):
    [X_tr, X_cv, y_class_tr, y_class_cv, y_reg_tr, y_reg_cv] = data
    etr = ExtraTreesRegressor(n_estimators=param['n_estimators'],
                              max_features=param['max_features'],
                              n_jobs=param['n_jobs'],
                              random_state=param['random_state'])
    etr.fit(X_tr, y_reg_tr)
    pred = etr.predict(X_cv)
    RMSEScore = getscoreRMSE(y_reg_cv, pred)
    return RMSEScore, pred
开发者ID:matlabat,项目名称:Home-Depot-Search-Relevance,代码行数:12,代码来源:models_param.py

示例10: MyExtraTreeReg

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
class MyExtraTreeReg(MyRegressor):
    def __init__(self, params=dict()):
        self._params = params
        self._extree = ExtraTreesRegressor(**(self._params))

    def update_params(self, updates):
        self._params.update(updates)
        self._extree = ExtraTreesRegressor(**(self._params))

    def fit(self, Xtrain, ytrain):
        self._extree.fit(Xtrain, ytrain)

    def predict(self, Xtest, option = None):
      return self._extree.predict(Xtest)

    def plt_feature_importance(self, fname_list, f_range = list()):
        importances = self._extree.feature_importances_

        std = np.std([tree.feature_importances_ for tree in self._extree.estimators_], axis=0)
        indices = np.argsort(importances)[::-1]

        fname_array = np.array(fname_list)

        if not f_range:
            f_range = range(indices.shape[0])

        n_f = len(f_range)

        plt.figure()
        plt.title("Extra Tree Feature importances")
        plt.barh(range(n_f), importances[indices[f_range]],
               color="b", xerr=std[indices[f_range]], ecolor='k',align="center")
        plt.yticks(range(n_f), fname_array[indices[f_range]])
        plt.ylim([-1, n_f])
        plt.show()


    def list_feature_importance(self, fname_list, f_range = list(), return_list = False):
        importances = self._extree.feature_importances_
        indices = np.argsort(importances)[::-1]

        print 'Extra tree feature ranking:'

        if not f_range :
            f_range = range(indices.shape[0])

        n_f = len(f_range)

        for i in range(n_f):
            f = f_range[i]
            print '{0:d}. feature[{1:d}]  {2:s}  ({3:f})'.format(f + 1, indices[f], fname_list[indices[f]], importances[indices[f]])

        if return_list:
            return [indices[f_range[i]] for i in range(n_f)]
开发者ID:tonyzhangrt,项目名称:wklearn,代码行数:56,代码来源:learner.py

示例11: algorithm_ExtraTrees

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def algorithm_ExtraTrees(X_train,Y_train,X_validation,Y_validation, seed=7):


    # 训练模型
    scaler = StandardScaler().fit(X_train)
    rescaledX = scaler.transform(X_train)
    gbr = ExtraTreesRegressor(n_estimators=80)
    gbr.fit(X=rescaledX, y=Y_train)
    # 评估算法模型
    rescaledX_validation = scaler.transform(X_validation)
    predictions = gbr.predict(rescaledX_validation)
    print(mean_squared_error(Y_validation, predictions))
开发者ID:jiluhu,项目名称:flask_ml,代码行数:14,代码来源:sklearn_regression_lib.py

示例12: __init__

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
class ModelERT:

    def __init__(self, model_set_name, i_fold):
        self.model_set_name = model_set_name
        self.i_fold = i_fold

    def set_params(self, prms):
        self.prms = prms

    def set_data(self, labels_tr, labels_te, data_tr, data_te):
        self.labels_tr = labels_tr
        self.labels_te = labels_te
        self.data_tr = data_tr
        self.data_te = data_te

    def train(self):
        print "start ert"
        self.model = ExtraTreesRegressor(n_jobs=self.prms["n_jobs"],
                                         verbose=1,
                                         random_state=self.prms["random_state"],
                                         n_estimators=int(self.prms["n_estimators"]),
                                         max_features=self.prms["max_features"])
        self.model.fit(self.data_tr.values, self.labels_tr)

    def predict(self):
        return self.model.predict(self.data_te.values)

    def predict_train(self):
        return self.model.predict(self.data_tr.values)

    def dump_model(self):
        pass

    def dump_pred(self, pred, name):
        folder = config.get_model_folder(self.model_set_name, self.i_fold)
        Files.mkdir(folder)
        path = config.get_model_path(self.model_set_name, name, self.i_fold)
        joblib.dump(pred, path)
开发者ID:threecourse,项目名称:kaggle-prudential-sample,代码行数:40,代码来源:model_ert.py

示例13: dummie_columns_extra_trees

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def dummie_columns_extra_trees(train, test):
    from sklearn.ensemble import ExtraTreesRegressor
    print "-- {} --".format("Extremely Randomized Trees Regression using all but remarks")
    predicting_columns = list(train._get_numeric_data().columns.values)
    predicting_columns.remove("LISTPRICE")
    predicting_columns.remove("SOLDPRICE")
    rf = ExtraTreesRegressor(
        n_estimators=300, n_jobs=-1)
    rf.fit(train[predicting_columns], train["SOLDPRICE"])
    score = rf.score(test[predicting_columns], test["SOLDPRICE"])
    predictions = rf.predict(test[predicting_columns])
    sample_predictions(test, predictions)
    print "Accuracy: {}\n".format(score)
    return score, predictions
开发者ID:CurleySamuel,项目名称:Thesis,代码行数:16,代码来源:first_pass.py

示例14: baseline_extra

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def baseline_extra(train_x, train_y,
                   test_x, test_y, n, d,
                   result_path="review_baseline_extra.txt"):
    predict = []
    clf = ExtraTreesRegressor(n_estimators=n,
                              max_depth=d,
                              random_state=0)
    clf = clf.fit(train_x, train_y)
    predict = clf.predict(test_x).tolist()
    result = pd.DataFrame([], columns=['review_count', 'predict'])
    result['review_count'] = test_y
    result['predict'] = predict
    result.to_csv(result_path, index=False)
    rmse = mean_squared_error(predict, test_y) ** 0.5
    return rmse
开发者ID:milton0825,项目名称:yelp-lr,代码行数:17,代码来源:baseline_review.py

示例15: simple_extremely_random_trees

# 需要导入模块: from sklearn.ensemble import ExtraTreesRegressor [as 别名]
# 或者: from sklearn.ensemble.ExtraTreesRegressor import predict [as 别名]
def simple_extremely_random_trees(data_train_x, data_test_x, data_train_y, data_test_y):
    from sklearn.ensemble import ExtraTreesRegressor
    print "-- {} --".format("Extremely Randomized Trees Regression using all but remarks")
    rf = ExtraTreesRegressor(
        n_estimators=300,
        n_jobs=-1
    )
    rf.fit(data_train_x, data_train_y)
    sample_predictions(rf.predict(data_test_x), data_test_y)
    score = rf.score(data_test_x, data_test_y)
    cross_validated_scores = cross_val_score(
        rf, data_test_x, data_test_y, cv=5)
    print "MSE Accuracy: {}".format(score)
    print "MSE Across 5 Folds: {}".format(cross_validated_scores)
    print "95%% Confidence Interval: %0.3f (+/- %0.3f)\n" % (cross_validated_scores.mean(), cross_validated_scores.std() * 1.96)
开发者ID:CurleySamuel,项目名称:Thesis,代码行数:17,代码来源:second_pass.py


注:本文中的sklearn.ensemble.ExtraTreesRegressor.predict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。