python - 如何使用 Orange 离散化存储在 numpy 数组中的数据?

标签 python python-3.x numpy orange

我有一组数据存储在“numpy”数组中:

array([['4.8', '3.0', '1.4', '0.3', 'Iris-setosa'],
['4.6', '3.2', '1.4', '0.2', 'Iris-setosa'],
['5.3', '3.7', '1.5', '0.2', 'Iris-setosa'],
['5.0', '3.3', '1.4', '0.2', 'Iris-setosa'],
['7.0', '3.2', '4.7', '1.4', 'Iris-versicolor'], dtype='<U15')
  • 这只是一个示例,我不仅在处理 iris 数据集。

我正在尝试使用 Orange离散化这些连续数据。

我知道我可以做这样的事情来完成工作:

import Orange
iris = Orange.data.Table("iris.tab")
disc = Orange.preprocess.Discretize()
disc.method = Orange.preprocess.discretize.EqualFreq(n=3)
d_iris = disc(iris)

然而,此方法仅适用于橙色数据表,不适用于 numpy 数组。

有没有办法使用 Orange 来离散化存储在 numpy 数组中的数据?

最佳答案

d_iris.X 已经是一个 numpy 数组,但您将丢失目标值和 header 。 d_iris.Y 是您可以与 X 合并的目标列。不过请记住,您只会在离散化后看到分配的 bin 值,这可能难以解释。

d_iris.X[:5]
array([[0., 3., 0., 0.],
    [0., 1., 0., 0.],
    [0., 2., 0., 0.],
    [0., 2., 0., 0.],
    [0., 3., 0., 0.]])

关于python - 如何使用 Orange 离散化存储在 numpy 数组中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52900064/

相关文章:

python - Django 模板 : Embed css from file

python-3.x - 如何确定for循环是异常退出还是从迭代器内部中断

python - 如何从 python 字典中返回特定信息?

python - 类型错误 : 'MapResult' object is not iterable using pathos. 多处理

python - 如何自动提取由与键关联的 numpy 数组表示的值作为字典中的单独数据

python - 对时间戳数组使用互相关有意义吗?

python - 包含 if 语句和 for 循环的单个语句

python - Tkinter Treeview 右键单击​​事件识别返回上一个右键单击行

python - 将列表转换为数据框时如何优化时间?

python - 从字符串中删除小写子字符串的快速方法?