algorithm - 从预测算法中获取两个目标值

标签 algorithm machine-learning target supervised-learning

我有一个包含序列元组和目标的数据集,如下所示:

       input_0  input_1 input_2 output
0        0       1.0    2.0      4.0
1        1       2.0    4.0      2.0
2        2       4.0    2.0      4.0
3        4       2.0    4.0      7.0
4        2       4.0    7.0      8.0

我使用输出作为目标值训练算法。

不过,我想要的是获得一个元组可能出现的两个最可能的变量。

例如,如果我有两个训练元组:a,b,c,da,b,c,e 我想得到 d e 作为各自百分比的结果。

有这样的可能吗?

最佳答案

根据您的评论,这似乎是一个 pandas.DataFrame。假设你开始于

from collections import Counter

df = pd.DataFrame({
    'input_0': [1, 1, 2, 4, 2], 
    'input_1': [1, 1, 2, 4, 4], 
    'input_2': [2, 2, 2, 4, 7],
    'output': [4, 3, 4, 7, 8]})
>>> df
    input_0 input_1 input_2 output
0   1   1   2   4
1   1   1   2   3
2   2   2   2   4
3   4   4   4   7
4   2   4   7   8

然后下面将显示每个输入元组的两个最常见的元素,以及它们的数量:

>>> df.output.groupby([df.input_0, df.input_1, df.input_2]).apply(lambda s: Counter(s).most_common(2)).reset_index()
    input_0 input_1 input_2 output
0   1   1   2   [(3, 1), (4, 1)]
1   2   2   2   [(4, 1)]
2   2   4   7   [(8, 1)]
3   4   4   4   [(7, 1)]

关于algorithm - 从预测算法中获取两个目标值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40284641/

相关文章:

machine-learning - DBSCAN 算法可以创建少于 minPts 的簇吗?

java - 当我们构建 java web 项目时会发生什么

arrays - 在两个排序数组中查找共同元素

C++ double 值在相乘时丢失精度?

python - 编码分类变量后如何跟踪列?

css - 仅在 CSS 中定位 WebKit 浏览器? (2019版)

ios - 不同目标的 Xcode 启动图像

python - 计算最多具有m个偶数元素的不同子数组的数量

C++算法计算多个数字的最小公倍数

machine-learning - PCA 使我的图像变得垃圾