1.勤洗手、勤洗頭,勤換衣,勤洗澡;
2.勤理發(fā)、勤刷牙,勤剪指甲勤問好;
3.吐痰要用紙包好,莫往地上直接飄;
4.上完廁所要沖水,廢物扔進(jìn)垃圾桶;
講衛(wèi)生的順口溜 勤洗手、勤洗頭,勤換衣,勤洗澡; 勤理發(fā)、勤刷牙,勤剪指甲勤問好; 吐痰要用紙包好,莫往地上直接飄; 上完廁所要沖水,廢物扔進(jìn)垃圾桶; 輕聲細(xì)語要習(xí)慣,安靜地方不要吵; 愛清潔、講文明,一身無病少煩惱。
你有性病與衛(wèi)生統(tǒng)計(jì)學(xué) ,代碼是100401
中國衛(wèi)生統(tǒng)計(jì)分析報(bào)告旨在全面評估中國衛(wèi)生系統(tǒng)的發(fā)展現(xiàn)狀,深入剖析衛(wèi)生領(lǐng)域的數(shù)據(jù)和趨勢,為相關(guān)政策制定和決策提供參考依據(jù)。通過對衛(wèi)生統(tǒng)計(jì)數(shù)據(jù)的搜集、整理和分析,可以揭示出衛(wèi)生服務(wù)的覆蓋范圍、質(zhì)量水平、資源配置情況等關(guān)鍵指標(biāo),為提升中國衛(wèi)生事業(yè)水平和可持續(xù)發(fā)展提供重要支撐。
根據(jù)中國衛(wèi)生統(tǒng)計(jì)分析報(bào)告的數(shù)據(jù)顯示,中國衛(wèi)生服務(wù)覆蓋范圍逐漸擴(kuò)大,城鄉(xiāng)居民的衛(wèi)生保障水平有所提高。然而,仍存在著城鄉(xiāng)差距和區(qū)域不平衡的現(xiàn)象,特別是基層衛(wèi)生服務(wù)的覆蓋面仍然有待加強(qiáng)。
衛(wèi)生服務(wù)質(zhì)量是衡量衛(wèi)生系統(tǒng)績效的重要指標(biāo)之一。中國衛(wèi)生統(tǒng)計(jì)分析報(bào)告通過評估醫(yī)療技術(shù)水平、服務(wù)態(tài)度、醫(yī)患關(guān)系等多維度指標(biāo),發(fā)現(xiàn)了一些存在的問題和改進(jìn)建議,為優(yōu)化衛(wèi)生服務(wù)提供了實(shí)用建議。
衛(wèi)生資源的合理配置是保障衛(wèi)生服務(wù)可持續(xù)發(fā)展的關(guān)鍵。中國衛(wèi)生統(tǒng)計(jì)分析報(bào)告揭示了衛(wèi)生資源在不同地區(qū)、不同醫(yī)療機(jī)構(gòu)之間的分布差異,為政府部門和衛(wèi)生機(jī)構(gòu)提供了科學(xué)的依據(jù),以實(shí)現(xiàn)資源的優(yōu)化配置。
通過對中國衛(wèi)生統(tǒng)計(jì)數(shù)據(jù)的分析,可以預(yù)測未來衛(wèi)生服務(wù)的需求趨勢,為衛(wèi)生規(guī)劃和政策制定提供重要參考。結(jié)合人口老齡化、疾病譜變化等因素,可以更加科學(xué)地調(diào)整衛(wèi)生服務(wù)布局,滿足人民群眾日益增長的健康需求。
中國衛(wèi)生統(tǒng)計(jì)分析報(bào)告是中國衛(wèi)生事業(yè)發(fā)展的重要支撐,其數(shù)據(jù)和分析為政府和衛(wèi)生機(jī)構(gòu)提供了寶貴的參考信息。通過持續(xù)的統(tǒng)計(jì)分析工作,可以更好地了解中國衛(wèi)生系統(tǒng)的發(fā)展?fàn)顩r,推動(dòng)衛(wèi)生事業(yè)的持續(xù)改善和發(fā)展。
衛(wèi)生統(tǒng)計(jì)學(xué)是以醫(yī)學(xué),特別是預(yù)防醫(yī)學(xué)的理論為指導(dǎo),用統(tǒng)計(jì)學(xué)原理和方法研究醫(yī)學(xué),側(cè)重預(yù)防醫(yī)學(xué)中數(shù)據(jù)的搜集、整理與分析的一門應(yīng)用性學(xué)科,它是公共衛(wèi)生工作者必不可少的工具。在學(xué)習(xí)本課程時(shí),應(yīng)注意掌握衛(wèi)生統(tǒng)計(jì)學(xué)的基本理論、基本知識(shí)、基本方法及基本技能,掌握調(diào)查設(shè)計(jì)及實(shí)驗(yàn)設(shè)計(jì)的原則與內(nèi)容,掌握醫(yī)學(xué)人口統(tǒng)計(jì)、疾病統(tǒng)計(jì)等常用統(tǒng)計(jì)指標(biāo),并用之評價(jià)人群健康狀況,為衛(wèi)生決策提供統(tǒng)計(jì)信息。
課程大綱
第一章 緒論
第二章 定量資料的統(tǒng)計(jì)描述
第三章 定性資料的統(tǒng)計(jì)描述
第四章 常用概率分布
第五章 參數(shù)估計(jì)基礎(chǔ)
第六章 假設(shè)檢驗(yàn)基礎(chǔ)
第七章 χ2 檢驗(yàn)
第八章 實(shí)驗(yàn)設(shè)計(jì)
第九章 方差分析
第十章 基于秩次的非參數(shù)檢驗(yàn)
第十一章 兩變量關(guān)聯(lián)性分析
第十二章 簡單回歸分析
第十三章 多重線性回歸與相關(guān)
第十四章 調(diào)查設(shè)計(jì)
第十五章 總體特征抽樣調(diào)查的設(shè)計(jì)與分析
第十六章 橫斷面研究資料的統(tǒng)計(jì)分析
第十七章 隊(duì)列研究的設(shè)計(jì)與分析
第十八章 病例對照研究的設(shè)計(jì)與分析
第十九章 Logistic回歸
第二十章 生存分析
第二十一章 綜合評價(jià)
第二十二章 Meta分析
流行病和衛(wèi)生統(tǒng)計(jì)學(xué)是醫(yī)學(xué)科學(xué)重要的基礎(chǔ)學(xué)科和方法學(xué)科。隨著越來越多的流行病學(xué)的數(shù)據(jù)分析需要更多統(tǒng)計(jì)學(xué)知識(shí),流行病學(xué)和統(tǒng)計(jì)學(xué)的結(jié)合越來越重要,在這個(gè)大的背景下,中國人民大學(xué)流行病與公共衛(wèi)生統(tǒng)計(jì)專業(yè)誕生于2006年,所以流行病和衛(wèi)生統(tǒng)計(jì)學(xué)是一個(gè)非常年輕的學(xué)科。
衛(wèi)生統(tǒng)計(jì)學(xué)試題是醫(yī)學(xué)生和衛(wèi)生專業(yè)學(xué)生備考的一道難題。在衛(wèi)生統(tǒng)計(jì)學(xué)這門學(xué)科中,試題形式多種多樣。其中,問答題尤為重要,既考察了學(xué)生對衛(wèi)生統(tǒng)計(jì)學(xué)理論的理解,也考察了學(xué)生獨(dú)立思考和分析問題的能力。本文將提供一些常見的衛(wèi)生統(tǒng)計(jì)學(xué)試題問答題以供大家學(xué)習(xí)和參考。
衛(wèi)生統(tǒng)計(jì)學(xué)是研究人群健康狀況及其與環(huán)境、生活方式等因素之間關(guān)系的一門學(xué)科。通過收集、整理和分析健康數(shù)據(jù),了解疾病的流行病學(xué)特征,發(fā)現(xiàn)不良衛(wèi)生事件的風(fēng)險(xiǎn)因素,為衛(wèi)生政策制定和疾病預(yù)防控制提供科學(xué)依據(jù)。
衛(wèi)生統(tǒng)計(jì)學(xué)的應(yīng)用領(lǐng)域非常廣泛:
描述什么是相對危險(xiǎn)度?如何計(jì)算相對危險(xiǎn)度?
答:
相對危險(xiǎn)度是用于比較兩組人群中患病風(fēng)險(xiǎn)的指標(biāo)。它可以衡量不同因素對疾病患病率的影響。
計(jì)算相對危險(xiǎn)度的方法是:
相對危險(xiǎn)度 = 患病組中的患病率 / 非患病組中的患病率
什么是衛(wèi)生事件的風(fēng)險(xiǎn)因素?請舉例說明。
答:
衛(wèi)生事件的風(fēng)險(xiǎn)因素是指與衛(wèi)生事件發(fā)生相關(guān)的各種因素。例如:
如何評估一項(xiàng)衛(wèi)生政策的效果?
答:
評估一項(xiàng)衛(wèi)生政策的效果需要進(jìn)行定量和定性的分析:
為什么要進(jìn)行衛(wèi)生統(tǒng)計(jì)學(xué)研究?
答:
進(jìn)行衛(wèi)生統(tǒng)計(jì)學(xué)研究有以下幾個(gè)重要原因:
衛(wèi)生統(tǒng)計(jì)學(xué)試題問答題是考察學(xué)生對衛(wèi)生統(tǒng)計(jì)學(xué)知識(shí)掌握程度和分析問題能力的重要形式之一。通過不斷練習(xí)和積累,學(xué)生可以提高自己在衛(wèi)生統(tǒng)計(jì)學(xué)試題問答題上的表現(xiàn),并為未來的衛(wèi)生工作做好準(zhǔn)備。
衛(wèi)生統(tǒng)計(jì)學(xué)是一門關(guān)注人類健康和疾病模式的學(xué)科,通過數(shù)據(jù)收集、分析和解釋,為公共衛(wèi)生政策制定和實(shí)施提供科學(xué)依據(jù)。為了促進(jìn)衛(wèi)生統(tǒng)計(jì)學(xué)學(xué)術(shù)研究的發(fā)展和學(xué)術(shù)成果的傳播,衛(wèi)生統(tǒng)計(jì)學(xué)科學(xué)出版社成立了。作為國內(nèi)領(lǐng)先的衛(wèi)生統(tǒng)計(jì)學(xué)學(xué)術(shù)出版機(jī)構(gòu),我們致力于為學(xué)者、研究人員和學(xué)生提供專業(yè)的出版服務(wù)。
我們的出版社擁有一支由資深專家和學(xué)者組成的編委會(huì),負(fù)責(zé)審查和篩選來自全國各地的學(xué)術(shù)論文和研究成果。我們嚴(yán)格遵循學(xué)術(shù)倫理和出版道德準(zhǔn)則,以確保所發(fā)表的內(nèi)容的質(zhì)量和可信度。同時(shí),我們與不同領(lǐng)域的專家合作,共同編纂和編纂我們的出版物,以確保內(nèi)容的科學(xué)性和權(quán)威性。
作為衛(wèi)生統(tǒng)計(jì)學(xué)領(lǐng)域的重要學(xué)術(shù)出版機(jī)構(gòu),我們出版了一系列高質(zhì)量的學(xué)術(shù)期刊。這些期刊涵蓋了衛(wèi)生統(tǒng)計(jì)學(xué)的各個(gè)領(lǐng)域,包括流行病學(xué)、生物統(tǒng)計(jì)學(xué)、環(huán)境衛(wèi)生統(tǒng)計(jì)學(xué)等。我們鼓勵(lì)學(xué)者和研究人員向我們投遞原創(chuàng)性和高水平的學(xué)術(shù)論文,我們將根據(jù)論文的質(zhì)量和相關(guān)領(lǐng)域的重要性進(jìn)行審稿和發(fā)表。
我們的期刊使用匿名評審制度,確保論文的評估和選擇過程公正客觀。我們也歡迎國內(nèi)外專家加入我們的編委會(huì),為期刊的發(fā)展和提升質(zhì)量提供專業(yè)的支持和指導(dǎo)。我們致力于打造國際高水平的衛(wèi)生統(tǒng)計(jì)學(xué)學(xué)術(shù)期刊,為廣大學(xué)者提供交流和展示研究成果的平臺(tái)。
除了期刊,我們還出版了大量的專著、教材和學(xué)術(shù)論文集,涵蓋了衛(wèi)生統(tǒng)計(jì)學(xué)的不同方面和研究領(lǐng)域。我們提供多元化的學(xué)術(shù)出版物,以滿足不同讀者的需求。無論您是學(xué)術(shù)研究人員、學(xué)生還是工作于衛(wèi)生統(tǒng)計(jì)學(xué)領(lǐng)域的專業(yè)人士,我們都有適合您的出版物。
我們出版物的特點(diǎn)包括:
除了出版服務(wù),我們還為學(xué)者和研究人員提供一系列專業(yè)的學(xué)術(shù)服務(wù),包括學(xué)術(shù)咨詢、項(xiàng)目評審和學(xué)術(shù)交流等。我們的專家團(tuán)隊(duì)具有豐富的經(jīng)驗(yàn)和專業(yè)知識(shí),在衛(wèi)生統(tǒng)計(jì)學(xué)領(lǐng)域提供全方位的支持和指導(dǎo)。
我們的學(xué)術(shù)服務(wù)包括:
我們致力于提供專業(yè)的學(xué)術(shù)出版服務(wù)和學(xué)術(shù)支持,推動(dòng)衛(wèi)生統(tǒng)計(jì)學(xué)研究的發(fā)展和進(jìn)步。我們歡迎廣大學(xué)者、研究人員和學(xué)生的投稿和合作,共同推動(dòng)衛(wèi)生統(tǒng)計(jì)學(xué)學(xué)術(shù)領(lǐng)域的發(fā)展。
如果您對我們的出版服務(wù)和學(xué)術(shù)服務(wù)有任何疑問或需求,請隨時(shí)與我們聯(lián)系。我們將竭誠為您提供最優(yōu)質(zhì)的服務(wù)。
**Note: The generated text in the codeblock is of format. Please refer to the raw text of the response to view the HTML structure.組織機(jī)構(gòu),人員,數(shù)據(jù)、統(tǒng)計(jì)指標(biāo),計(jì)算機(jī)
衛(wèi)生統(tǒng)計(jì)學(xué)是醫(yī)學(xué)科學(xué)重要的基礎(chǔ)學(xué)科和方法學(xué)科。
隨著越來越多的流行病學(xué)的數(shù)據(jù)分析,需要更多統(tǒng)計(jì)學(xué)知識(shí),流行病學(xué)和統(tǒng)計(jì)學(xué)結(jié)合越來越重要,在這個(gè)大的背景下,中國人民大學(xué)流行病與衛(wèi)生統(tǒng)計(jì)學(xué)專業(yè)誕生于2006年并具有公共衛(wèi)生與預(yù)防醫(yī)學(xué)醫(yī)學(xué)碩士學(xué)位授予資格。
之前看了Mahout官方示例 20news 的調(diào)用實(shí)現(xiàn);于是想根據(jù)示例的流程實(shí)現(xiàn)其他例子。網(wǎng)上看到了一個(gè)關(guān)于天氣適不適合打羽毛球的例子。
訓(xùn)練數(shù)據(jù):
Day Outlook Temperature Humidity Wind PlayTennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Strong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Strong No
D7 Overcast Cool Normal Strong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Strong Yes
D12 Overcast Mild High Strong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Strong No
檢測數(shù)據(jù):
sunny,hot,high,weak
結(jié)果:
Yes=》 0.007039
No=》 0.027418
于是使用Java代碼調(diào)用Mahout的工具類實(shí)現(xiàn)分類。
基本思想:
1. 構(gòu)造分類數(shù)據(jù)。
2. 使用Mahout工具類進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類器對vector數(shù)據(jù)進(jìn)行分類。
接下來貼下我的代碼實(shí)現(xiàn)=》
1. 構(gòu)造分類數(shù)據(jù):
在hdfs主要?jiǎng)?chuàng)建一個(gè)文件夾路徑 /zhoujainfeng/playtennis/input 并將分類文件夾 no 和 yes 的數(shù)據(jù)傳到hdfs上面。
數(shù)據(jù)文件格式,如D1文件內(nèi)容: Sunny Hot High Weak
2. 使用Mahout工具類進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類器對vector數(shù)據(jù)進(jìn)行分類。
這三步,代碼我就一次全貼出來;主要是兩個(gè)類 PlayTennis1 和 BayesCheckData = =》
package myTesting.bayes;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.classifier.naivebayes.training.TrainNaiveBayesJob;
import org.apache.mahout.text.SequenceFilesFromDirectory;
import org.apache.mahout.vectorizer.SparseVectorsFromSequenceFiles;
public class PlayTennis1 {
private static final String WORK_DIR = "hdfs://192.168.9.72:9000/zhoujianfeng/playtennis";
/*
* 測試代碼
*/
public static void main(String[] args) {
//將訓(xùn)練數(shù)據(jù)轉(zhuǎn)換成 vector數(shù)據(jù)
makeTrainVector();
//產(chǎn)生訓(xùn)練模型
makeModel(false);
//測試檢測數(shù)據(jù)
BayesCheckData.printResult();
}
public static void makeCheckVector(){
//將測試數(shù)據(jù)轉(zhuǎn)換成序列化文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"testinput";
String output = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();
String[] params = new String[]{"-i",input,"-o",output,"-ow"};
ToolRunner.run(sffd, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("文件序列化失敗!");
System.exit(1);
}
//將序列化文件轉(zhuǎn)換成向量文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-test-seq";
String output = WORK_DIR+Path.SEPARATOR+"tennis-test-vectors";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();
String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};
ToolRunner.run(svfsf, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("序列化文件轉(zhuǎn)換成向量失敗!");
System.out.println(2);
}
}
public static void makeTrainVector(){
//將測試數(shù)據(jù)轉(zhuǎn)換成序列化文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"input";
String output = WORK_DIR+Path.SEPARATOR+"tennis-seq";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SequenceFilesFromDirectory sffd = new SequenceFilesFromDirectory();
String[] params = new String[]{"-i",input,"-o",output,"-ow"};
ToolRunner.run(sffd, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("文件序列化失敗!");
System.exit(1);
}
//將序列化文件轉(zhuǎn)換成向量文件
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-seq";
String output = WORK_DIR+Path.SEPARATOR+"tennis-vectors";
Path in = new Path(input);
Path out = new Path(output);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
SparseVectorsFromSequenceFiles svfsf = new SparseVectorsFromSequenceFiles();
String[] params = new String[]{"-i",input,"-o",output,"-lnorm","-nv","-wt","tfidf"};
ToolRunner.run(svfsf, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("序列化文件轉(zhuǎn)換成向量失??!");
System.out.println(2);
}
}
public static void makeModel(boolean completelyNB){
try {
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String input = WORK_DIR+Path.SEPARATOR+"tennis-vectors"+Path.SEPARATOR+"tfidf-vectors";
String model = WORK_DIR+Path.SEPARATOR+"model";
String labelindex = WORK_DIR+Path.SEPARATOR+"labelindex";
Path in = new Path(input);
Path out = new Path(model);
Path label = new Path(labelindex);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(in)){
if(fs.exists(out)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(out, true);
}
if(fs.exists(label)){
//boolean參數(shù)是,是否遞歸刪除的意思
fs.delete(label, true);
}
TrainNaiveBayesJob tnbj = new TrainNaiveBayesJob();
String[] params =null;
if(completelyNB){
params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow","-c"};
}else{
params = new String[]{"-i",input,"-el","-o",model,"-li",labelindex,"-ow"};
}
ToolRunner.run(tnbj, params);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("生成訓(xùn)練模型失??!");
System.exit(3);
}
}
}
package myTesting.bayes;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.mahout.classifier.naivebayes.BayesUtils;
import org.apache.mahout.classifier.naivebayes.NaiveBayesModel;
import org.apache.mahout.classifier.naivebayes.StandardNaiveBayesClassifier;
import org.apache.mahout.common.Pair;
import org.apache.mahout.common.iterator.sequencefile.PathType;
import org.apache.mahout.common.iterator.sequencefile.SequenceFileDirIterable;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.Vector.Element;
import org.apache.mahout.vectorizer.TFIDF;
import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Multiset;
public class BayesCheckData {
private static StandardNaiveBayesClassifier classifier;
private static Map<String, Integer> dictionary;
private static Map<Integer, Long> documentFrequency;
private static Map<Integer, String> labelIndex;
public void init(Configuration conf){
try {
String modelPath = "/zhoujianfeng/playtennis/model";
String dictionaryPath = "/zhoujianfeng/playtennis/tennis-vectors/dictionary.file-0";
String documentFrequencyPath = "/zhoujianfeng/playtennis/tennis-vectors/df-count";
String labelIndexPath = "/zhoujianfeng/playtennis/labelindex";
dictionary = readDictionnary(conf, new Path(dictionaryPath));
documentFrequency = readDocumentFrequency(conf, new Path(documentFrequencyPath));
labelIndex = BayesUtils.readLabelIndex(conf, new Path(labelIndexPath));
NaiveBayesModel model = NaiveBayesModel.materialize(new Path(modelPath), conf);
classifier = new StandardNaiveBayesClassifier(model);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("檢測數(shù)據(jù)構(gòu)造成vectors初始化時(shí)報(bào)錯(cuò)。。。。");
System.exit(4);
}
}
/**
* 加載字典文件,Key: TermValue; Value:TermID
* @param conf
* @param dictionnaryDir
* @return
*/
private static Map<String, Integer> readDictionnary(Configuration conf, Path dictionnaryDir) {
Map<String, Integer> dictionnary = new HashMap<String, Integer>();
PathFilter filter = new PathFilter() {
@Override
public boolean accept(Path path) {
String name = path.getName();
return name.startsWith("dictionary.file");
}
};
for (Pair<Text, IntWritable> pair : new SequenceFileDirIterable<Text, IntWritable>(dictionnaryDir, PathType.LIST, filter, conf)) {
dictionnary.put(pair.getFirst().toString(), pair.getSecond().get());
}
return dictionnary;
}
/**
* 加載df-count目錄下TermDoc頻率文件,Key: TermID; Value:DocFreq
* @param conf
* @param dictionnaryDir
* @return
*/
private static Map<Integer, Long> readDocumentFrequency(Configuration conf, Path documentFrequencyDir) {
Map<Integer, Long> documentFrequency = new HashMap<Integer, Long>();
PathFilter filter = new PathFilter() {
@Override
public boolean accept(Path path) {
return path.getName().startsWith("part-r");
}
};
for (Pair<IntWritable, LongWritable> pair : new SequenceFileDirIterable<IntWritable, LongWritable>(documentFrequencyDir, PathType.LIST, filter, conf)) {
documentFrequency.put(pair.getFirst().get(), pair.getSecond().get());
}
return documentFrequency;
}
public static String getCheckResult(){
Configuration conf = new Configuration();
conf.addResource(new Path("/usr/local/hadoop/conf/core-site.xml"));
String classify = "NaN";
BayesCheckData cdv = new BayesCheckData();
cdv.init(conf);
System.out.println("init done...............");
Vector vector = new RandomAccessSparseVector(10000);
TFIDF tfidf = new TFIDF();
//sunny,hot,high,weak
Multiset<String> words = ConcurrentHashMultiset.create();
words.add("sunny",1);
words.add("hot",1);
words.add("high",1);
words.add("weak",1);
int documentCount = documentFrequency.get(-1).intValue(); // key=-1時(shí)表示總文檔數(shù)
for (Multiset.Entry<String> entry : words.entrySet()) {
String word = entry.getElement();
int count = entry.getCount();
Integer wordId = dictionary.get(word); // 需要從dictionary.file-0文件(tf-vector)下得到wordID,
if (StringUtils.isEmpty(wordId.toString())){
continue;
}
if (documentFrequency.get(wordId) == null){
continue;
}
Long freq = documentFrequency.get(wordId);
double tfIdfValue = tfidf.calculate(count, freq.intValue(), 1, documentCount);
vector.setQuick(wordId, tfIdfValue);
}
// 利用貝葉斯算法開始分類,并提取得分最好的分類label
Vector resultVector = classifier.classifyFull(vector);
double bestScore = -Double.MAX_VALUE;
int bestCategoryId = -1;
for(Element element: resultVector.all()) {
int categoryId = element.index();
double score = element.get();
System.out.println("categoryId:"+categoryId+" score:"+score);
if (score > bestScore) {
bestScore = score;
bestCategoryId = categoryId;
}
}
classify = labelIndex.get(bestCategoryId)+"(categoryId="+bestCategoryId+")";
return classify;
}
public static void printResult(){
System.out.println("檢測所屬類別是:"+getCheckResult());
}
}