【发布时间】:2018-02-18 10:13:53
【问题描述】:
我是一名初学者,尝试使用 Python 中的随机森林创建预测模型,并使用训练和测试数据集。 train["ALLOW/BLOCK"] 可以取 4 个期望值中的 1 个(所有字符串)。 test["ALLOW/BLOCK"] 是需要预测的。
y,_ = pd.factorize(train["ALLOW/BLOCK"])
y
Out[293]: array([0, 1, 0, ..., 1, 0, 2], dtype=int64)
我使用predict 进行预测。
clf.predict(test[features])
clf.predict(test[features])[0:10]
Out[294]: array([0, 0, 0, 0, 0, 2, 2, 0, 0, 0], dtype=int64)
如何获取原始值而不是数字值?下面的代码实际上是在比较实际值和预测值吗?
z,_= pd.factorize(test["AUDIT/BLOCK"])
z==clf.predict(test[features])
Out[296]: array([ True, False, False, ..., False, False, False], dtype=bool)
【问题讨论】:
标签: python pandas random-forest prediction