




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優(yōu)質文檔-傾情為你奉上昆明理工大學信息工程與自動化學院學生實驗報告( 2011 2012 學年 第 1 學期 )課程名稱:人工智能 開課實驗室:信自樓計算機機房444 2011 年12月 16 日專業(yè)班級0學號200姓名成績實驗名稱天氣決策樹指導教師 教師評語該同學是否了解實驗原理: A.了解B.基本了解 C.不了解該同學的實驗能力:A.強 B.中等 C.差 該同學的實驗是否達到要求:A.達到B.基本達到 C.未達到實驗報告是否規(guī)范:A.規(guī)范B.基本規(guī)范 C.不規(guī)范實驗過程是否詳細記錄:A.詳細B.一般 C.沒有 教師簽名: 2011 年12 月 日一、上機目的及內容1.上機內容根據下列給
2、定的14個數據,運用Information Gain構造一個天氣決策樹。例子編號屬 性分類天況溫度濕度風況1晴熱大無N2晴熱大有N3多云熱大無P4雨中大無P5雨冷正常無P6雨冷正常有N7多云冷正常有P8晴中大無N9晴冷正常無P10雨中正常無P11晴中正常有P12多云中大有P13多云熱正常無P14雨中大有N2.上機目的(1)學習用Information Gain構造決策樹的方法;(2)在給定的例子上,構造出正確的決策樹;(3)理解并掌握構造決策樹的技術要點。二、實驗原理及基本技術路線圖(方框原理圖或程序流程圖)(1)設計并實現程序,構造出正確的決策樹;(2)對所設計的算法采用大O符號進行時間復雜
3、性和空間復雜性分析;主函數流程圖:Attributevalue.cpp流程圖Basefun流程圖:Datapiont.cpp流程圖:Dataset主要流程圖:三、所用儀器、材料(設備名稱、型號、規(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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國鎂錳電池市場規(guī)模分析及發(fā)展建議研究報告
- 2025-2030年中國辣椒制品行業(yè)運行動態(tài)與投資戰(zhàn)略研究報告
- 2025-2030年中國蒿甲醚行業(yè)市場現狀調研與前景規(guī)模預測報告
- 2025-2030年中國自動高壓蒸汽滅菌器市場發(fā)展狀況及前景趨勢分析報告
- 2025-2030年中國育發(fā)水市場發(fā)展狀況及投資規(guī)劃研究報告
- 2025安全員-C證考試題庫
- 2025-2030年中國糯玉米汁飲料市場發(fā)展預測及前景調研分析報告
- 2025-2030年中國粉針類頭孢制劑行業(yè)需求分析與十三五規(guī)劃研究報告
- 2025-2030年中國移動電源車產業(yè)運行動態(tài)及前景趨勢預測報告
- 2025-2030年中國石棉板行業(yè)運行態(tài)勢及投資戰(zhàn)略研究報告
- 2025年云南省昆明國家高新技術產業(yè)開發(fā)區(qū)招聘合同聘用制專業(yè)技術人員47人歷年高頻重點模擬試卷提升(共500題附帶答案詳解)
- 1.1青春的邀約 教學課件 2024-2025學年七年級道德與法治下冊(統(tǒng)編版2024)
- 2024年財政部會計法律法規(guī)答題活動題目及答案一
- 2024年01月廣州期貨交易所2024年招考筆試歷年參考題庫附帶答案詳解
- 中小學教師家訪記錄表內容(18張)8
- 《冠心病》課件(完整版)
- 2024年聊城職業(yè)技術學院高職單招(英語/數學/語文)筆試歷年參考題庫含答案解析
- 精品資料(2021-2022年收藏)垃圾焚燒發(fā)電廠監(jiān)理規(guī)劃
- 聲屏障工程施工組織設計方案
- 五年級美術下冊全冊教材分析
- 第五章:毒物泄漏及擴散模型-第四次
評論
0/150
提交評論