#include "stdafx.h"
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <tchar.h>
using namespace std;
typedef vector<pair<vector<string>,int> > Items;
Items initdata();
bool Item_Exists(Items& item,vector<string>& arr);
void Item_Show(Items& item);
int Calculate_Count(Items& item,const vector<string>& arr);
Items Item_Generate(Items& item,int& k);
static double MINSUP = 0.3;
int _tmain(int argc, _TCHAR* argv[])
{
Items data = initdata();
Item_Show(data);
Items item;
Items::iterator iter;
for(iter = data.begin(); iter != data.end(); iter++)
{
for(int i = 0; i < iter->first.size(); i++)
{
vector<string> item_tmp;
item_tmp.push_back(iter->first[i]);
if(!Item_Exists(item,item_tmp))
{
int c = Calculate_Count(data,item_tmp);
if((double)c/data.size() >=MINSUP)
item.push_back(pair<vector<string>, int>(item_tmp, c));
}
}
}
Item_Show(item);
for (int k = 2;item.size() > 0; k++)
{
Items item2 = Item_Generate(item,k);
for (iter = item2.begin(); iter != item2.end(); iter++)
{
int c = Calculate_Count(data,iter->first);
iter->second = c;
}
Item_Show(item2);
item = item2;
}
cout<<endl;
return 0;
}
请各位高手帮帮忙看看Apriori C++代码 含义,帮忙注释一下
还有下面的函数也是,是接着问题的函数的~~Items initdata() \/\/数据集函数 { \/\/static string data[][5] = { \/\/ {"牛肉","鸡肉","牛奶"},\/\/ {"牛肉","奶酪"},\/\/ {"奶酪","靴子"},\/\/ {"牛肉","鸡肉","奶酪"},\/\/ {"牛肉","鸡肉","衣服","奶酪","牛...