forked from sjwhitworth/golearn
/
domain.go
46 lines (39 loc) · 993 Bytes
/
domain.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
// Package base provides base interfaces for GoLearn objects to implement.
// It also provides a raw base for those objects.
package base
import (
"bytes"
"encoding/gob"
"io/ioutil"
"gonum.org/v1/gonum/mat"
)
// An Estimator is object that can ingest some data and train on it.
type Estimator interface {
Fit()
}
// A Predictor is an object that provides predictions.
type Predictor interface {
Predict()
}
// A Model is a supervised learning object, that is
// possible of scoring accuracy against a test set.
type Model interface {
Score()
}
type BaseEstimator struct {
Data *mat.Dense
}
// SaveEstimatorToGob serialises an estimator to a provided filepath, in gob format.
// See http://golang.org/pkg/encoding/gob for further details.
func SaveEstimatorToGob(path string, e *Estimator) {
b := new(bytes.Buffer)
enc := gob.NewEncoder(b)
err := enc.Encode(e)
if err != nil {
panic(err)
}
err = ioutil.WriteFile(path, b.Bytes(), 0644)
if err != nil {
panic(err)
}
}