修改IP地址,把LAN口地址改為192.168.2.1,上網(wǎng)方式選擇自動(dòng)獲取IP就可以了。一般就是IP沖突的原因。
將網(wǎng)絡(luò)地址和子網(wǎng)掩碼均換算成2進(jìn)制格式,那么32位的地址,從左往右數(shù)均是全1的部分,就是子網(wǎng)不變的部分,也就是子網(wǎng)號(hào)。
舉個(gè)例子,假設(shè)網(wǎng)絡(luò)中某個(gè)IP地址為192.168.174.86,子網(wǎng)掩碼255.255.240.0。換成二進(jìn)制IP地址為11000000.10101000.10101100.01010110子網(wǎng)掩碼為11111111.11111111.11111000.00000000掩碼全1部分為21位,那么網(wǎng)絡(luò)號(hào)就是21,對(duì)應(yīng)IP地址,前21位是不變的,那么子網(wǎng)號(hào)就為32-21=11。11位的子網(wǎng)。該網(wǎng)絡(luò)就為192.168.168.0
額,我最近也在自學(xué)計(jì)算機(jī)網(wǎng)絡(luò)方面的知識(shí),我的理解是這樣的,子網(wǎng)掩碼呢實(shí)際上就是規(guī)定一個(gè)子網(wǎng)的ip范圍。想我們經(jīng)常看到的,ip是192.168.1.9。子網(wǎng)掩碼為:255.255.255.0,你知道什么意思吧?也就是說(shuō)該子網(wǎng)的范圍就是192.168.1.0到192.168.1.255,就是256個(gè)ip,但是每個(gè)子網(wǎng)都必須保留兩個(gè)ip,最小的ip192.168.1.0作為子網(wǎng)號(hào),最大的ip192.168.1.255作為廣播地址。所以可用ip等于總范圍的該子網(wǎng)內(nèi)所有ip數(shù)量-2等于254。額這么說(shuō)你明白嗎?不明白繼續(xù)問(wèn)!我會(huì)盡力吧我理解的跟你說(shuō)!
看是那一類(lèi)網(wǎng),A類(lèi)子網(wǎng)掩碼是255.0.0.0
B類(lèi)子網(wǎng)掩碼是255.255.0.0
C類(lèi)子網(wǎng)掩碼是255.255.255.0
當(dāng)然有區(qū)別,子網(wǎng)就是來(lái)區(qū)分不同網(wǎng)絡(luò)區(qū)域。子網(wǎng)掩碼就是來(lái)劃分子網(wǎng)的。
就像192.168.1.1這個(gè)地址。沒(méi)有掩碼是不能看子網(wǎng)是什么的。192.168.1.1/255.255.255.128就是分為了2個(gè)子網(wǎng)。所以192.168.1.2和1.130就不在一下子網(wǎng)。就是說(shuō)是不是在一個(gè)子網(wǎng)是由掩碼確定的
比如172.16.2.160/255.255.255.0: 【1】在沒(méi)有劃分子網(wǎng)的情況下: 這個(gè)IP地址的【網(wǎng)絡(luò)號(hào)】就是172.16.2.0 【主機(jī)號(hào)】為 0.0.0.160 【2】劃分子網(wǎng)情況如: 172. 16. 2. 160/255.255.255.192(IP地址/掩碼) 1010 1100 0001 0000 0000 0010 1010 0000 (二進(jìn)制) 1111 1111 1111 1111 1111 1111 1100 0000 (子網(wǎng)掩碼) ------------------------------------------相"與"(理解成相乘) 1010 1100 0001 0000 0000 0010 1000 0000(172.16.2.128這就是子網(wǎng)號(hào)) 1010 1100 0001 0000 0000 0010 1000 0001(172.16.2.129是第一個(gè)主機(jī)) 1010 1100 0001 0000 0000 0010 1011 1110(172.16.2.190最后一個(gè)主機(jī)) 1010 1100 0001 0000 0000 0010 1011 1111 廣播地址 172.16.2.191 1010 1100 0001 0000 0000 0010 1100 0000 172.16.2.192 下一個(gè)子網(wǎng) 因?yàn)檠诖a是255.255.255.192 ,因此它們之間的網(wǎng)段間隔是256-192=64 所以這個(gè)網(wǎng)段只有(2的平方-2)2個(gè)子網(wǎng) 172.16.2.128 172.16.2.192 -------------------------------------------------
首先聲明,以下為本人看法,不代表任何立場(chǎng),如有雷同,不勝榮幸。
因?yàn)橐恍┰颍枰?gòu)置汽車(chē)一輛,然后就逛逛汽車(chē)之家之類(lèi)的APP,從最先準(zhǔn)備的買(mǎi)新車(chē),變?yōu)榱速I(mǎi)一臺(tái)合適的二手車(chē),本人又恰巧屬于半個(gè)汽車(chē)行業(yè)的工作者~所以有了接下來(lái)的故事。
最先去本地的二手車(chē)市場(chǎng),逛了一遍,價(jià)格偏高,而且沒(méi)有比較適合自己的車(chē),所以就經(jīng)常到網(wǎng)上看一些車(chē)源。逐漸發(fā)現(xiàn)其中瓜子網(wǎng)還相對(duì)靠譜一些,于是就還價(jià)準(zhǔn)備購(gòu)車(chē)。接下來(lái)就好玩了~
首先是北京總部的電話(huà),已經(jīng)被一群人標(biāo)記為了騷擾電話(huà),基本就是問(wèn)下你準(zhǔn)備不準(zhǔn)備按揭啊?(如果你按揭,恭喜你,單獨(dú)的服務(wù)費(fèi),GPS費(fèi)等等你一樣少不了)上哪里戶(hù)啊?就完了,接下來(lái)車(chē)輛所屬地的業(yè)務(wù)員就會(huì)給你打電話(huà),這里我不得不吐槽一下,這個(gè)業(yè)務(wù)員各地水平真相差挺大的~今早還價(jià)約看個(gè)觀致3,業(yè)務(wù)員打電話(huà)來(lái),我告訴他,這個(gè)車(chē)現(xiàn)在優(yōu)惠兩萬(wàn)起,所以車(chē)主標(biāo)價(jià)純屬亂賣(mài),他不信~我也就呵呵了~
其次,瓜子網(wǎng)上的新上架的汽車(chē),分分鐘,秒變價(jià)格(當(dāng)然我是指上架幾分鐘后突然就加價(jià)幾千,難道是因?yàn)槲谊P(guān)注 還價(jià)了?尷尬臉0.0)
這里我認(rèn)為各個(gè)業(yè)務(wù)員能力有差距很正常,不代表我對(duì)所有瓜子網(wǎng)業(yè)務(wù)員的看法。不過(guò),我還是想弱弱的問(wèn)一句,瓜子網(wǎng),你還招業(yè)務(wù)員嗎?能BB不動(dòng)腦的那種,我也來(lái)混份工資0.0
隨著看車(chē)和選擇車(chē)的范圍不斷擴(kuò)大,突然發(fā)現(xiàn),瓜子網(wǎng)這里面的水,越來(lái)越深了~
首先是服務(wù)費(fèi),我不想提你的廣告詞怎么怎么,不賺錢(qián),誰(shuí)干這個(gè)啊?車(chē)價(jià)3%,最低2000元服務(wù)費(fèi),這個(gè)好像是去年的收費(fèi),現(xiàn)在,呵呵呵呵呵~最低收費(fèi)3500~真特么打臉~(據(jù)說(shuō)服務(wù)費(fèi)可以講價(jià))
沒(méi)有中間商賺差價(jià),車(chē)主多賣(mài)錢(qián),買(mǎi)家少花錢(qián)。車(chē)主多沒(méi)多賣(mài)錢(qián),不知道,畢竟沒(méi)賣(mài)過(guò)車(chē),買(mǎi)家少花錢(qián),哈哈哈哈哈哈哈哈哈哈~普遍瓜子網(wǎng)的車(chē)價(jià)格都比二手車(chē)貴一點(diǎn),加上服務(wù)費(fèi),我就呵呵呵呵呵了~(我指的是售價(jià)5-15萬(wàn)之前的車(chē),其余沒(méi)怎么關(guān)注)
當(dāng)然這也只能欺騙欺騙萌新~后面的自欺欺人更是無(wú)敵~
照片中,車(chē)輛旁邊的就是售價(jià),然后你懂得~拿觀致5來(lái)說(shuō),10.5萬(wàn)我就不賣(mài),我只買(mǎi)10.1萬(wàn)~買(mǎi)家也很傲嬌,10.1萬(wàn)我就不買(mǎi),我就要買(mǎi)10.5萬(wàn)的~~~~~哈哈哈哈哈,啪啪啪啪啪的打臉~
最后我想對(duì)瓜子網(wǎng)的工作人員說(shuō)一句,買(mǎi)家想買(mǎi)便宜的車(chē)很正常,賣(mài)家想賣(mài)高價(jià)也無(wú)可厚非,請(qǐng)找到中間的那個(gè)度,別把賣(mài)家當(dāng)上帝,買(mǎi)家當(dāng)傻子,你要弄清楚,誰(shuí)付的 服務(wù)費(fèi)養(yǎng)你們的?也請(qǐng)動(dòng)動(dòng)腦子和手指多收集相關(guān)資料回答買(mǎi)家問(wèn)題,解決問(wèn)題,促成買(mǎi)賣(mài)達(dá)成。
想起再更新吧,洗澡去了。。。
子網(wǎng)掩碼是255.255.255.240,掩碼二進(jìn)制位共有連續(xù)28個(gè)1,可簡(jiǎn)記為IP/28。則主機(jī)位是IP二進(jìn)制的最后4位,一個(gè)子網(wǎng)內(nèi)地址是2?=16個(gè),子網(wǎng)可劃分為256/16=16個(gè)。
子網(wǎng)1: 192.168.0.0/28~192.168.0.15/28;
子網(wǎng)2: 192.168.0.16/28~192.168.0.31/28;
子網(wǎng)3: 192.168.0.32/28~192.168.0.47/28;
......
子網(wǎng)16: 192.168.0.240/28~192.168.0.255/28。
子網(wǎng)地址包括網(wǎng)絡(luò)地址,主機(jī)地址和廣播地址。
子網(wǎng)掩碼是用來(lái)區(qū)分網(wǎng)絡(luò)地址和主機(jī)地址的,舉個(gè)例子來(lái)說(shuō),子網(wǎng)192.168.1.0,子網(wǎng)掩碼是255.255.255.0。網(wǎng)絡(luò)地址:192.168.1.0,該地址用在路由器的路由表中; 主機(jī)地址:192.168.1.1到192.168.1.254,用來(lái)識(shí)別不同的主機(jī); 廣播地址:192.168.1.255,用于在該網(wǎng)段的所有主機(jī)設(shè)備發(fā)送報(bào)文。再來(lái)說(shuō)掩碼: 255用二進(jìn)制表示是8個(gè)1,11111111,3個(gè)255用二進(jìn)制表示是24個(gè)1,對(duì)應(yīng)IP地址的網(wǎng)絡(luò)地址部分:192.168.1,這個(gè)部分對(duì)所有在這個(gè)網(wǎng)段的主機(jī)都是一樣的,掩碼最后一個(gè)0對(duì)應(yīng)二進(jìn)制的8個(gè)0,不同主機(jī)該部分是不同的,在該網(wǎng)段對(duì)應(yīng)1~254。IP地址與掩碼通過(guò)二進(jìn)制“與”運(yùn)算來(lái)得到IP地址的網(wǎng)絡(luò)部分和主機(jī)部分。之前看了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
檢測(cè)數(shù)據(jù):
sunny,hot,high,weak
結(jié)果:
Yes=》 0.007039
No=》 0.027418
于是使用Java代碼調(diào)用Mahout的工具類(lèi)實(shí)現(xiàn)分類(lèi)。
基本思想:
1. 構(gòu)造分類(lèi)數(shù)據(jù)。
2. 使用Mahout工具類(lèi)進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測(cè)數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類(lèi)器對(duì)vector數(shù)據(jù)進(jìn)行分類(lèi)。
接下來(lái)貼下我的代碼實(shí)現(xiàn)=》
1. 構(gòu)造分類(lèi)數(shù)據(jù):
在hdfs主要?jiǎng)?chuàng)建一個(gè)文件夾路徑 /zhoujainfeng/playtennis/input 并將分類(lèi)文件夾 no 和 yes 的數(shù)據(jù)傳到hdfs上面。
數(shù)據(jù)文件格式,如D1文件內(nèi)容: Sunny Hot High Weak
2. 使用Mahout工具類(lèi)進(jìn)行訓(xùn)練,得到訓(xùn)練模型。
3。將要檢測(cè)數(shù)據(jù)轉(zhuǎn)換成vector數(shù)據(jù)。
4. 分類(lèi)器對(duì)vector數(shù)據(jù)進(jìn)行分類(lèi)。
這三步,代碼我就一次全貼出來(lái);主要是兩個(gè)類(lèi) 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";
/*
* 測(cè)試代碼
*/
public static void main(String[] args) {
//將訓(xùn)練數(shù)據(jù)轉(zhuǎn)換成 vector數(shù)據(jù)
makeTrainVector();
//產(chǎn)生訓(xùn)練模型
makeModel(false);
//測(cè)試檢測(cè)數(shù)據(jù)
BayesCheckData.printResult();
}
public static void makeCheckVector(){
//將測(cè)試數(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(){
//將測(cè)試數(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("檢測(cè)數(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);
}
// 利用貝葉斯算法開(kāi)始分類(lèi),并提取得分最好的分類(lèi)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("檢測(cè)所屬類(lèi)別是:"+getCheckResult());
}
}