本文整理汇总了Python中sklearn.ensemble.RandomForestClassifier.predicted_proba方法的典型用法代码示例。如果您正苦于以下问题:Python RandomForestClassifier.predicted_proba方法的具体用法?Python RandomForestClassifier.predicted_proba怎么用?Python RandomForestClassifier.predicted_proba使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.ensemble.RandomForestClassifier
的用法示例。
在下文中一共展示了RandomForestClassifier.predicted_proba方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_data
# 需要导入模块: from sklearn.ensemble import RandomForestClassifier [as 别名]
# 或者: from sklearn.ensemble.RandomForestClassifier import predicted_proba [as 别名]
def read_data(filename):
with open(filename) as f:
samples = []
target = []
for line in f:
line = line.strip().split()
target = int(line[0])
sample = [float(x) for x in line[1:]]
samples.append(sample)
return samples, target
def write_delimited_file(filename, data, labels):
with open(filename, "w") as f:
for line, label in zip(data, labels):
f.write(label + " ".join(line) + "\n")
if __name__ == '__main__':
homeDir = os.environ['HOME']
assert(homeDir is not None)
train, target = read_data(homeDir + "/out.cvs")
test, _ = read_data(homeDir + "/test")
rf = RandomForestClassifier(n_estimators=100, min_split=2)
rf.fit(train, target)
predicted_probs = rf.predicted_proba(test)
predicted_probs = ["%f" % x[1] for x in predicted_probs]
write_delimited_file("./result.cvs", predicted_probs)