Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forests get Type, so Predict can be generic. #25

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion applyforest/applyforest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {
var sum bool
flag.BoolVar(&sum, "sum", false, "Force numeric sum voting (for gradient boosting etc).")
var expit bool
flag.BoolVar(&expit, "expit", false, "Expit (inverst logit) transform data (for gradient boosting classification).")
flag.BoolVar(&expit, "expit", false, "Expit (inverse logit) transform data (for gradient boosting classification).")
var cat bool
flag.BoolVar(&cat, "mode", false, "Force categorical (mode) voting.")

Expand All @@ -46,6 +46,10 @@ func main() {
if err != nil {
log.Fatal(err)
}
if forest.PredCfg.Gradboost != 0 {
sum = true
}
fmt.Printf("Forest is of type %v.\n", forest.Type.String())

var predfile *os.File
if *predfn != "" {
Expand Down
6 changes: 6 additions & 0 deletions catballotbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ func (bb *CatBallotBox) TallyError(feature Feature) float64 {
e = 1.0 - e
return e
}

// TallyNum always returns NaN for a SumBallotBox; we
// meet the demands of the expanded VoteTallyer interface.
func (bb *CatBallotBox) TallyNum(i int) (predicted float64) {
return nan
}
73 changes: 73 additions & 0 deletions cfpred/cfpred.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"flag"
"fmt"
"log"
"os"

"github.com/lytics/CloudForest"
)

func main() {
fm := flag.String("fm",
"featurematrix.afm", "AFM formated feature matrix containing data.")
rf := flag.String("rfpred",
"rface.sf", "A predictor forest.")
predfn := flag.String("preds",
"", "The name of a file to write the predictions into.")

flag.Parse()

//Parse Data
data, err := CloudForest.LoadAFM(*fm)
if err != nil {
log.Fatal(err)
}

forestfile, err := os.Open(*rf) // For read access.
if err != nil {
log.Fatal(err)
}
defer forestfile.Close()
forestreader := CloudForest.NewForestReader(forestfile)
forest, err := forestreader.ReadForest()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Forest is of type %v.\n", forest.Type.String())

var predfile *os.File
if *predfn != "" {
predfile, err = os.Create(*predfn)
if err != nil {
log.Fatal(err)
}
defer predfile.Close()
}
targeti, hasTarget := data.Map[forest.Target]

preds, err := CloudForest.Predict(data, forest)
if err != nil {
log.Fatal(err)
}
if *predfn != "" {
fmt.Printf("Outputting label predicted actual tsv to %v\n", *predfn)
for i, l := range data.CaseLabels {
actual := "NA"
if hasTarget {
actual = data.Data[targeti].GetStr(i)
}

var result string
if preds.IsReal {
result = fmt.Sprintf("%v", preds.Real[i])
} else {
result = preds.Cat[i]
}

fmt.Fprintf(predfile, "%v\t%v\t%v\n", l, result, actual)
}
}

}
Loading