91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

數據挖掘中的經典關聯規則算法,網上找了很多,不是不能運行,就是只能處理英文字母或數字,就花了幾天時間自己寫了個c++程序,用于處理字符串頻繁項的挖掘。在c-free4.0和visual studio 2008上都能運行。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include

using?namespace?std;

typedef?struct?Item//只有一個詞的頻繁項
{
string?sItem;
int?iSupport;
}ITEM;

typedef?vector?VEC_STR;
typedef?vector?VEC_VEC_STR;

typedef?struct?MultiItem//高層的頻繁項
{
VEC_STR?vsItem;
int?iSupport;
}MULTIITEM;

typedef?vector?VEC_ITEM;//只有一個詞的頻繁項集合
typedef?vector?VEC_MULTIITEM;//高層的頻繁項集合
typedef?map?MAP_STR_INT;//存儲詞語及其出現頻率

void?readFile(ifstream?&?const?string?&?VEC_STR?&);
void?countWord(VEC_STR?*?MAP_STR_INT?&?const?char?separator=‘\\‘);
void?generateLevel1Set(MAP_STR_INT?*?VEC_ITEM?&);
void?generateLevel2(VEC_ITEM?*?VEC_MULTIITEM?&);
void?cycGenerator(VEC_MULTIITEM?*?VEC_STR?&?ofstream?&);
void?generateHighLevelSet(VEC_MULTIITEM?*?VEC_MULTIITEM?&?VEC_STR?&);
void?generateInitialHigh(VEC_MULTIITEM?*?VEC_VEC_STR?&);
void?pruning(VEC_VEC_STR?*?VEC_MULTIITEM?*?VEC_MULTIITEM?&);
bool?find(VEC_MULTIITEM?*?VEC_STR?*);
void?countSupport(VEC_STR?*?VEC_MULTIITEM?&);
void?generateFrequentSet(VEC_MULTIITEM?*?VEC_MULTIITEM?&);
void?printFrequentSet(VEC_ITEM?*?ostream?&os=cout);
void?printFrequentSet(VEC_MULTIITEM?*?ostream?&os=cout);

const?int?MINSUPPORT?=?2;//最小支持度

int?main()
{
//從源文件讀取數據
ifstream?infile;
VEC_STR?vs_word;
readFile(infile“in.txt“vs_word);
infile.close();

//計算所有詞語的出現頻率
MAP_STR_INT?word_count;
countWord(&vs_word?word_count);

//生成單個詞語的頻繁項集合
VEC_ITEM?level1Set;
generateLevel1Set(&word_count?level1Set);

//生成具有兩個詞語的頻繁項集合
VEC_MULTIITEM?level2?level2Set;
generateLevel2(&level1Set?level2);
countSupport(&vs_word?level2);
generateFrequentSet(&level2?level2Set);

//生成具有三個詞語的頻繁項集合
VEC_MULTIITEM?level3Set;
generateHighLevelSet(&level2Set?level3Set?vs_word);

//輸出單個詞的頻繁項到文件
ofstream?outfile;
outfile.open(“out.txt“);
if(!outfile)
cout<<“Unable?to?open?this?file!“< printFrequentSet(&level1Set?outfile);

//循環產生高層的頻繁項集合并輸出到文件
cycGenerator(&level2Set?vs_word?outfile);

cout<<“OK!“< return?0;
}

/**從源文件讀取詞語
*每一行作為一個字符串存入向量中
*/
void?readFile(ifstream?&infile?const?string?&filename?VEC_STR?&vs_word)
{
infile.close();
infile.clear();

infile.open(filename.c_str());?
if(!infile)
cout<<“Unable?to?open?this?file!“<
string?word;
while(getline(infile?word))
vs_word.push_back(word);
}

/**計算每個詞語的支持度
*從字符串中提取出所有詞語,與其支持度一道存入map中
*/
void?countWord(VEC_STR?*vs_word?MAP_STR_INT?&word_count?const?char?separator)
{
string?sentenceword;
for(unsigned?int?i=0;?isize();?++i)
{
sentence?=?(*vs_word)[i];
while(sentence.find(separator)!=-1)
{
word?=?sentence.substr(0sentence.find(separator));
++word_count[word];
sentence?=?sentence.substr(sentence.find(separator)+1?sentence.size()-1);
}
++word_count[sentence];
}
}

/**找出頻繁1項集的集合
*/
void?generateLevel1Set(MAP_STR_INT?*pWord_Co

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????8080??2008-11-06?23:13??Apriori.cpp

?????文件????????295??2008-11-05?16:19??in.txt

-----------?---------??----------?-----??----

?????????????????8375????????????????????2


評論

共有 條評論