




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、昆明理工大學信息工程與自動化學院學生實驗報告 (2011 2012 學年第1 學期) 課程名稱:人工智能開課實驗室:信自樓計算機機房444 2011 年12月16日 專業班級 0 學號 200 姓名 成績 實驗名稱 天氣決策樹 指導教師 教該同學是否了解實驗原理: A. 了解口 B.基本了解口 C.不了解 師該同學的實驗能力: A.強 B.中等 C.差 該同學的實驗是否達到要求:A.達到口 B.基本達到口 C.未達到 評 實驗報告是否規范: A.規范口 B.基本規范口 C.不規范 語實驗過程是否詳細記錄: A.詳細口 B. 一般 C.沒有口 教師簽名: 2011 年12月 日 、上機目的及內容
2、 1. 上機內容 根據下列給定的14個數據,運用In formation Ga in構造一個天氣決策樹 例子編號 屬 性 分類 天況 溫度 濕度 風況 1 晴 熱 大 無 N 2 晴 熱 大 有 N 3 多云 熱 大 無 P 4 雨 中 大 無 P 5 雨 冷 正常 無 P 6 雨 冷 正常 有 N 7 多云 冷 正常 有 P 8 晴 中 大 無 N 1 9 晴 冷 正常 無 P 10 雨 中 正常 無 P 11 晴 中 正常 有 P亍 12 多云 中 大 有 P 13 多云 熱 正常 無 P 14 雨 中 大 有 N 2. 上機目的 (1) 學習用In formation Ga in 構造決
3、策樹的方法; (2) 在給定的例子上,構造出正確的決策樹; (3) 理解并掌握構造決策樹的技術要點。 、實驗原理及基本技術路線圖(方框原理圖或程序流程圖) (1) 設計并實現程序,構造出正確的決策樹; (2) 對所設計的算法采用大 0符號進行時間復雜性和空間復雜性分析; 主函數流程圖: srd: stringsLine; Multiplex I Maltipkx Attributevalue.cpp 流程圖 9 Basefun流程圖: L noaisucn-O. rewind. sum*-prcb*lo rtf-tLirbUcn: Datapi on t.cpp流程圖: 三、所用儀器、材料(設
4、備名稱、型號、規格等或使用軟件) 1 臺 PC及 VISUAL C+6.0 軟件 四、實驗方法、步驟(或:程序代碼或操作過程) 工程源代碼: Mai n.cpp: #in elude #i nclude #i nclude #i nclude #in elude #in elude #i nclude AttributeValue.h #i nclude DataPoi nt.h #i nclude DataSet.h DataPo int processL in e(std:stri ng const std:vector attributes; / TODO: n eed to han d
5、le begi nning and ending empty spaces. while( isL in e.good() std:stri ng rawfield; isLi ne rawfield; attributes.push_back( AttributeValue( rawfield ); AttributeValue v = attributes.back(); attributes.pop_back(); bool type = v.GetType(); return DataPoi nt(attributes, type); void mai n() std:ifstream
6、 ifs(i n.txt, std:ifstream:i n); DataSet in itDataset; while( ifs.good() / TODO: n eed to han dle empty lin es. std:stri ng sLine; std:getli ne(ifs, sLin e); in itDataset.addDataPoi nt( processL in e(sL ine); std:list processQ; std:vector fini shedDataSet; processQ.push_back(i nitDataset); while ( p
7、rocessQ.size() 0 ) std:vector splittedDataSets; DataSet dataset = processQ.fr on t(); dataset.splitDataSet(splittedDataSets); processQ.pop_fro nt(); for (i nt i=0; isplittedDataSets.size(); +i) float prob = splittedDataSetsi.getPositiveProb(); if (prob = 0.0 | prob = 1.0) fin ishedDataSet.push_back(
8、splittedDataSetsi); else processQ.push_back(splittedDataSetsi); std:cout The dicisi on tree is: std:e ndl; for (i nt i = 0; i fini shedDataSet.size(); +i) fin ishedDataSeti.display(); Attributevalue.cpp : #i nclude AttributeValue.h #in clude base.h AttributeValue:AttributeValue(std:stri ng const els
9、e if (m_value = N) return false; else throw DataErrExceptio n(); Basef un. cpp: #in clude float log2 (float x) return 1.0 / Iog10(2) * Iog10(x); float calE ntropy(float prob) float sum=0; if (prob = 0 | prob = 1) return 0; sum -= prob * Iog2(prob); sum -= (1 - prob) * Iog2 ( 1 - prob ); return sum;
10、Datapi on t.cpp: #in elude #i nclude DataPoi nt.h DataPo in t:DataPo in t(std:vector const iattributes.size(); +i) m_attributes.push_back( attributesi); void DataPo in t:display() for (int i=0; im_attributes.size(); +i) std:cout t m_attributesi.getValue(); if (true = m_type) std:cout tP; else std:co
11、ut tN; std:cout std:e ndl; Dataset.cpp: #in elude #in elude #in elude base.h #in elude DataSet.h void SplitAttributeValue:display() std:cout tSplit attribute ID( m_attribute In dex )t; std:cout Split attribute value( m_v.getValue() ) std:e ndl; void DataSet:addDataPo in t(DataPo int const float Data
12、Set:getPositiveProb() float n Positive = 0; for(i nt i=0; im_data.size(); +i) if ( m_datai.isPositive() n Positive+; return n Positive / m_data.size(); struct Stat int n Pos; int nN eg; int id; void DataSet:splitDataSet(std:vector int i, j; std:vector splitt in gAttributeBV; splitt in gAttributeBV.r
13、esize( nAttributes); for (i=0; in Attributes; +i) splitti ngAttributeBVi = true; for (i=0; im_splitAttributes.size(); +i) splitt in gAttributeBV m_splitAttributesi.getAttributel ndex() = false; std:vect or splitt in gAttributeIds; for (i=0; in Attributes; +i) if (true = splitt in gAttributeBVi) spli
14、tt in gAttributelds.push_back(i); typedef std:map AttributeValueStat; typedefstd:map:iterator AttributeValueStat_iterator; typedef std:map:c on st_iterator AttributeValueStat_c on st_iterator; / go through data on ce, and collect n eeded statistics to calculate en tropy std:vector splitt in gStats;
15、splitti ngStats.resize( splitt in gAttributeIds.size(); for (i=0; im_data.size(); +i) for (j=0; jsplitti ngAttributelds.size(); +j) AttributeValueconst AttributeValueStat_iterator it = splitti ngStatsj.fi nd(v); if ( splitt in gStatsj.e nd() = it ) Stat stat; if ( m_datai.isPositive() stat. nPos = 1
16、; stat .nNeg = 0; stat.id = 0; else stat. nPos = 0; stat .nNeg = 1; stat.id = 0; splitt in gStatsj.i nsert(std:pair(v, stat); else if ( m_datai.isPositive() it-sec ond.n Pos+; else it-sec ond.nN eg+; / display collected statistics for (j=0; jsplitt in gAttributelds.size(); +j) std:cout Attribute spl
17、itt in gAttributeIdsj ): std:e ndl; std:cout tValue t nPos t nN eg std:e ndl; for (AttributeValueStat_c on st_iterator it = splitt in gStatsj.begi n(); it != splitti ngStatsj.e nd(); +it) std:cout t first.getValue() t sec ond.n Pos t sec ond.nNeg std:e ndl; / find splitt ing attribute float minEn tr
18、opy = 0.0; int splitAttributeld = -1; for (j=0; jsec ond.n Pos + it-sec ond.nN eg; float p = it-sec ond.n Pos; p /= n Samples; en tropy += calE ntropy(p) * n Samples / n; if (en tropy minEn tropy | -1 = splitAttributeld) minEn tropy = en tropy; splitAttributeld = j; ) std:cout Split at attribute( sp
19、littingAttributeldssplitAttributeld std:e ndl sec on d.id = k+; splittedSets.resize( k); for (i=0; ik; +i) for (j=0; jseco nd.id.m_splitAttributes.push_back(SplitAttributeValue(itt -first, attrld); for (i=0; iseco nd.id.addDataPoi nt(m_datai); else throw DataErrExcepti on(); void DataSet:display() i
20、nt i; std:cout Dataset( this ) std:e ndl; for (i=0; im_splitAttributes.size(); +i) m_splitAttributesi.display(); std:cout Data: std:e ndl; for (i=0; im_data.size(); +i) m_datai.display(); std:cout std:e ndl; 五、實驗過程原始記錄(測試數據、圖表、計算等) 18 nPos 1 0 Ualue nPos 1 at attribute2) Ualue 正常 nPos 0 2 ttrihute f
21、littribiite C0 : ittribute: ittrUbute (2): ValuenPg ttribute(3 : plit at nNeg 0 3 S1熱中W UaluenPos 多云4 晴2 雨3 UaluenPos 冷3 熱2 申4 歪常I UaluenPgs 無6 有3 nNef 1 2 2 nNe$f 4 1 nNeg 2 3 nNeg 0 2 1 nNejf 3 fi nNejf 2 1 ttribute: Ualue 冷 中 ttribate: Value 壹常 七tribute : Ualue 無 有 nPos 1 2 nHest 1 1 nPos 1 nNej 1 1 nPos 3 0 plit at attj*ibute nNeg 0 2 he die ision tree is: ataset Split attribute ata: 多云 ID Split attribute valuieataset Split attribute Sp
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 基礎研究與應用研究和綜合研究的區別
- 數學中解決問題的策略有哪些
- 心理健康指導師報考官網
- 護理科研課題設計與實現
- 老齡化背景下社區公園微更新策略與實踐研究
- 廢棄動物骨基復合材料固化風積沙的抗風蝕性能優化研究
- 小學語文習作教學案例分析與理論研究
- 智能垃圾分類系統的開發與應用研究
- 體育教師教學評語
- 會議旅游策劃書
- 隱龍山墓園規劃方案
- 礦燈管理工培訓課件
- 村醫培訓死因監測課件
- 玻璃幕墻清洗施工方案
- 管理授權手冊7.28
- lcd制造工藝流程
- 2024屆北京市石景山區七年級生物第二學期期末學業水平測試模擬試題含解析
- 《數據中心液冷系統技術規程》
- 人教版八年級日語單詞表
- 建筑施工安全管理及揚塵治理檢查投標方案(技術方案)
- 醫院耗材SPD解決方案(技術方案)
評論
0/150
提交評論