Ant*_*ico 2 algorithm regression r data-analysis decision-tree
我正在寻找一些算法或程序或函数来推断变量是如何创建的,只要我提供其他变量.我认为计算机程序员会称之为"反编译",而建筑师会将其称为"逆向工程",但我想我不知道统计学家会称它为什么......或者如果有可接受的方法可以做到这一点.
假设我在被叫中有一个分类列,我不确切知道它是如何构建的.但我确实知道用什么变量来创建它.或者至少我可以提供一组用于创建变量的详尽变量 - 即使并非所有变量都被使用.data.framenewvar
# start with an example data set
x <- mtcars
# # # # # # # # # # # # # # # # # # # # # # # #
# pretend this block of code is a black box
x <-
transform(
x ,
newvar =
ifelse( mpg > 24 , 1 ,
ifelse( cyl == 6 , 9 ,
ifelse( hp > 120 , 4 ,
ifelse( mpg > 22 , 7 , 2 ) ) ) )
)
# end of unknown block of code
# # # # # # # # # # # # # # # # # # # # # # # #
# now knowing that `mtcars` has only 11 columns to choose from
names(x)
# how were these 11 columns used to construct `newvar`?
table( x$newvar )
# here's a start..
y <- data.frame( ftable( x[ , c( 'mpg' , 'cyl' , 'hp' , 'newvar' ) ] ) )
# ..combinations with any records
y[y[,5]!=0,]
# but that's not enough to back-out the construction
Run Code Online (Sandbox Code Playgroud)
所以我认为你可以newvar通过线性回归或决策树来支持构造,但这仍然需要一些思考并将系数拼凑在一起以确定黑盒内发生了什么.
是否有任何可用的算法猜测黑盒子,可以这么说?谢谢!!
一般来说,没有.甚至应用了很多关于可能发生的事情的知识,它仍然(可能)没有.让我举例说明你的例子.添加输出为离散值的"黑匣子"的知识,并且基于其他值的阈值导出它们,分类树应该能够恢复标准.所以:
library("party")
tmp <- ctree(factor(newvar) ~ ., data=x,
controls=ctree_control(mincriterion=0, minsplit=2, minbucket=1))
Run Code Online (Sandbox Code Playgroud)
我将控制值设置为完全不合理的值,以强制算法驱动每个桶只包含一个值.即使这样,它也不是你开始的:

因此,通过一个简单的示例并添加有关转换的更多知识,它无法完成,在一般情况下无法真正希望能够做到这一点.