domain6.py

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

PY
29
字号
# Description: Shows how to use Filter_sameValues for instance selection
# Category:    preprocessing
# Uses:        imports-85
# Classes:     
# Referenced:  domain.htm

import orange

def report_prob(header, data):
  print 'Size of %s: %i instances; ' % (header, len(data)), 
  n = 0
  for i in data:
    if int(i.getclass())==0:
      n = n + 1
  if len(data):
    print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data))
  else:
    print

filename = "../datasets/adult_sample.tab"
data = orange.ExampleTable(filename)
report_prob('data', data)

data1 = data.select(age=(30,40))
report_prob('data1, age from 30 to 40', data1)

data2 = data.select(age=(40,30))
report_prob('data2, younger than 30 or older than 40', data2)

⌨️ 快捷键说明

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