我使用SPSS建模器来计算各种每周估计的准确性。我有一个数据表,其中有几周的估算和几周的实际数据点。目前,要计算每周的错误,我必须使用每周的派生节点:ex:wk1错误

问题描述 投票:0回答:2

<- (Wk1 estimate - Wk1 actual). This is naturally inefficient when considering many weeks. Is there a way to derive all of these error columns at once?

我不确定在普通建模器GUI中是否可以使用,因为您需要解析相应的字段名称并将其用作派生(多个)节点中的参数。 但是,您可以使用

模型脚本语言

。请参阅以下脚本,该脚本创建一个UserInput节点并用一些示例数据填充它,并根据WeekX列动态创建派生节点:

import modeler.api import re s = modeler.script.stream() # create user input node and fill with sample data input_node = s.create("userinput", "Userinput Node") input_node.setPropertyValue("names", ["group", "week1 (estimate)", "week2 (estimate)", "week3 (estimate)", "week1 (actual)", "week2 (actual)", "week3 (actual)"]) input_node.setKeyedPropertyValue("data", "group", '"A" "B" "C" "D"') input_node.setKeyedPropertyValue("data", "week1 (estimate)", '1 2 5 1') input_node.setKeyedPropertyValue("data", "week2 (estimate)", '2 3 1 4') input_node.setKeyedPropertyValue("data", "week3 (estimate)", '1 1 1 1') input_node.setKeyedPropertyValue("data", "week1 (actual)", '1 3 2 5') input_node.setKeyedPropertyValue("data", "week2 (actual)", '1 3 6 2') input_node.setKeyedPropertyValue("data", "week3 (actual)", '1 1 1 1') input_node.setKeyedPropertyValue("custom_storage", "group", "String") input_node.setKeyedPropertyValue("custom_storage", "week1 (estimate)", "Integer") input_node.setKeyedPropertyValue("custom_storage", "week2 (estimate)", "Integer") input_node.setKeyedPropertyValue("custom_storage", "week3 (estimate)", "Integer") input_node.setKeyedPropertyValue("custom_storage", "week1 (actual)", "Integer") input_node.setKeyedPropertyValue("custom_storage", "week2 (actual)", "Integer") input_node.setKeyedPropertyValue("custom_storage", "week3 (actual)", "Integer") input_node.setPropertyValue("data_mode", "Ordered") # alternatively (e.g. data from database, flatfile): find input node by id and read fieldlist #input_node = s.findByID("id1UTWII7ZNZF") #fieldlist = [] #for field in input_node.getOutputDataModel().iterator(): # fieldlist.append(field) # get fieldlist from input node fieldlist = input_node.getPropertyValue("names") print(fieldlist) # loop through field list and assemble dict weekdic = {} p = re.compile('[wW]eek.?[0-9]') for field in fieldlist: print(field) m = p.match(field) if m: try: weekdic[m.group()[len(m.group())-1]].append(field) except: weekdic[m.group()[len(m.group())-1]] = [field] derive = False # loop through dic and create derive node and set formula for i in weekdic: derive_temp = s.create("derive", "My node"+i) if derive: s.link(derive,derive_temp) derive = derive_temp else: derive = derive_temp s.link(input_node,derive) derive.setPropertyValue("new_name", "week" + i + " (error)") derive.setPropertyValue("result_type", "Formula") derive.setPropertyValue("formula_expr", "'" + weekdic[i][0] + "'" + ' - ' + "'" + weekdic[i][1] + "'") # link last derive node to outputtable tablenode = s.createAt("table", "Results", 288, 64) s.link(derive, tablenode) results = [] tablenode.run(results)

data-analysis spss spss-modeler
2个回答
0
投票
有多个派生节点进行单个操作,然后使用合并节点与原始列并排放置结果。在合并节点上,消除重复的列。


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.