1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-28 13:48:56 +08:00

error strings should not be capitalized

This commit is contained in:
Niclas Jern 2014-07-18 14:00:22 +03:00
parent 90106077cc
commit 13da7d0cac

View File

@ -15,10 +15,10 @@ func shuffleMatrix(returnDatasets []*mat.Dense, dataset mat.Matrix, testSize int
shuffledSet := mat.DenseCopyOf(dataset) shuffledSet := mat.DenseCopyOf(dataset)
rowCount, colCount := shuffledSet.Dims() rowCount, colCount := shuffledSet.Dims()
temp := make([]float64, colCount) temp := make([]float64, colCount)
// FisherYates shuffle // FisherYates shuffle
for i := 0; i < rowCount; i++ { for i := 0; i < rowCount; i++ {
j := numGen.Intn(i+1) j := numGen.Intn(i + 1)
if j != i { if j != i {
// Make a "hard" copy to avoid pointer craziness. // Make a "hard" copy to avoid pointer craziness.
copy(temp, shuffledSet.RowView(i)) copy(temp, shuffledSet.RowView(i))
@ -43,29 +43,29 @@ func TrainTestSplit(size interface{}, randomState interface{}, datasets ...*mat.
// Input should be one or two matrices. // Input should be one or two matrices.
dataCount := len(datasets) dataCount := len(datasets)
if dataCount > 2 { if dataCount > 2 {
return nil, fmt.Errorf("Expected 1 or 2 datasets, got %d\n", dataCount) return nil, fmt.Errorf("expected 1 or 2 datasets, got %d\n", dataCount)
} }
if dataCount == 2 { if dataCount == 2 {
// Test for consistency. // Test for consistency.
labelCount, labelFeatures := datasets[1].Dims() labelCount, labelFeatures := datasets[1].Dims()
if labelCount != instanceCount { if labelCount != instanceCount {
return nil, fmt.Errorf("Data and labels must have the same number of instances") return nil, fmt.Errorf("data and labels must have the same number of instances")
} else if labelFeatures != 1 { } else if labelFeatures != 1 {
return nil, fmt.Errorf("Label matrix must have single feature") return nil, fmt.Errorf("label matrix must have single feature")
} }
} }
var testSize int var testSize int
switch size := size.(type) { switch size := size.(type) {
// If size is an integer, treat it as the test data instance count. // If size is an integer, treat it as the test data instance count.
case int: case int:
testSize = size testSize = size
case float64: case float64:
// If size is a float, treat it as a percentage of the instances to be allocated to the test set. // If size is a float, treat it as a percentage of the instances to be allocated to the test set.
testSize = int(float64(instanceCount)*size + 0.5) testSize = int(float64(instanceCount)*size + 0.5)
default: default:
return nil, fmt.Errorf("Expected a test instance count (int) or percentage (float64)") return nil, fmt.Errorf("expected a test instance count (int) or percentage (float64)")
} }
var randSeed int64 var randSeed int64