プライマリ・コンテンツに移動
Oracle® R Enterpriseユーザーズ・ガイド
リリース1.5
E67082-02
目次へ移動
目次
索引へ移動
索引

前
前へ
次
次へ

4.2.2 相関ルール・モデルの構築

ore.odmAssocRules関数は、Aprioriアルゴリズムを実装することで、高頻度アイテム・セットを検索して相関モデルを生成します。これによって、マーケット・バスケット分析のような場合の大量のトランザクション・データにおいて、アイテムの同時発生が検出されます。相関ルールは、トランザクション・レコードで一連のアイテムが出現すれば、もう1つの一連のアイテムが存在するというデータのパターンを特定します。ルールの形成に使用されるアイテムのグループは、発生(ルールの支持度)する頻度および後件が前件(ルールの信頼度)に従う回数に応じて、最小しきい値を渡す必要があります。相関モデルは、ユーザー指定のしきい値よりも大きい支持度および信頼度を備えるすべてのルールを生成します。Aprioriアルゴリズムは効率的で、トランザクション数、アイテム数および生成されるアイテム・セットおよびルールの数が有効に測定されます。

formulaの仕様にはform ~ termsがあり、ここでtermsは分析に含まれる一連の列名です。複数の列名は列名の間に+を使用することで指定されます。~ .は、データのすべての列をモデル構築に使用する場合に使用します。列を除外するには、除外する各列名の前に-を使用します。関数は変換を確認するためにtermsの項目に適用できます。

ore.odmAssocRules関数は、次の形式のデータを受け入れます。

  • トランザクション・データ

  • アイテムIDおよびアイテム値を使用した複数レコードのケース・データ

  • リレーショナル・データ

データの形式の指定の例および関数の引数の詳細は、help(ore.odmAssocRules)を呼び出してください。

関数rulesは、クラスore.rules (一連の相関ルールを指定します)のオブジェクトを返します。ore.pullを使用して、ore.rulesオブジェクトをローカルのRセッションのメモリーにプルできます。ローカルのインメモリー・オブジェクトは、arulesパッケージで定義されているクラスrulesのものです。help(ore.rules)を参照してください。

関数itemsetsは、クラスore.itemsets (一連のアイテムセットを指定します)のオブジェクトを返します。ore.pullを使用して、ore.itemsetsオブジェクトをローカルのRセッションのメモリーにプルできます。ローカルのインメモリー・オブジェクトは、arulesパッケージで定義されているクラスitemsetsのものです。help(ore.itemsets)を参照してください。

例4-8 ore.odmAssocRules関数の使用方法

この例では、トランザクション・データセットに基づいて相関モデルを構築します。パッケージarulesおよびarulesVizは、生成されるルールおよびアイテムセットをクライアントのRセッションのメモリーにプルして表示するために必要です。このルールのグラフを図4-1に示します。

# Load the arules and arulesViz packages.
library(arules)
library(arulesViz)
# Create some transactional data.
id <- c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
item <- c("b", "d", "e", "a", "b", "c", "e", "b", "c", "d", "e")
# Push the data to the database as an ore.frame object.
transdata_of <- ore.push(data.frame(ID = id, ITEM = item))
# Build a model with specifications.
ar.mod1 <- ore.odmAssocRules(~., transdata_of, case.id.column = "ID",
             item.id.column = "ITEM", min.support = 0.6, min.confidence = 0.6,
             max.rule.length = 3)
# Generate itemsets and rules of the model.
itemsets <- itemsets(ar.mod1)
rules <- rules(ar.mod1)
# Convert the rules to the rules object in arules package.
rules.arules <- ore.pull(rules)
inspect(rules.arules)          
# Convert itemsets to the itemsets object in arules package.
itemsets.arules <- ore.pull(itemsets)
inspect(itemsets.arules)
# Plot the rules graph.
plot(rules.arules, method = "graph", interactive = TRUE)
例4-8のリスト
R> # Load the arules and arulesViz packages.
R> library(arules)
R> library(arulesViz)
R> # Create some transactional data.
R> id <- c(1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3)
R> item <- c("b", "d", "e", "a", "b", "c", "e", "b", "c", "d", "e")
R> # Push the data to the database as an ore.frame object.
R> transdata_of <- ore.push(data.frame(ID = id, ITEM = item))
R> # Build a model with specifications.
R> ar.mod1 <- ore.odmAssocRules(~., transdata_of, case.id.column = "ID",
+             item.id.column = "ITEM", min.support = 0.6, min.confidence = 0.6,
+             max.rule.length = 3)
R> # Generate itemsets and rules of the model.
R> itemsets <- itemsets(ar.mod1)
R> rules <- rules(ar.mod1)
R> # Convert the rules to the rules object in arules package.
R> rules.arules <- ore.pull(rules)
R> inspect(rules.arules)          
   lhs    rhs   support confidence lift
1  {b} => {e} 1.0000000  1.0000000    1
2  {e} => {b} 1.0000000  1.0000000    1
3  {c} => {e} 0.6666667  1.0000000    1
4  {d,                                 
    e} => {b} 0.6666667  1.0000000    1
5  {c,                                 
    e} => {b} 0.6666667  1.0000000    1
6  {b,                                 
    d} => {e} 0.6666667  1.0000000    1
7  {b,                                 
    c} => {e} 0.6666667  1.0000000    1
8  {d} => {b} 0.6666667  1.0000000    1
9  {d} => {e} 0.6666667  1.0000000    1
10 {c} => {b} 0.6666667  1.0000000    1
11 {b} => {d} 0.6666667  0.6666667    1
12 {b} => {c} 0.6666667  0.6666667    1
13 {e} => {d} 0.6666667  0.6666667    1
14 {e} => {c} 0.6666667  0.6666667    1
15 {b,                                 
    e} => {d} 0.6666667  0.6666667    1
16 {b,                                 
    e} => {c} 0.6666667  0.6666667    1
R> # Convert itemsets to the itemsets object in arules package.
R> itemsets.arules <- ore.pull(itemsets)
R> inspect(itemsets.arules)
   items   support
1  {b}   1.0000000
2  {e}   1.0000000
3  {b,            
    e}   1.0000000
4  {c}   0.6666667
5  {d}   0.6666667
6  {b,            
    c}   0.6666667
7  {b,            
    d}   0.6666667
8  {c,            
    e}   0.6666667
9  {d,            
    e}   0.6666667
10 {b,            
    c,            
    e}   0.6666667
11 {b,            
    d,            
    e}   0.6666667

R> # Plot the rules graph.
R> plot(rules.arules, method = "graph", interactive = TRUE)

図4-1 相関ルールの視覚的デモンストレーション

図4-1の説明が続きます
「図4-1 相関ルールの視覚的デモンストレーション」の説明