本文整理汇总了Python中sklearn.ensemble.RandomForestRegressor.fit_transform方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestRegressor.fit_transform方法的具体用法?Python RandomForestRegressor.fit_transform怎么用?Python RandomForestRegressor.fit_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.RandomForestRegressor
的用法示例。
在下文中一共展示了RandomForestRegressor.fit_transform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: buildForest
# 需要导入模块: from sklearn.ensemble import RandomForestRegressor [as 别名]
# 或者: from sklearn.ensemble.RandomForestRegressor import fit_transform [as 别名]
def buildForest(self, X_train, y_train):
NUM_TREES = 100
NUM_JOBS = 1
FEATURES_IN_EACH_TREE = "sqrt"
rf = RandomForestRegressor(n_estimators=NUM_TREES, verbose=1, n_jobs=NUM_JOBS, max_features=FEATURES_IN_EACH_TREE, oob_score=True, max_depth=25)
rf.fit_transform(X_train, y_train)
return rf
示例2: predict_on_test
# 需要导入模块: from sklearn.ensemble import RandomForestRegressor [as 别名]
# 或者: from sklearn.ensemble.RandomForestRegressor import fit_transform [as 别名]
def predict_on_test():
sample = pd.read_csv(join(SAMPLES_FILE_PATH, "sample_train.csv"))
test = pd.read_csv(join(SAMPLES_FILE_PATH, "sample_test.csv"))
preprocessed = Preprocess(sample)
rf = RandomForestRegressor(n_estimators = 100, criterion = "mse", bootstrap = True, max_features = 'sqrt', depth = 40)
rf.fit_transform(X = preprocessed.features, y = preprocessed.labels.values.ravel())
test_preprocessed = Preprocess(test)
predicted_values = rf.predict(test_preprocessed.features)
error_rate, _ = benchmark(predicted_values.ravel(), test_preprocessed.labels.values)
print "Mean Square Prediction Erorr = %s" % MSE_prediction(predicted_values, test_preprocessed.labels)
plot_feature_importances(preprocessed.features.columns.values, rf.feature_importances_)
示例3: cross_validate_depth
# 需要导入模块: from sklearn.ensemble import RandomForestRegressor [as 别名]
# 或者: from sklearn.ensemble.RandomForestRegressor import fit_transform [as 别名]
def cross_validate_depth():
sample = pd.read_csv(join(SAMPLES_FILE_PATH, "sample_train.csv"))
preprocessed = Preprocess(sample)
depths = (2, 40, 60, 80)
oob_scores = []
for depth in depths:
rf = RandomForestRegressor(n_estimators = 60, criterion = "mse", bootstrap = True, oob_score = True, max_features = 'sqrt', max_depth = depth)
rf.fit_transform(X = preprocessed.features, y = preprocessed.labels.values.ravel())
score = 1.0 - rf.oob_score_
oob_scores.append(score)
print "Out-of-Bag Error for Depth %s: %s" % (depth, score)
pdb.set_trace()
plot_oob_error_depth(depths, oob_scores)
示例4: dense2sparse
# 需要导入模块: from sklearn.ensemble import RandomForestRegressor [as 别名]
# 或者: from sklearn.ensemble.RandomForestRegressor import fit_transform [as 别名]
dftrain_X, feature_names = dense2sparse(dftrain_Xdense)
dftest_X, feature_names = dense2sparse(dftest_Xdense)
# X is your feature space, Y is your target variable
dftrain_y = df1[df1.date <= date1]['FanDuelPts']
dftest_y = df1[df1.date > date1]['FanDuelPts']
#==============================================================================
# Predict last two weeks
#==============================================================================
from sklearn.ensemble import RandomForestRegressor
rf1 = RandomForestRegressor(verbose=True) # Parameters need to be tuned
rf1.fit_transform(dftrain_X,dftrain_y) # Train the model
rf1_preds = rf1.predict(dftest_X) # Predict against the test set
# Performance metrics
from sklearn.metrics import mean_absolute_error, mean_squared_error
mean_absolute_error(dftest_y,rf1_preds)
np.sqrt(mean_squared_error(dftest_y,rf1_preds))
# Plot model results
dfplot = pd.merge(dftest_y.to_frame('Actual'), pd.DataFrame(rf1_preds,
columns=['Pred']), left_index=True, right_index=True)
dfplot.plot()
import matplotlib.pyplot as plt
plt.plot(np.arange(1,len(rf1_preds),),rf1_preds)