Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to convert class name into single quote? #275

Open
mattn opened this issue Mar 8, 2022 · 0 comments
Open

Question: How to convert class name into single quote? #275

mattn opened this issue Mar 8, 2022 · 0 comments

Comments

@mattn
Copy link

mattn commented Mar 8, 2022

I'm trying to train/predict iris.csv and got problem that can not pass string attributes into Fit since CategoryAttribute is not FloatAttribute. I want to know how to convert "Iris-setosa", "Iris-versicolor" and "Iris-virsinica" into 0, 1, 2 or (0.0, 0.3333, 0.6666). Could you please let me know the way?

package main

import (
	"fmt"
	"log"

	"github.com/sjwhitworth/golearn/base"
	"github.com/sjwhitworth/golearn/evaluation"
	"github.com/sjwhitworth/golearn/linear_models"
)

func main() {
	inst, err := base.ParseCSVToInstances("datasets/iris.csv", false)
	if err != nil {
		log.Fatal(err)
	}

	lr, err := linear_models.NewLogisticRegression("l2", 1.0, 1e-6)
	if err != nil {
		log.Fatal(err)
	}

	trainData, testData := base.InstancesTrainTestSplit(inst, 0.50)

	lr.Fit(trainData)

	pred, err := lr.Predict(testData)
	if err != nil {
		log.Fatal(err)
	}
	confusionMat, err := evaluation.GetConfusionMatrix(testData, pred)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(evaluation.GetSummary(confusionMat))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant