小编Par*_*rat的帖子

在 Python 中使用 factorize() 后如何获取原始值?

我是一个初学者,尝试使用 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)
Run Code Online (Sandbox Code Playgroud)

我用于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)
Run Code Online (Sandbox Code Playgroud)

如何获得原始值而不是数字值?以下代码实际上是在比较实际值和预测值吗?

z,_= pd.factorize(test["AUDIT/BLOCK"])

z==clf.predict(test[features])
Out[296]: array([ True, False, False, ..., False, False, False], dtype=bool) 
Run Code Online (Sandbox Code Playgroud)

python prediction pandas random-forest

6
推荐指数
1
解决办法
2785
查看次数

标签 统计

pandas ×1

prediction ×1

python ×1

random-forest ×1