规则:从规则中提取lhs项 [英] R arules : Extract lhs items from rules

查看:109
本文介绍了规则:从规则中提取lhs项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从规则生成的规则中提取lhs个项目.

I want to extract lhs items from a rule generated from arules.

例如,

{a,b,c} => {d}

我希望能够提取a,b,c并将其放入字符向量中,因此我可以基于这些项目进行迭代并进行进一步处理.

I want to be able to extract a,b,c and put it in a character vector, so I can iterate and do further processing based on these items.

目前,我可以考虑解析规则集,将其转换为数据框,然后使用字符操作/正则表达式将这些项目分开.我希望有更好的方法来提取这些项目.

At the moment, I can think of parsing the set of rules, converting it to a data frame and then separate these items using character manipulation/regex. I hope there's better way of extracting these items.

推荐答案

只需将LHS和/或RHS强制列出:

Just coerce the LHS and/or the RHS into a list:

data("Adult")
rules <- apriori(Adult, 
   parameter = list(supp = 0.5, conf = 0.9, target = "rules"))

as(lhs(rules), "list")
as(rhs(rules), "list")

这篇关于规则:从规则中提取lhs项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆