mirror of
https://github.com/sjwhitworth/golearn.git
synced 2025-05-05 19:30:19 +08:00
Remove unused untested ParseCSV function
This commit is contained in:
parent
580913938f
commit
f38fc713ef
47
base/csv.go
47
base/csv.go
@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -211,49 +210,3 @@ func ParseCSVToInstances(filepath string, hasHeaders bool) (instances *DenseInst
|
||||
|
||||
return instances, nil
|
||||
}
|
||||
|
||||
//ParseCSV parses a CSV file and returns the number of columns and rows, the headers, the labels associated with
|
||||
//classification, and the data that will be used for training.
|
||||
func ParseCSV(filepath string, label int, columns []int) (int, int, []string, []string, []float64) {
|
||||
labels := make([]string, 0)
|
||||
data := make([]float64, 0)
|
||||
headers := make([]string, 0)
|
||||
rows := 0
|
||||
|
||||
file, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
reader := csv.NewReader(file)
|
||||
|
||||
headerrow, _ := reader.Read()
|
||||
|
||||
for _, col := range columns {
|
||||
entry := headerrow[col]
|
||||
headers = append(headers, entry)
|
||||
}
|
||||
|
||||
for {
|
||||
record, err := reader.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
}
|
||||
|
||||
//
|
||||
labels = append(labels, record[label])
|
||||
|
||||
//Iterate over our rows and append the values to a slice
|
||||
for _, col := range columns {
|
||||
entry := record[col]
|
||||
number, _ := strconv.ParseFloat(entry, 64)
|
||||
data = append(data, number)
|
||||
}
|
||||
rows++
|
||||
}
|
||||
cols := len(columns)
|
||||
return cols, rows, headers, labels, data
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user