example2.py

来自「orange源码 数据挖掘技术」· Python 代码 · 共 39 行

PY
39 行
字号
# Description: Shows how to use meta-attributes with orange.Example
# Category:    basic classes, meta-attributes
# Classes:     Example
# Uses:        lenses
# Referenced:  Example.htm

import orange, random

random.seed(0)

data = orange.ExampleTable("lenses")

id = -42
# Note that this is wrong. Id should be assigned by
# id = orange.newmetaid()
# We only do this so that the script gives the same output each time it's run

for example in data:
    example[id] = orange.Value(random.random())

print data[0]

print orange.getClassDistribution(data)
print orange.getClassDistribution(data, id)

w = orange.FloatVariable("w")
data.domain.addmeta(id, w)

print data[0]

print data[0][id]
print data[0][w]
print data[0]["w"]

data[0][id] = orange.Value(w, 2.0)
data[0][id] = "2.0"
data[0][id] = 2.0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?