Apriori算法實驗報告(共7頁)_第1頁
Apriori算法實驗報告(共7頁)_第2頁
Apriori算法實驗報告(共7頁)_第3頁
Apriori算法實驗報告(共7頁)_第4頁
Apriori算法實驗報告(共7頁)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、河北大學數學與計算機學院實 驗 報 告課程名稱 數據挖掘 實驗項目 編程實現(xiàn)Apriori算法 實驗儀器 VC+6.0 專 業(yè)_計算機軟件與理論_ 學 號 20101180 學生姓名 喬紅光 實驗日期 2011年4月9日 實驗地點 實驗室 成 績 指導教師 袁方 一、實驗目的1.加強對Apriori算法的理解;2.鍛煉分析問題、解決問題并動手實踐的能力;二、實驗內容編程實現(xiàn)Apriori算法;三、實驗要求 編程實現(xiàn)Apriori算法,加深對其理解。四、實驗準備1.看懂Apriori算法的基本思想;2.上網查閱相關資料。五、實驗過程主要代碼如下:void CAprioriView:Apriori

2、Gen(int nCandFreqItem, int nMinSupp)/由L(k-1)生成C(k)CString strTemp1,strTemp2,strRightTemp1,strRightTemp2;CString strTemp,strLeftTemp1,strLeftTemp2;int nstrTemp1,nstrTemp2; int nCandFreqItemCount=0;strTemp1=;strTemp2=;strRightTemp1=;strRightTemp2=;strTemp=;strLeftTemp1=; strLeftTemp2=;nstrTemp1=0;nstr

3、Temp2=0;nAllFreqItem=nAllFreqItem + LargeItemCountnCandFreqItem-1;for(int i1=0;i1LargeItemCountnCandFreqItem-1;i1+) strTemp1=LargeItemnCandFreqItem -1i1; nstrTemp1=strTemp1.ReverseFind(,);strRightTemp1=strTemp1.Right(strTemp1.GetLength ()-nstrTemp1-1); strLeftTemp1=strTemp1.Left(nstrTemp1);for(int j

4、1=i1+1;j1LargeItemCountnCandFreqItem-1;)/strTemp2=strCandFreqItemj1;strTemp2=LargeItemnCandFreqItem-1j1;nstrTemp2=strTemp2.ReverseFind (,);strRightTemp2=strTemp2.Right(strTemp2.GetLength ()-nstrTemp2-1);strLeftTemp2=strTemp2.Left(nstrTemp2) ;if(strLeftTemp1=strLeftTemp2)&(strRightTemp1strRightTemp2)

5、strTemp=strTemp1+,+strRightTemp2;if(Prune(nCandFreqItem,strTemp)CandLargeItemnCandFreqItemnCandFreqItemCount+=strTemp;j1+;elsej1+;else break;CandLargeItemCountnCandFreqItem=nCandFreqItemCount;void CAprioriView:SubItemGen(int strSubItemCount,CString strSubItem)/對每個事務分解成單個項目CString strTemp1;CString st

6、rTempSubItem10;CString strReverse;int nSubItemCount;int nstrRightTemp1;int nTempCount;strTemp1=strSubItem;nSubItemCount=0;while(nstrRightTemp1=strTemp1.ReverseFind(,)!=-1)nTempCount=strTemp1.GetLength() - nstrRightTemp1 - 1; strTempSubItemnSubItemCount+=strTemp1.Right( nTempCount);strTemp1=strTemp1.

7、Left(nstrRightTemp1); strTempSubItemnSubItemCount+=strTemp1;for(int i2=0;i2nSubItemCount/2;i2+)strReverse=strTempSubItemnSubItemCount-i2-1;strTempSubItemnSubItemCount- i2-1=strTempSubItemi2;strTempSubItemi2=strReverse; for(int i1=0;i1GetODBCFieldCount();int nCount=0;int nFreqItem100; int nDbCount=0;

8、CString strInit;CString strValue;CString strIntToString; / 初始化候選項目集 for(int nInitCount=0;nInitCountnItemCount;nInitCount+) strInit=;strInit.Format(%s%d,strInit,nInitCount+1); CandLargeItem0nInitCount=I+strInit;/初始化數組for(int ii=0;iiMoveFirst ();while(!m_pSet-IsEOF()for(int j=1;jGetFieldValue(j,strVal

9、ue); SubItemGen(nDbCount+ ,strValue);for(int i=0;iMoveNext();nDbItemCount=nDbCount; for(int i1=0;i1=dItemSupp) LargeItem0nCount=CandLargeItem0i1; m_List_FreqItem.InsertItem(nCount,strIntToString);m_List_FreqItem.SetItemText(nCount,0,LargeItem0nCount); strIntToString=;strIntToString.Format(%s%d,strIn

10、tToString,nFreqItemi1);m_List_FreqItem.SetItemText(nCount,1,strIntToString);nCount+;LargeItemCount0=nCount;BOOL CAprioriView:Prune(int nCandFreqItemCount,CString strCandFreqItem)CString strTemp1;CString strTempSubItemnMaxSize;CString strReverse;CString strSubCandFreqItemnMaxSize;/分解候選項目CString strSu

11、bTemp=;CString strSubTemp1;int nSubFreqItemCount=0;/統(tǒng)計分解候選項目的個數int nSubItemCount;int nstrRightTemp1;int nTempCount;int nPruneCount=0;strTemp1=strCandFreqItem;nSubItemCount=0;while(nstrRightTemp1=strTemp1.ReverseFind(,)!=-1)nTempCount=strTemp1.GetLength() - nstrRightTemp1 - 1; strTempSubItemnSubItemC

12、ount+=strTemp1.Right( nTempCount);strTemp1=strTemp1.Left(nstrRightTemp1); strTempSubItemnSubItemCount+=strTemp1;for(int i2=0;i2=0;i3-) strSubTemp1=strTempSubItemi3;strSubTemp.Empty(); for(int i4=0;i4nSubItemCount;i4+)if(strSubTemp1!=strTempSubItemi4) strSubTemp=strSubTemp+strTempSubItemi4+,;strSubCa

13、ndFreqItemnSubFreqItemCount+ = strSubTemp.Left(strSubTemp.GetLength()-1); for(int i5=0;i5nSubFreqItemCount;i5+) for(int i6=0;i6=0) nPruneCount+;if(nPruneCount=nSubItemCount)return TRUE;return FALSE;void CAprioriView:ShowFreqItem(int nScanCount)CString strIntToString=; CString strValue;CString strjj3

14、2;int nLargeCount=-1;int nLargeItemCount=0; /以下為求頻繁項目集int k,nListFreqItemCount;k=nScanCount; nListFreqItemCount=LargeItemCountk-1;m_List_FreqItem.InsertItem(0,strValue);m_List_FreqItem.SetItemText(0,0,-); m_List_FreqItem.SetItemText(0,1,-); for(int jj2=0;jj2=dItemSupp)LargeItemknLargeItemCount+=Cand

15、LargeItemkjj2;nLargeCount+;strjj31=strIntToString;strjj30=CandLargeItemkjj2;strIntToString=;strIntToString.Format(%s%d,strIntToString,nCountCandjj2); strjj31=strIntToString;m_List_FreqItem.InsertItem(nLargeCount,strValue);m_List_FreqItem.SetItemText(nLargeCount,0,LargeItemknLargeItemCount-1);m_List_FreqItem.SetItemText(nLargeCount,1,strIntToString);UpdateWindow(); /復制頻繁項目個數 LargeItemCountk=nLargeItemCount;運行結果圖如下:六、實驗總結

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論