golearn icon indicating copy to clipboard operation
golearn copied to clipboard

load custom data?

Open trayanr opened this issue 6 years ago • 8 comments

Is there a function that can easily transform a slice or a map to an instance, or to somehow directly use raw data for the prediction algorithm?

trayanr avatar Mar 20 '18 15:03 trayanr

After hours reading code and trying different things, I ended up just converting my slice/map/struct to a CSV format and parse it back:

record := // Any array of strings
attributes := strings.Join(record, ",")
strReader := bytes.NewReader([]byte(attributes))
hasHeaders := false
fixedDataGrid, err := base.ParseCSVToInstancesFromReader(strReader, hasHeaders)

Not the solution I would want, but it works for now.

cesarrodrig avatar Mar 22 '18 14:03 cesarrodrig

Yeah, I think we could do better. Would something like a ParseMapListToTemplatedInstances([]map[string]interface{}, base.Instances) error-style function be close to what you're looking for?

Sentimentron avatar Mar 24 '18 00:03 Sentimentron

For Python, scikit-learn has great integration with pandas since the two go hand in hand for many data science projects. It would be strategic if this library interfaced with Gota, the Go dataframes library. They already have wrappers around Gonum matrices, so integration between these two libraries would be nice.

shreydesai avatar Jun 29 '18 20:06 shreydesai

Interesting... Gota didn't really exist when this project got going, but I'd say it's worth looking into.

Sentimentron avatar Jul 01 '18 18:07 Sentimentron

I recently had to use this library for a project, but needed a dataframe for data wrangling purposes. Obviously, there's no integration between dataframes and dense instances even though the two data structures are quite similar. Sketching out some sort of API to interface with Gota would be worthwhile.

shreydesai avatar Jul 01 '18 23:07 shreydesai

In mnist example, I want load a Image then convert it into test data,How?

lanybass avatar Oct 19 '18 02:10 lanybass

After hours reading code and trying different things, I ended up just converting my slice/map/struct to a CSV format and parse it back:

record := // Any array of strings
attributes := strings.Join(record, ",")
strReader := bytes.NewReader([]byte(attributes))
hasHeaders := false
fixedDataGrid, err := base.ParseCSVToInstancesFromReader(strReader, hasHeaders)

Not the solution I would want, but it works for now.

Hi! @cesarrodrig, I'm triying this solution but I'm having the error: panic: attributes not compatible. I'm using the iris_headers.csv

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
5.1,2.5,3.0,1.1,Iris-versicolor
5.7,2.8,4.1,1.3,Iris-versicolor
6.3,3.3,6.0,2.5,Iris-virginica
5.8,2.7,5.1,1.9,Iris-virginica

I'm trying to get the prediction but without luck, also I'm not really sure how to pass the recordstring....

record := []string{"5.1, 3.5, 1.4, 0.2"} // Any array of strings
attributes := strings.Join(record, ",")
strReader := bytes.NewReader([]byte(attributes))
hasHeaders := false
fixedDataGrid, err := base.ParseCSVToInstancesFromReader(strReader, hasHeaders)
predictions, err := cls.Predict(fixedDataGrid)
fmt.Println(predictions)
if err != nil {
panic(err)
}
fmt.Println(predictions)

output:
Load our csv data
Initialize our KNN classifier
Perform a training-test split
Calculate the euclidian distance and return the most popular label
<nil>
panic: attributes not compatible

goroutine 1 [running]:
main.main()
	/Users/chris/go-knn/main.go:41 +0x5b1
exit status 2

Any help is really appreciated.

Cheers. Chris.

ch-rigu avatar Apr 20 '21 16:04 ch-rigu

Can I try my hands on this ?

MayukhSobo avatar Aug 10 '21 14:08 MayukhSobo