我想在模型机学习的输出中获得两个以上的目标

发布于 2025-02-05 20:50:06 字数 170 浏览 1 评论 0原文

我想在用文本的分类模型预测中获得两个类。

model_RandomForest = RandomForestClassifier(n_estimators=100,criterion='gini', random_state=0) 

如果我可以添加数字输出的参数

I want to get two classes in the prediction of the classification model with text.

model_RandomForest = RandomForestClassifier(n_estimators=100,criterion='gini', random_state=0) 

if I can add a parameter of number output

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

属性 2025-02-12 20:50:06

如果您有多标签样本,则只需要将类标签定义为2D numpy数组即可。

示例:

from sklearn.ensemble import RandomForestClassifier
import numpy as np

np.random.seed(0)

X = np.random.rand(10,3)
y = np.random.rand(10,2)
y[y>0.7] = 1
y[y<=0.7] = 0

clf = RandomForestClassifier(max_depth=2, random_state=0)
clf.fit(X, y)

预测多级标签:

clf.predict(X[:5,:])

array([[0., 0.],
       [0., 0.],
       [0., 0.],
       [0., 0.],
       [1., 0.]])

sklearn中,这被称为多标签 - 辅助

'多标记 - 指示剂':y是标签指示器矩阵,一个两个数组
具有至少两个列的尺寸,最多有2个唯一值。

If you have multi-label samples, you just need to define the class labels as a 2d numpy array.

Example:

from sklearn.ensemble import RandomForestClassifier
import numpy as np

np.random.seed(0)

X = np.random.rand(10,3)
y = np.random.rand(10,2)
y[y>0.7] = 1
y[y<=0.7] = 0

clf = RandomForestClassifier(max_depth=2, random_state=0)
clf.fit(X, y)

Predict the multi-class labels:

clf.predict(X[:5,:])

array([[0., 0.],
       [0., 0.],
       [0., 0.],
       [0., 0.],
       [1., 0.]])

In sklearn, this is known as multilabel-indicator.

‘multilabel-indicator’: y is a label indicator matrix, an array of two
dimensions with at least two columns, and at most 2 unique values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文