当前位置: 首页>>代码示例>>Golang>>正文


Golang tabula.Claset类代码示例

本文整理汇总了Golang中github.com/shuLhan/tabula.Claset的典型用法代码示例。如果您正苦于以下问题:Golang Claset类的具体用法?Golang Claset怎么用?Golang Claset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Claset类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestSmote

func TestSmote(t *testing.T) {
	smot := smote.New(PercentOver, K, 5)

	// Read samples.
	dataset := tabula.Claset{}

	_, e := dsv.SimpleRead(fcfg, &dataset)
	if nil != e {
		t.Fatal(e)
	}

	fmt.Println("[smote_test] Total samples:", dataset.Len())

	minorset := dataset.GetMinorityRows()

	fmt.Println("[smote_test] # minority samples:", minorset.Len())

	e = smot.Resampling(*minorset)
	if e != nil {
		t.Fatal(e)
	}

	fmt.Println("[smote_test] # synthetic:", smot.GetSynthetics().Len())

	e = smot.Write("phoneme_smote.csv")
	if e != nil {
		t.Fatal(e)
	}
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:29,代码来源:smote_test.go

示例2: TestLNSmote

func TestLNSmote(t *testing.T) {
	// Read sample dataset.
	dataset := tabula.Claset{}
	_, e := dsv.SimpleRead(fcfg, &dataset)
	if nil != e {
		t.Fatal(e)
	}

	fmt.Println("[lnsmote_test] Total samples:", dataset.GetNRow())

	// Write original samples.
	writer, e := dsv.NewWriter("")

	if nil != e {
		t.Fatal(e)
	}

	e = writer.OpenOutput("phoneme_lnsmote.csv")
	if e != nil {
		t.Fatal(e)
	}

	sep := dsv.DefSeparator
	_, e = writer.WriteRawRows(dataset.GetRows(), &sep)
	if e != nil {
		t.Fatal(e)
	}

	// Initialize LN-SMOTE.
	lnsmoteRun := lnsmote.New(100, 5, 5, "1", "lnsmote.outliers")

	e = lnsmoteRun.Resampling(&dataset)

	fmt.Println("[lnsmote_test] # synthetic:", lnsmoteRun.Synthetics.Len())

	sep = dsv.DefSeparator
	_, e = writer.WriteRawRows(lnsmoteRun.Synthetics.GetRows(), &sep)
	if e != nil {
		t.Fatal(e)
	}

	e = writer.Close()
	if e != nil {
		t.Fatal(e)
	}
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:46,代码来源:lnsmote_test.go

示例3: runSmote

//
// runSmote will select minority class from dataset and run oversampling.
//
func runSmote(smote *smote.Runtime, dataset *tabula.Claset) (e error) {
	minorset := dataset.GetMinorityRows()

	if DEBUG >= 1 {
		fmt.Println("[smote] # minority samples:", minorset.Len())
	}

	e = smote.Resampling(*minorset)
	if e != nil {
		return
	}

	if DEBUG >= 1 {
		fmt.Println("[smote] # synthetics:", smote.Synthetics.Len())
	}

	return
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:21,代码来源:main.go

示例4: main

func main() {
	defer un(trace("smote"))

	flag.Parse()

	if len(flag.Args()) <= 0 {
		usage()
		os.Exit(1)
	}

	fcfg := flag.Arg(0)

	// Parsing config file and parameter.
	smote, e := createSmote(fcfg)
	if e != nil {
		panic(e)
	}

	// Get dataset.
	dataset := tabula.Claset{}
	_, e = dsv.SimpleRead(fcfg, &dataset)
	if e != nil {
		panic(e)
	}

	fmt.Println("[smote] Dataset:", &dataset)

	row := dataset.GetRow(0)
	fmt.Println("[smote] sample:", row)

	e = runSmote(smote, &dataset)
	if e != nil {
		panic(e)
	}

	if !merge {
		return
	}

	e = runMerge(smote, &dataset)
	if e != nil {
		panic(e)
	}
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:44,代码来源:main.go

示例5: test

func test() {
	testset := tabula.Claset{}
	_, e := dsv.SimpleRead(testCfg, &testset)
	if e != nil {
		panic(e)
	}

	fmt.Println(tag, "Test set:", &testset)
	fmt.Println(tag, "Sample test set:", testset.GetRow(0))

	predicts, cm, probs := crforest.ClassifySetByWeight(&testset, nil)

	fmt.Println("[crf] Test set CM:", cm)

	crforest.Performance(&testset, predicts, probs)

	e = crforest.WritePerformance()
	if e != nil {
		panic(e)
	}
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:21,代码来源:main.go

示例6: CountOOBError

/*
CountOOBError process out-of-bag data on tree and return error value.
*/
func (runtime *Runtime) CountOOBError(oob tabula.Claset) (
	errval float64,
	e error,
) {
	// save the original target to be compared later.
	origTarget := oob.GetClassAsStrings()

	if DEBUG >= 2 {
		fmt.Println("[cart] OOB:", oob.Columns)
		fmt.Println("[cart] TREE:", &runtime.Tree)
	}

	// reset the target.
	oobtarget := oob.GetClassColumn()
	oobtarget.ClearValues()

	e = runtime.ClassifySet(&oob)

	if e != nil {
		// set original target values back.
		oobtarget.SetValues(origTarget)
		return
	}

	target := oobtarget.ToStringSlice()

	if DEBUG >= 2 {
		fmt.Println("[cart] original target:", origTarget)
		fmt.Println("[cart] classify target:", target)
	}

	// count how many target value is miss-classified.
	runtime.OOBErrVal, _, _ = tekstus.WordsCountMissRate(origTarget, target)

	// set original target values back.
	oobtarget.SetValues(origTarget)

	return runtime.OOBErrVal, nil
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:42,代码来源:cart.go

示例7: TestReaderWithClaset

func TestReaderWithClaset(t *testing.T) {
	fcfg := "testdata/claset.dsv"

	claset := tabula.Claset{}

	_, e := dsv.NewReader(fcfg, &claset)
	if e != nil {
		t.Fatal(e)
	}

	assert(t, 3, claset.GetClassIndex(), true)

	claset.SetMajorityClass("regular")
	claset.SetMinorityClass("vandalism")

	clone := claset.Clone().(tabula.ClasetInterface)

	assert(t, 3, clone.GetClassIndex(), true)
	assert(t, "regular", clone.MajorityClass(), true)
	assert(t, "vandalism", clone.MinorityClass(), true)
}
开发者ID:shuLhan,项目名称:dsv,代码行数:21,代码来源:claset_test.go

示例8: getSamples

func getSamples() (train, test tabula.ClasetInterface) {
	samples := tabula.Claset{}
	_, e := dsv.SimpleRead(SampleDsvFile, &samples)
	if nil != e {
		log.Fatal(e)
	}

	if !DoTest {
		return &samples, nil
	}

	ntrain := int(float32(samples.Len()) * (float32(NBootstrap) / 100.0))

	bag, oob, _, _ := tabula.RandomPickRows(&samples, ntrain, false)

	train = bag.(tabula.ClasetInterface)
	test = oob.(tabula.ClasetInterface)

	train.SetClassIndex(samples.GetClassIndex())
	test.SetClassIndex(samples.GetClassIndex())

	return train, test
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:23,代码来源:rf_test.go

示例9: TestCART

func TestCART(t *testing.T) {
	fds := "../../testdata/iris/iris.dsv"

	ds := tabula.Claset{}

	_, e := dsv.SimpleRead(fds, &ds)
	if nil != e {
		t.Fatal(e)
	}

	fmt.Println("[cart_test] class index:", ds.GetClassIndex())

	// copy target to be compared later.
	targetv := ds.GetClassAsStrings()

	assert(t, NRows, ds.GetNRow(), true)

	// Build CART tree.
	CART, e := cart.New(&ds, cart.SplitMethodGini, 0)
	if e != nil {
		t.Fatal(e)
	}

	fmt.Println("[cart_test] CART Tree:\n", CART)

	// Create test set
	testset := tabula.Claset{}
	_, e = dsv.SimpleRead(fds, &testset)

	if nil != e {
		t.Fatal(e)
	}

	testset.GetClassColumn().ClearValues()

	// Classifiy test set
	e = CART.ClassifySet(&testset)
	if nil != e {
		t.Fatal(e)
	}

	assert(t, targetv, testset.GetClassAsStrings(), true)
}
开发者ID:shuLhan,项目名称:go-mining,代码行数:43,代码来源:cart_test.go


注:本文中的github.com/shuLhan/tabula.Claset类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。