本文整理汇总了Python中sklearn.ensemble.RandomForestClassifier.pred方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.pred方法的具体用法?Python RandomForestClassifier.pred怎么用?Python RandomForestClassifier.pred使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.RandomForestClassifier
的用法示例。
在下文中一共展示了RandomForestClassifier.pred方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: rmsle
# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import pred [as 别名]
from sklearn.cross_validation import train_test_split
def rmsle(preds,actuals):
return np.sum((np.log(np.array(preds)+1) - np.log(np.array(actuals)+1))**2 / len(preds))
def load_data(path):
df = pd.read_csv(path, parse_dates='quote_date')
return df
def make_submission(clf, X_test, ids, encoder, name='rf_calibrated1.csv'):
y_prob = clf.predict_proba(X_test)
preds = pd.DataFrame(y_prob, index=ids, columns=encoder.classes_)
preds.to_csv(name, index_label='id', float_format='%.4f')
print("Wrote submission to file {}.".format(name))
train = load_data('train_set.csv')
test = load_data('test_set.csv')
X_train, X_val, y_train, y_val = train_test_split(X,y, test_size = 0.1)
# Train random forest classifier
rf_model = RandomForestClassifier(n_estimators=500, max_features=32)
rf_model.fit(X_train, y_train)
rf_model.pred = rf_model.predict(X_val)
score = log_loss(y_val, rf_model.pred)
print(score)
make_submission(sig_clf, X_test, ids, encoder)