




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上昆明理工大學(xué)信息工程與自動化學(xué)院學(xué)生實(shí)驗報告( 2011 2012 學(xué)年 第 1 學(xué)期 )課程名稱:人工智能 開課實(shí)驗室:信自樓計算機(jī)機(jī)房444 2011 年12月 16 日專業(yè)班級0學(xué)號200姓名成績實(shí)驗名稱天氣決策樹指導(dǎo)教師 教師評語該同學(xué)是否了解實(shí)驗原理: A.了解B.基本了解 C.不了解該同學(xué)的實(shí)驗?zāi)芰Γ篈.強(qiáng) B.中等 C.差 該同學(xué)的實(shí)驗是否達(dá)到要求:A.達(dá)到B.基本達(dá)到 C.未達(dá)到實(shí)驗報告是否規(guī)范:A.規(guī)范B.基本規(guī)范 C.不規(guī)范實(shí)驗過程是否詳細(xì)記錄:A.詳細(xì)B.一般 C.沒有 教師簽名: 2011 年12 月 日一、上機(jī)目的及內(nèi)容1.上機(jī)內(nèi)容根據(jù)下列給
2、定的14個數(shù)據(jù),運(yùn)用Information Gain構(gòu)造一個天氣決策樹。例子編號屬 性分類天況溫度濕度風(fēng)況1晴熱大無N2晴熱大有N3多云熱大無P4雨中大無P5雨冷正常無P6雨冷正常有N7多云冷正常有P8晴中大無N9晴冷正常無P10雨中正常無P11晴中正常有P12多云中大有P13多云熱正常無P14雨中大有N2.上機(jī)目的(1)學(xué)習(xí)用Information Gain構(gòu)造決策樹的方法;(2)在給定的例子上,構(gòu)造出正確的決策樹;(3)理解并掌握構(gòu)造決策樹的技術(shù)要點(diǎn)。二、實(shí)驗原理及基本技術(shù)路線圖(方框原理圖或程序流程圖)(1)設(shè)計并實(shí)現(xiàn)程序,構(gòu)造出正確的決策樹;(2)對所設(shè)計的算法采用大O符號進(jìn)行時間復(fù)雜
3、性和空間復(fù)雜性分析;主函數(shù)流程圖:Attributevalue.cpp流程圖Basefun流程圖:Datapiont.cpp流程圖:Dataset主要流程圖:三、所用儀器、材料(設(shè)備名稱、型號、規(guī)格等或使用軟件)1臺PC及VISUAL C+6.0軟件4、 實(shí)驗方法、步驟(或:程序代碼或操作過程)工程源代碼:Main.cpp:#include #include #include #include #include #include #include AttributeValue.h#include DataPoint.h#include DataSet.hDataPoint processLin
4、e(std:string const& sLine)std:istringstream isLine(sLine, std:istringstream:in);std:vector attributes;/ TODO: need to handle beginning and ending empty spaces.while( isLine.good() )std:string rawfield;isLine rawfield;attributes.push_back( AttributeValue( rawfield ) );AttributeValue v = attributes.ba
5、ck();attributes.pop_back();bool type = v.GetType();return DataPoint(attributes, type);void main()std:ifstream ifs(in.txt, std:ifstream:in);DataSet initDataset;while( ifs.good() )/ TODO: need to handle empty lines.std:string sLine;std:getline(ifs, sLine);initDataset.addDataPoint( processLine(sLine) )
6、;std:list processQ;std:vector finishedDataSet;processQ.push_back(initDataset);while ( processQ.size() 0 )std:vector splittedDataSets;DataSet dataset = processQ.front();dataset.splitDataSet(splittedDataSets);processQ.pop_front();for (int i=0; isplittedDataSets.size(); +i)float prob = splittedDataSets
7、i.getPositiveProb();if (prob = 0.0 | prob = 1.0)finishedDataSet.push_back(splittedDataSetsi);elseprocessQ.push_back(splittedDataSetsi);std:cout The dicision tree is: std:endl;for (int i = 0; i finishedDataSet.size(); +i)finishedDataSeti.display();Attributevalue.cpp:#include AttributeValue.h#include
8、base.hAttributeValue:AttributeValue(std:string const& instring):m_value(instring)bool AttributeValue:GetType()if (m_value = P)return true;else if (m_value = N)return false;elsethrow DataErrException();Basefun.cpp:#include float log2 (float x)return 1.0 / log10(2) * log10(x);float calEntropy(float pr
9、ob)float sum=0; if (prob = 0 | prob = 1)return 0;sum -= prob * log2(prob);sum -= (1 - prob) * log2 ( 1 - prob );return sum;Datapiont.cpp:#include #include DataPoint.hDataPoint:DataPoint(std:vector const& attributes, bool type):m_type(type)for (int i=0; iattributes.size(); +i)m_attributes.push_back(
10、attributesi );void DataPoint:display()for (int i=0; im_attributes.size(); +i)std:cout t m_attributesi.getValue();if (true = m_type)std:cout tP;elsestd:cout tN;std:cout std:endl;Dataset.cpp:#include #include #include base.h#include DataSet.hvoid SplitAttributeValue:display()std:cout tSplit attribute
11、ID( m_attributeIndex )t;std:cout Split attribute value( m_v.getValue() ) std:endl;void DataSet:addDataPoint(DataPoint const& datapoint)m_data.push_back(datapoint);float DataSet:getPositiveProb()float nPositive = 0;for(int i=0; im_data.size(); +i)if ( m_datai.isPositive() )nPositive+;return nPositive
12、 / m_data.size();struct Statint nPos;int nNeg;int id;void DataSet:splitDataSet(std:vector& splittedSets)/ find all available splitting attributesint nAttributes = m_data0.getNAttributes();int i, j;std:vector splittingAttributeBV;splittingAttributeBV.resize(nAttributes);for (i=0; inAttributes; +i)spl
13、ittingAttributeBVi = true;for (i=0; im_splitAttributes.size(); +i)splittingAttributeBV m_splitAttributesi.getAttributeIndex() = false;std:vector splittingAttributeIds;for (i=0; inAttributes; +i)if (true = splittingAttributeBVi)splittingAttributeIds.push_back(i);typedef std:map AttributeValueStat;typ
14、edef std:map:iterator AttributeValueStat_iterator;typedef std:map:const_iterator AttributeValueStat_const_iterator;/ go through data once, and collect needed statistics to calculate entropystd:vector splittingStats;splittingStats.resize( splittingAttributeIds.size() );for (i=0; im_data.size(); +i)fo
15、r (j=0; jsplittingAttributeIds.size(); +j)AttributeValue const& v = m_datai.getAttribute(splittingAttributeIdsj);AttributeValueStat_iterator it = splittingStatsj.find(v);if ( splittingStatsj.end() = it )Stat stat;if ( m_datai.isPositive() )stat.nPos = 1;stat.nNeg = 0;stat.id = 0;elsestat.nPos = 0;st
16、at.nNeg = 1;stat.id = 0;splittingStatsj.insert(std:pair(v, stat);elseif ( m_datai.isPositive() )it-second.nPos+;elseit-second.nNeg+;/ display collected statisticsfor (j=0; jsplittingAttributeIds.size(); +j)std:cout Attribute( splittingAttributeIdsj ): std:endl;std:cout tValue t nPos t nNeg std:endl;
17、for (AttributeValueStat_const_iterator it = splittingStatsj.begin();it != splittingStatsj.end(); +it)std:cout t first.getValue() t second.nPos t second.nNeg std:endl;/ find splitting attributefloat minEntropy = 0.0;int splitAttributeId = -1;for (j=0; jsecond.nPos + it-second.nNeg;float p = it-second
18、.nPos;p /= nSamples;entropy += calEntropy(p) * nSamples / n;if (entropy minEntropy | -1 = splitAttributeId)minEntropy = entropy;splitAttributeId = j;std:cout Split at attribute( splittingAttributeIdssplitAttributeId ) std:endl second.id = k+;splittedSets.resize( k);for (i=0; ik; +i)for (j=0; jsecond.id.m_splitAttributes.push_back(SplitAttributeValue(itt-first, attrId);for (i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 智慧城市基礎(chǔ)設(shè)施維護(hù)與更新策略
- 智慧城市基礎(chǔ)設(shè)施的投資與運(yùn)營策略
- 從教育信息化看政策驅(qū)動的力量
- 跑腿服務(wù)如何助力教育資源的優(yōu)化配置
- 學(xué)生抗壓能力培養(yǎng)的教育心理學(xué)研究進(jìn)展
- 2024-2025學(xué)年度宜賓職業(yè)技術(shù)學(xué)院單招《職業(yè)適應(yīng)性測試》自我提分評估含答案詳解(滿分必刷)
- 2024年南通市經(jīng)濟(jì)技術(shù)開發(fā)區(qū)教育系統(tǒng)招聘教師筆試真題
- 哪里可以購買培訓(xùn)課件
- 山東省滕州市鮑溝中學(xué)2025-2026學(xué)年八年級下學(xué)期周周清(05.25)英語試題(無答案)
- 2023年度長沙航空職業(yè)技術(shù)學(xué)院單招《物理》真題附完整答案詳解【網(wǎng)校專用】
- 中醫(yī)診所負(fù)責(zé)人合作協(xié)議書范文
- 循環(huán)系統(tǒng)疾病智慧樹知到答案2024年哈爾濱醫(yī)科大學(xué)附屬第一醫(yī)院
- 2024-2030年中國激光水平儀行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略分析報告
- 疑難病例討論課件
- 部編本小學(xué)語文六年級下冊畢業(yè)總復(fù)習(xí)教案
- JB∕T 11864-2014 長期堵轉(zhuǎn)力矩電動機(jī)式電纜卷筒
- 小兒氨酚黃那敏顆粒的藥動學(xué)研究
- 生態(tài)環(huán)境行政處罰自由裁量基準(zhǔn)
- 長沙市開福區(qū)2024屆六年級下學(xué)期小升初數(shù)學(xué)試卷含解析
- 2024年安徽普通高中學(xué)業(yè)水平選擇性考試化學(xué)試題及答案
- DZ/T 0462.3-2023 礦產(chǎn)資源“三率”指標(biāo)要求 第3部分:鐵、錳、鉻、釩、鈦(正式版)
評論
0/150
提交評論