コード例 #1
0
ファイル: knnclassifier_iris.go プロジェクト: npbool/golearn
func main() {
	//Parses the infamous Iris data.
	cols, rows, _, labels, data := data.ParseCsv("datasets/iris.csv", 4, []int{0, 1, 2})

	//Initialises a new KNN classifier
	cls := knn.NewKnnClassifier("euclidean")
	cls.Fit(labels, data, rows, cols)

	for {
		//Creates a random array of N float64s between 0 and 7
		randArray := util.RandomArray(3, 7)

		//Calculates the Euclidean distance and returns the most popular label
		labels := cls.Predict(randArray, 3)
		fmt.Println(labels)
	}
}
コード例 #2
0
ファイル: knnregressor_random.go プロジェクト: npbool/golearn
func main() {
	//Parses the infamous Iris data.
	cols, rows, _, labels, data := data.ParseCsv("datasets/randomdata.csv", 2, []int{0, 1})
	newlabels := util.ConvertLabelsToFloat(labels)

	//Initialises a new KNN classifier
	cls := knn.NewKnnRegressor("euclidean")
	cls.Fit(newlabels, data, rows, cols)

	for {
		//Creates a random array of N float64s between 0 and Y
		randArray := util.RandomArray(2, 100)

		//Initialises a vector with this array
		random := mat64.NewDense(1, 2, randArray)

		//Calculates the Euclidean distance and returns the most popular label
		outcome := cls.Predict(random, 3)
		fmt.Println(outcome)
	}
}