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

Example about how to query the model after being trained using KNN ? #265

Open
ch-rigu opened this issue Apr 19, 2021 · 4 comments
Open

Comments

@ch-rigu
Copy link

ch-rigu commented Apr 19, 2021

Hi!
Please cold you give an example about how to query this model after being trained ?
like when the testData is pased here: cls.Predict(testData)
it is possible do to something like this :

csv example:
Sepal length, Sepal width,Petal length, Petal width, Species
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
5.9,3.0,4.2,1.5,Iris-versicolor
6.0,2.2,4.0,1.0,Iris-versicolor
6.1,2.9,4.7,1.4,Iris-versicolor

input := '5.1,3.5,1.4,0.2'
predictions, err := cls.Predict(input)
if err != nil {
panic(err)
}
and print/get the species type ?

I managed to this in python but and quite lost about how to do it in Go

Cheers!
Chris.

@ch-rigu ch-rigu changed the title Example about how to query the model after being trained ? Example about how to query the model after being trained using KNN ? Apr 20, 2021
@Yushgoel
Copy link
Contributor

@ch-rigu Going through the code, the cls.Predict() function requires a FixedDataGrid as input. So you will need to convert input to a Fixed Data Grid format to pass it into Predict()

@alexanderjophus
Copy link

I'm also trying to solve this problem. After converting the user input to a FixedDataGrid the CategoricalAttribute is missing from the input data, when using Predict(), it complains attributes not compatible.

As far as I understand it, I do not want to pass in the categorical info from my user input, I want that to be returned from the Predict() function

	cls, err := knn.ReloadKNNClassifier("model.cls")
	if err != nil {
		log.Fatal(fmt.Errorf("loading model: %w", err))
	}
	toPredict := strings.NewReader("5.1,3.5,1.4,0.2")

	rawData, err := base.ParseCSVToInstancesFromReader(toPredict, false)
	if err != nil {
		log.Fatal(fmt.Errorf("parse reader: %w", err))
	}

	fmt.Println(cls.TrainingData.AllAttributes())
	fmt.Println(rawData.AllAttributes())
	predictions, err := cls.Predict(rawData)
	if err != nil {
		log.Fatal(fmt.Errorf("predicting: %w", err))
	}

The output from the 2 print statements is;

[FloatAttribute(0) FloatAttribute(1) FloatAttribute(2) FloatAttribute(3) CategoricalAttribute("4", [Iris-setosa Iris-versicolor Iris-virginica])]
[FloatAttribute(0) FloatAttribute(1) FloatAttribute(2) FloatAttribute(3)]

Am I doing something wrong in the model?

@ymmemo
Copy link

ymmemo commented Nov 2, 2022

I had the same question. Is there a solution to the problem?

@riverlaker
Copy link

riverlaker commented Nov 2, 2022 via email

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

5 participants