




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上昆明理工大學(xué)信息工程與自動化學(xué)院學(xué)生實驗報告( 2011 2012 學(xué)年 第 1 學(xué)期 )課程名稱:人工智能 開課實驗室:信自樓計算機機房444 2011 年12月 16 日專業(yè)班級0學(xué)號200姓名成績實驗名稱天氣決策樹指導(dǎo)教師 教師評語該同學(xué)是否了解實驗原理: A.了解B.基本了解 C.不了解該同學(xué)的實驗?zāi)芰Γ篈.強 B.中等 C.差 該同學(xué)的實驗是否達(dá)到要求:A.達(dá)到B.基本達(dá)到 C.未達(dá)到實驗報告是否規(guī)范:A.規(guī)范B.基本規(guī)范 C.不規(guī)范實驗過程是否詳細(xì)記錄:A.詳細(xì)B.一般 C.沒有 教師簽名: 2011 年12 月 日一、上機目的及內(nèi)容1.上機內(nèi)容根據(jù)下列給
2、定的14個數(shù)據(jù),運用Information Gain構(gòu)造一個天氣決策樹。例子編號屬 性分類天況溫度濕度風(fēng)況1晴熱大無N2晴熱大有N3多云熱大無P4雨中大無P5雨冷正常無P6雨冷正常有N7多云冷正常有P8晴中大無N9晴冷正常無P10雨中正常無P11晴中正常有P12多云中大有P13多云熱正常無P14雨中大有N2.上機目的(1)學(xué)習(xí)用Information Gain構(gòu)造決策樹的方法;(2)在給定的例子上,構(gòu)造出正確的決策樹;(3)理解并掌握構(gòu)造決策樹的技術(shù)要點。二、實驗原理及基本技術(shù)路線圖(方框原理圖或程序流程圖)(1)設(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、 實驗方法、步驟(或:程序代碼或操作過程)工程源代碼: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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024-2025新入員工安全培訓(xùn)考試試題附參考答案【綜合卷】
- 2025工廠員工安全培訓(xùn)考試試題及答案
- 2025企業(yè)聘用離職人員合同范本
- 2025機密資料保密合同協(xié)議書
- 2025年網(wǎng)絡(luò)設(shè)備租賃合同
- 2025養(yǎng)殖合同書(家畜) 承包合同
- 2025兼職工作合同范本
- 2025分銷授權(quán)合同范本
- 2025年風(fēng)電電纜項目建議書
- 2025技術(shù)服務(wù)合同書模板
- 傳統(tǒng)園林技藝智慧樹知到期末考試答案2024年
- 直播中的禮儀與形象塑造
- 2024年八年級數(shù)學(xué)下冊期中檢測卷【含答案】
- 老年人中醫(yī)健康知識講座總結(jié)
- 海南聲茂羊和禽類半自動屠宰場項目環(huán)評報告
- 跳繩市場調(diào)研報告
- 《民法典》合同編通則及司法解釋培訓(xùn)課件
- 《大學(xué)生的情緒》課件
- 交通事故法律處理與索賠案例分析與實踐指導(dǎo)
- 2023年河北高中學(xué)業(yè)水平考試物理試卷真題及答案詳解
- 大學(xué)生組織管理能力大賽題庫第三屆
評論
0/150
提交評論