Naïve Bayes(朴素贝叶斯)分类算法的实现
(1) 简介:
(2) 算法描述:
(3)
1 "); 20 $con = explode(" ",$result[$j]); 21 array_push($array,$con); 22 } 23 array_splice($array,0,1); 24 return $array; 25 } 26 //-------------------------------------------------------------------- 27 28 29 /* 30 *NaiveBayes朴素贝叶斯算法 31 *$test:测试文本;$train:训练文本;$flagsyes:yes;$flagsno:no 32 */ 33 //-------------------------------------------------------------------- 34 function NaiveBayes($test,$train,$flagsyes,$flagsno) 35 { 36 $count_yes = 0; 37 $num = count($train[0]); 38 for($i=1;$i
"); 62 print_r($testnumno."
"); 63 print_r($count_yes."
"); 64 print_r($count_no."
"); 65 print_r($array_no[$i]."
"); 66 */ 67 } 68 69 $py=1; 70 $pn=1; 71 for($i=1;$i
$pn)return $flagsyes; 80 else return $flagsno; 81 82 /* print_r($py." "); 83 print_r($pn." "); 84 */ 85 86 } 87 //-------------------------------------------------------------------- 88 89 $train = getFileContent("train.txt"); 90 $test = getFileContent("test.txt"); 91 92 for($i=1;$i ";120 print_r($test);121 echo "";122 //--------------------------------------------------------------------123 ?>