Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "gopkg.in/sensorbee/sensorbee.v0/data" "math/rand" ) type shogun struct { family string given string } func unigram(s string) FeatureVector { fv := make(FeatureVector) for _, r := range s { fv[string(r)] = data.Float(1) } return fv } func main() { shogunList := []shogun{ {"徳川", "家康"}, {"徳川", "秀忠"}, {"徳川", "家光"}, {"徳川", "家綱"}, {"徳川", "綱吉"}, {"徳川", "家宣"}, {"徳川", "家継"}, {"徳川", "吉宗"}, {"徳川", "家重"}, {"徳川", "家治"}, {"徳川", "家斉"}, {"徳川", "家慶"}, {"徳川", "家定"}, {"徳川", "家茂"}, {"足利", "尊氏"}, {"足利", "義詮"}, {"足利", "義満"}, {"足利", "義持"}, {"足利", "義量"}, {"足利", "義教"}, {"足利", "義勝"}, {"足利", "義政"}, {"足利", "義尚"}, {"足利", "義稙"}, {"足利", "義澄"}, {"足利", "義稙"}, {"足利", "義晴"}, {"足利", "義輝"}, {"足利", "義栄"}, {"北条", "時政"}, {"北条", "義時"}, {"北条", "泰時"}, {"北条", "経時"}, {"北条", "時頼"}, {"北条", "長時"}, {"北条", "政村"}, {"北条", "時宗"}, {"北条", "貞時"}, {"北条", "師時"}, {"北条", "宗宣"}, {"北条", "煕時"}, {"北条", "基時"}, {"北条", "高時"}, {"北条", "貞顕"}, } shuffledShogunList := make([]shogun, len(shogunList)) perm := rand.Perm(len(shogunList)) for i, v := range perm { shuffledShogunList[v] = shogunList[i] } var arow, _ = NewAROW(1) for _, s := range shuffledShogunList { fv := unigram(s.given) arow.Train(fv, Label(s.family)) } scores, _ := arow.Classify(unigram("慶喜")) l, _ := scores.Max() fmt.Println(l) scores, _ = arow.Classify(unigram("義昭")) l, _ = scores.Max() fmt.Println(l) scores, _ = arow.Classify(unigram("守時")) l, _ = scores.Max() fmt.Println(l) }
Output: 徳川 足利 北条
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AROWClassify ¶
AROWClassify classifies the input using the given model having stateName.
func ClassifiedLabel ¶
ClassifiedLabel returns the label having the highest score in a classification result.
Types ¶
type AROW ¶
type AROW struct {
// contains filtered or unexported fields
}
AROW holds a model for classification.
func NewAROW ¶
NewAROW creates an AROW model. regWeight means sensitivity for data. When regWeight is large, the model learns quickly but harms from noise. regWeight must be larger than zero.
func (*AROW) Classify ¶
func (a *AROW) Classify(v FeatureVector) (LScores, error)
Classify classifies a feature vector. This function returns all labels and scores.
type AROWState ¶
type AROWState struct {
// contains filtered or unexported fields
}
AROWState is a state which support AROW classification algorithm.
type AROWStateCreator ¶
type AROWStateCreator struct { }
AROWStateCreator is used by BQL to create or load AROWState as a UDS.
func (*AROWStateCreator) CreateState ¶
func (c *AROWStateCreator) CreateState(ctx *core.Context, params data.Map) (core.SharedState, error)
CreateState creates a new state for AROW classifier.
Click to show internal directories.
Click to hide internal directories.