コード例 #1
0
ファイル: week2.go プロジェクト: c4e8ece0/caltechx.go
func q5() {
	runs := 1000 // number of times we repeat the experiment
	linreg := linreg.NewLinearRegression()
	linreg.N = 100
	var avgEin, avgEout float64

	for run := 0; run < runs; run++ {
		linreg.Initialize()

		linreg.Learn()
		avgEin += linreg.Ein()
		avgEout += linreg.Eout()
	}
	avgEin = avgEin / float64(runs)
	avgEout = avgEout / float64(runs)
	fmt.Printf("average of In sample error 'Ein' for Linear regresion for N = 100 is %4.2f\n", avgEin)
	fmt.Printf("average of Out of sample error 'Eout' for Linear regresion for N = 100 is %4.2f\n", avgEout)
}
コード例 #2
0
ファイル: week2.go プロジェクト: c4e8ece0/caltechx.go
func q9() {

	runs := 1000 // number of times we repeat the experiment
	linreg := linreg.NewLinearRegression()
	linreg.N = 1000
	linreg.RandomTargetFunction = false
	linreg.TwoParams = true
	linreg.Noise = 0.1
	var aAvgIn, bAvgIn, cAvgIn, dAvgIn, eAvgIn float64
	var aAvgOut, bAvgOut, cAvgOut, dAvgOut, eAvgOut float64

	var AvgEout float64
	for run := 0; run < runs; run++ {

		linreg.TargetFunction = f //non linear function
		linreg.Initialize()
		linreg.TransformDataSet(nonLinearFeature, 6)
		linreg.Learn()

		aAvgIn += linreg.CompareInSample(a, 2)
		bAvgIn += linreg.CompareInSample(b, 2)
		cAvgIn += linreg.CompareInSample(c, 2)
		dAvgIn += linreg.CompareInSample(d, 2)
		eAvgIn += linreg.CompareInSample(e, 2)

		aAvgOut += linreg.CompareOutOfSample(a, 2)
		bAvgOut += linreg.CompareOutOfSample(b, 2)
		cAvgOut += linreg.CompareOutOfSample(c, 2)
		dAvgOut += linreg.CompareOutOfSample(d, 2)
		eAvgOut += linreg.CompareOutOfSample(e, 2)

		AvgEout += linreg.Eout()
	}

	aAvgIn = aAvgIn / float64(runs)
	bAvgIn = bAvgIn / float64(runs)
	cAvgIn = cAvgIn / float64(runs)
	dAvgIn = dAvgIn / float64(runs)
	eAvgIn = eAvgIn / float64(runs)

	aAvgOut = aAvgOut / float64(runs)
	bAvgOut = bAvgOut / float64(runs)
	cAvgOut = cAvgOut / float64(runs)
	dAvgOut = dAvgOut / float64(runs)
	eAvgOut = eAvgOut / float64(runs)

	AvgEout = AvgEout / float64(runs)

	fmt.Printf("average of difference in sample between a() and the linear regression hypothesis is %5.3f\n", aAvgIn)
	fmt.Printf("average of difference in sample between b() and the linear regression hypothesis is %5.3f\n", bAvgIn)
	fmt.Printf("average of difference in sample between c() and the linear regression hypothesis is %5.3f\n", cAvgIn)
	fmt.Printf("average of difference in sample between d() and the linear regression hypothesis is %5.3f\n", dAvgIn)
	fmt.Printf("average of difference in sample between e() and the linear regression hypothesis is %5.3f\n", eAvgIn)

	fmt.Printf("average of difference out of sample between a() and the linear regression hypothesis is %7.5f\n", aAvgOut)
	fmt.Printf("average of difference out of sample between b() and the linear regression hypothesis is %7.5f\n", bAvgOut)
	fmt.Printf("average of difference out of sampleb etween c() and the linear regression hypothesis is %7.5f\n", cAvgOut)
	fmt.Printf("average of difference out of sample between d() and the linear regression hypothesis is %7.5f\n", dAvgOut)
	fmt.Printf("average of difference out of sample between e() and the linear regression hypothesis is %7.5f\n", eAvgOut)

	fmt.Printf("average Eout of the hypothesis learn through linear regression with noise of %4.2f is %4.3f\n", linreg.Noise, AvgEout)
}