bayes
1.1.4
bayes
: PHP용 Naive- bayes 분류기 bayes
문서(텍스트 조각)를 가져와서 해당 문서가 어떤 카테고리에 속하는지 알려줍니다.
이 라이브러리는 nodejs lib @ https://github.com/ttezel/bayes에서 포팅되었습니다.
텍스트 콘텐츠를 임의의 범주 집합으로 분류하는 데 이 기능을 사용할 수 있습니다. 예를 들어:
composer require niiknow/ bayes
$ classifier = new Niiknow bayes ();
// teach it positive phrases
$ classifier -> learn ( ' amazing, awesome movie!! Yeah!! Oh boy. ' , ' positive ' );
$ classifier -> learn ( ' Sweet, this is incredibly, amazing, perfect, great!! ' , ' positive ' );
// teach it a negative phrase
$ classifier -> learn ( ' terrible, shitty thing. Damn. Sucks!! ' , ' negative ' );
// now ask it to categorize a document it has never seen before
$ classifier -> categorize ( ' awesome, cool, amazing!! Yay. ' );
// => 'positive'
// serialize the classifier's state as a JSON string.
$ stateJson = $ classifier -> toJson ();
// load the classifier back from its JSON representation.
$ classifier -> fromJson ( $ stateJson );
$classifier = new Niiknow bayes ([options])
bayes 분류기의 인스턴스를 반환합니다.
인스턴스를 구성하려면 선택적 options
개체를 전달하세요. options
에 tokenizer
함수를 지정하면 해당 함수가 인스턴스의 토크나이저로 사용됩니다.
$classifier->learn(text, category)
text
어떤 category
에 속하는지 분류자에게 알려주세요. 분류자를 더 많이 가르칠수록 분류자의 신뢰성이 높아집니다. 이전에 본 적이 없는 새로운 문서를 식별하기 위해 학습한 내용을 사용할 것입니다.
$classifier->categorize(text)
text
속한다고 생각되는 category
반환합니다. 판단은 .learn() 으로 가르친 내용을 기반으로 합니다.
$classifier->probabilities(text)
알려진 각 범주에 대한 확률을 추출합니다.
$classifier->toJson()
분류자의 JSON 표현을 반환합니다.
$classifier->fromJson(jsonStr)
JSON 표현에서 분류자 인스턴스를 반환합니다. $classifier->toJson()
에서 얻은 JSON 표현과 함께 이것을 사용하십시오.
생성자에서 자체 토크나이저 함수를 전달할 수 있습니다. 예:
// array containing stopwords
$stopwords = array("der", "die", "das", "the");
// escape the stopword array and implode with pipe
$s = '~^W*('.implode("|", array_map("preg_quote", $stopwords)).')W+b|bW+(?1)W*$~i';
$options['tokenizer'] = function($text) use ($s) {
// convert everything to lowercase
$text = mb_strtolower($text);
// remove stop words
$text = preg_replace($s, '', $text);
// split the words
preg_match_all('/[[:alpha:]]+/u', $text, $matches);
// first match list of words
return $matches[0];
};
$classifier = new niiknow bayes ($options);