⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pp-weights.py

📁 orange源码 数据挖掘技术
💻 PY
字号:
# Description: Shows how to reweight the examples to modify the class distribution
# Category:    preprocessing, weighting
# Classes:     Preprocessor, Preprocessor_addClassWeight
# Uses:        lenses
# Referenced:  preprocessing.htm

import orange
data = orange.ExampleTable("lenses")
age, prescr, astigm, tears, y = data.domain.variables

pp = orange.Preprocessor_addClassWeight()
pp.classWeights = [2.0, 1.0, 1.0]
data2, weightID = pp(data)
# we add a meta attribute so that output is always the same
# (else, the meta id would depend upon the number of meta attributes
# constructed, which would trigger suspicions about randomness in testing scripts
data2.domain.addmeta(weightID, orange.FloatVariable("W"))

print "Assigning weight 2.0 to examples from the first class"
print "  - original class distribution: ", orange.Distribution(y, data2)
print "  - weighted class distribution: ", orange.Distribution(y, data2, weightID)

pp.classWeights = None
pp.equalize = 1
data2, weightID = pp(data)
data2.domain.addmeta(weightID, orange.FloatVariable("W"))

print "\nEqualizing class distribution"
print "  - original class distribution: ", orange.Distribution(y, data2)
print "  - weighted class distribution: ", orange.Distribution(y, data2, weightID)


pp.classWeights = [0.5, 0.25, 0.25]
pp.equalize = 1
data2, weightID = pp(data)
data2.domain.addmeta(weightID, orange.FloatVariable("W"))

print "\nEqualizing class distribution and weighting by [0.5, 0.25, 0.25]"
print "  - original class distribution: ", orange.Distribution(y, data2)
print "  - weighted class distribution: ", orange.Distribution(y, data2, weightID)

⌨️ 快捷键说明

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