Skip to content

Instantly share code, notes, and snippets.

@twinkfrag
Created January 7, 2015 15:06
Show Gist options
  • Save twinkfrag/aef9c11c966dcbf3eddb to your computer and use it in GitHub Desktop.
Save twinkfrag/aef9c11c966dcbf3eddb to your computer and use it in GitHub Desktop.
トランザクションの問題の確認用
using System;
using System.Linq;
using System.Collections.Generic;
using System.Console;
namespace twinkfrag.Transaction
{
class Transaction
{
public static void Main(string[] args)
{
List<string> item = new List<string>()
{
"A", "B", "C", "D", "E"
};
List<string> hoge = new List<string>()
{
"ABC",
"ABC",
"",
"",
"",
"",
"",
"",
"DE",
"DE",
};
foreach (var c1 in item)
{
foreach (var c2 in item.Where(x => x != c1))
{
var c1Contain = hoge.FindAll(x => x.Contains(c1)).Count;
var c12Contain = hoge.FindAll(x => x.Contains(c1) && x.Contains(c2)).Count;
if (c12Contain > 1)
{
if ((Double)c12Contain / c1Contain > 0.7) Write("> ");
WriteLine("{0} => {1}: {2}", c1, c2, (Double)c12Contain / c1Contain);
}
}
}
foreach (var c1 in item)
{
foreach (var c2 in item.Where(x => x != c1))
{
foreach (var c3 in item.Where(x => x != c1 && x != c2))
{
var c1Contain = hoge.FindAll(x => x.Contains(c1)).Count;
var c12Contain = hoge.FindAll(x => x.Contains(c1) && x.Contains(c2)).Count;
var c123Contain = hoge.FindAll(x => x.Contains(c1) && x.Contains(c2) && x.Contains(c3)).Count;
if (c123Contain > 1)
{
if ((Double)c123Contain / c12Contain > 0.7) Write("> ");
WriteLine("{0}, {1} => {2}: {3}", c1, c2, c3, (Double)c123Contain / c12Contain);
}
}
}
}
}
}
}
@twinkfrag
Copy link
Author

A, Bが両方入っているものには必ずCも入れる
Dが入っているものには必ずEも入れる
これを2レコードずつで支持度0.2,確信度1.0

あとは他の確信度がばらけるように適当に突っ込む.最後の2つみたいに{D, E}にそれぞれAとBとか入れるとA->DやD->Bなんかがばらけていい感じな気がする
(適当)

@sydosy
Copy link

sydosy commented Jan 20, 2017

TID アイテム集合
1 {A,B,C}
2 {A,B,C,E}
3 {D,E}
4 {A,D,E}
5 {B,E}
6 {A,C}
7 {B,C}
8 {A}
9 {B}
10 {C}

これでいい感じに命題満たせました()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment