1

決定列のない1つのデータテーブルを2番目のテーブルにコピーしてから、データをシャッフルしてそれら2つのテーブルを1つにマージしようとしています。エラーが発生するため、達成できません。私の意見では、オレンジ色のドキュメントは十分ではなく、それを達成する方法がわかりません。これが私のコードと私が得ているエラーです。誰かがそれを行う方法を知っているなら、私を助けてください。

db_name = "titanic"
data = Orange.data.Table(db_name)

new_domain = data

input_domain = new_domain.domain

all_vars = (list(input_domain.variables) +
            list(input_domain.class_vars) +
            input_domain.getmetas().values())

edited_vars = []

# Apply any saved transformations as listed in
# `domain_change_hints`
import OWEditDomain

for var in range(len(all_vars)-1):
    for x in range(len(all_vars[var].values)):
        all_vars[var].values[x] +='_1'

    all_vars[var].name += '_1'

    desc = OWEditDomain.variable_description(all_vars[var])

    try:
        new = OWEditDomain.variable_from_description(desc)
    except ValueError, ex:
        new = None

    if new is not None:
        # Make  sure orange's domain transformations will work.
        new.source_variable = all_vars[var]
        new.get_value_from =               Orange.core.ClassifierFromVar(whichVar=all_vars[var])
        all_vars[var] = new

    edited_vars.append(all_vars[var])

tabela = Orange.data.Table(new_domain, edited_vars)

tabela.shuffle()

data = Orange.data.Table(db_name)

merged = Orange.data.Table([data, tabela])
#
print "Domain 1: ", data.domain
print "Domain 2: ", tabela.domain
print "Merged:   ", merged.domain

エラー:

Traceback (most recent call last):
  File "C:/Python27/Lib/site-packages/Orange/OrangeWidgets/Classify/OWCN2.py", line 412, in <module>
    merged = Orange.data.Table([data, tabela])
orange.KernelException: 'orange.ExampleTable': mismatching value of attribute 'survived' in example #0
4

1 に答える 1

1

これを試して

def clone_var(var, namefmt="%s"):
    if isinstance(var, Orange.feature.Discrete):
        newvar = Orange.feature.Discrete(namefmt % var.name, values=var.values)
    elif isinstance(var, Orange.feature.Continuous):
        newvar = Orange.feature.Continuous(namefmt % var.name)
        newvar.number_of_decimals = var.number_of_decimals
        newvar.scientific_format = var.scientific_format
    elif isinstance(var, Orange.feature.String):
        newvar = Orange.feature.String(namefmt % var.name)
    else:
        raise TypeError
    newvar.attributes = dict(var.attributes)
    return newvar


def clone_table(table):
    features = [clone_var(var, "%s_1") for var in table.domain.features]
    if table.domain.class_var is not None:
        class_var = clone_var(table.domain.class_var, "%s_1")
    else:
        class_var = None
    class_vars = [clone_var(var, "%s_1") for var in table.domain.class_vars]
    domain = Orange.data.Domain(features, class_var, class_vars=class_vars)
    return Orange.data.Table(domain, table.native(2))

# copy of table without the class column
table_nocls = Orange.data.Table(Orange.data.Domain(table.domain.features, None), table)
# clone it, creating new variables, and shuffle
table_clone = clone_table(table_nocls)
table_clone.shuffle()

merged = Orange.data.Table([table, table_clone])
于 2015-04-01T08:50:17.417 に答える