Example #1
0
func main() {
	var r regression.Regression
	//r.Debug = true
	r.SetObservedName("Distance")
	r.SetVarName(0, "Weight")
	r.SetVarName(1, "Height")
	r.SetVarName(2, "Blood sugar")
	r.AddDataPoint(regression.DataPoint{Observed: 98, Variables: []float64{483, 343, 0.0386}})
	r.AddDataPoint(regression.DataPoint{Observed: 75, Variables: []float64{227, 419, 0.0705}})
	r.AddDataPoint(regression.DataPoint{Observed: 0, Variables: []float64{380, 666, 0.0245}})
	r.AddDataPoint(regression.DataPoint{Observed: 20, Variables: []float64{85, 833, 0.0567}})
	r.AddDataPoint(regression.DataPoint{Observed: 50, Variables: []float64{188, 182, 0.0143}})
	r.AddDataPoint(regression.DataPoint{Observed: 90, Variables: []float64{783, 1148, 0.0129}})
	r.RunLinearRegression()
	r.Dump(true)
}
Example #2
0
func main() {
	// Initialise a new regression data set
	var r regression.Regression

	// Load the CSV data as data points
	dataFile, err := os.Open("data-no-zeros.csv")
	if err != nil {
		fmt.Print(err, "\n")
	}
	reader := csv.NewReader(dataFile)
	row, err := reader.Read()
	count := 0
	for err == nil {
		if count == 0 {
			for i := 0; i < len(row); i++ {
				if i == 0 {
					r.SetObservedName(row[i])
				} else {
					r.SetVarName(i-1, row[i])
				}
			}
		} else {
			var d regression.DataPoint
			d.Variables = make([]float64, len(row)-1)
			for i := 0; i < len(row); i++ {
				if i == 0 {
					observed, _ := strconv.ParseFloat(row[i], 64)
					d.Observed = observed
				} else {
					variable, _ := strconv.ParseFloat(row[i], 64)
					d.Variables[i-1] = variable
				}
			}
			r.AddDataPoint(d)
		}
		count++
		row, err = reader.Read()
	}
	dataFile.Close()

	// Run the regression
	r.RunLinearRegression()
	r.Dump(true)
}