diff --git a/base/csv.go b/base/csv.go index 307cfc2..c782036 100644 --- a/base/csv.go +++ b/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 -}