Open trayanr opened 6 years ago
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.
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?
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.
Interesting... Gota didn't really exist when this project got going, but I'd say it's worth looking into.
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.
In mnist example, I want load a Image then convert it into test data,How?
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 record
string....
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.
Can I try my hands on this ?
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?