/
myprogram.go
63 lines (49 loc) · 1.69 KB
/
myprogram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"log"
"os"
"github.com/gonum/floats"
"github.com/gonum/stat"
"github.com/kniren/gota/dataframe"
)
func main() {
// Open the CSV file.
irisFile, err := os.Open("../data/iris.csv")
if err != nil {
log.Fatal(err)
}
defer irisFile.Close()
// Create a dataframe from the CSV file.
irisDF := dataframe.ReadCSV(irisFile)
// Get the float values from the "sepal_length" column as
// we will be looking at the measures for this variable.
sepalLength := irisDF.Col("petal_length").Float()
// Calculate the Max of the variable.
minVal := floats.Min(sepalLength)
// Calculate the Max of the variable.
maxVal := floats.Max(sepalLength)
// Calculate the Median of the variable.
rangeVal := maxVal - minVal
// Calculate the variance of the variable.
varianceVal := stat.Variance(sepalLength, nil)
// Calculate the standard deviation of the variable.
stdDevVal := stat.StdDev(sepalLength, nil)
// Sort the values.
inds := make([]int, len(sepalLength))
floats.Argsort(sepalLength, inds)
// Get the Quantiles.
quant25 := stat.Quantile(0.25, stat.Empirical, sepalLength, nil)
quant50 := stat.Quantile(0.50, stat.Empirical, sepalLength, nil)
quant75 := stat.Quantile(0.75, stat.Empirical, sepalLength, nil)
// Output the results to standard out.
fmt.Printf("\nSepal Length Summary Statistics:\n")
fmt.Printf("Max value: %0.2f\n", maxVal)
fmt.Printf("Min value: %0.2f\n", minVal)
fmt.Printf("Range value: %0.2f\n", rangeVal)
fmt.Printf("Variance value: %0.2f\n", varianceVal)
fmt.Printf("Std Dev value: %0.2f\n", stdDevVal)
fmt.Printf("25 Quantile: %0.2f\n", quant25)
fmt.Printf("50 Quantile: %0.2f\n", quant50)
fmt.Printf("75 Quantile: %0.2f\n\n", quant75)
}