本文整理汇总了Golang中github.com/shuLhan/tabula.ClasetInterface.GetRows方法的典型用法代码示例。如果您正苦于以下问题:Golang ClasetInterface.GetRows方法的具体用法?Golang ClasetInterface.GetRows怎么用?Golang ClasetInterface.GetRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shuLhan/tabula.ClasetInterface
的用法示例。
在下文中一共展示了ClasetInterface.GetRows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ClassifySet
//
// ClassifySet given a samples predict their class by running each sample in
// forest, adn return their class prediction with confusion matrix.
// `samples` is the sample that will be predicted, `sampleIds` is the index of
// samples.
// If `sampleIds` is not nil, then sample index will be checked in each tree,
// if the sample is used for training, their vote is not counted.
//
// Algorithm,
//
// (0) Get value space (possible class values in dataset)
// (1) For each row in test-set,
// (1.1) collect votes in all trees,
// (1.2) select majority class vote, and
// (1.3) compute and save the actual class probabilities.
// (2) Compute confusion matrix from predictions.
// (3) Compute stat from confusion matrix.
// (4) Write the stat to file only if sampleIds is empty, which mean its run
// not from OOB set.
//
func (forest *Runtime) ClassifySet(samples tabula.ClasetInterface,
sampleIds []int,
) (
predicts []string, cm *classifier.CM, probs []float64,
) {
stat := classifier.Stat{}
stat.Start()
if len(sampleIds) <= 0 {
fmt.Println(tag, "Classify set:", samples)
fmt.Println(tag, "Classify set sample (one row):",
samples.GetRow(0))
}
// (0)
vs := samples.GetClassValueSpace()
actuals := samples.GetClassAsStrings()
sampleIdx := -1
// (1)
rows := samples.GetRows()
for x, row := range *rows {
// (1.1)
if len(sampleIds) > 0 {
sampleIdx = sampleIds[x]
}
votes := forest.Votes(row, sampleIdx)
// (1.2)
classProbs := tekstus.WordsProbabilitiesOf(votes, vs, false)
_, idx, ok := numerus.Floats64FindMax(classProbs)
if ok {
predicts = append(predicts, vs[idx])
}
// (1.3)
probs = append(probs, classProbs[0])
}
// (2)
cm = forest.ComputeCM(sampleIds, vs, actuals, predicts)
// (3)
forest.ComputeStatFromCM(&stat, cm)
stat.End()
if len(sampleIds) <= 0 {
fmt.Println(tag, "CM:", cm)
fmt.Println(tag, "Classifying stat:", stat)
_ = stat.Write(forest.StatFile)
}
return predicts, cm, probs
}