goscore

package module
v0.0.0-...-a24f0a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2022 License: MIT Imports: 8 Imported by: 0

README

Build Status Go Report Card Coverage Status GoDoc

Goscore

Go scoring API for Predictive Model Markup Language (PMML).

Currently supports Neural Network, Decision Tree, Random Forest and Gradient Boosted Models

Will be happy to implement new models by demand, or assist with any other issue.

Contact me here or at aschers@gmail.com.

Tutorial - Deploy Machine Learning Models from R Research to Go Production with PMML

Installation

go get github.com/asafschers/goscore

Usage

Random Forest / Gradient Boosted Model

Generate PMML - R

Fetch model from PMML file -

modelXml, _ := ioutil.ReadFile("fixtures/model.pmml")
var model goscore.RandomForest // or goscore.GradientBoostedModel
xml.Unmarshal([]byte(modelXml), &model)

Set features -

features := map[string]interface{}{
  "Sex": "male",
  "Parch": 0,
  "Age": 30,
  "Fare": 9.6875,
  "Pclass": 2,
  "SibSp": 0,
  "Embarked": "Q",
}

Score features by model -

score, _ := model.Score(features, "1") // gbm.score doesn't recieve label

Score faster -

runtime.GOMAXPROCS(runtime.NumCPU()) // use all cores
score, _ := model.ScoreConcurrently(features, "1") // parallelize tree traversing  

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/asafschers/goscore. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Documentation

Overview

Package goscore is a go scoring API for PMML files

Index

Constants

This section is empty.

Variables

View Source
var ActivationFunctionNotImplemented = errors.New("Activation Function Not Implemented Yet")
View Source
var ActivationFunctions map[string]ActivationFunction
View Source
var NormalizationMethodNotImplemented = errors.New("Normalization Method Not Implemented Yet")
View Source
var NormalizationMethods map[string]NormalizationMethod

Functions

func ArctanActivationFunction

func ArctanActivationFunction(Z float64) float64

func CosineActivationFunction

func CosineActivationFunction(Z float64) float64

func ElliottActivationFunction

func ElliottActivationFunction(Z float64) float64

func ExponentialActivationFunction

func ExponentialActivationFunction(Z float64) float64

func GaussActivationFunction

func GaussActivationFunction(Z float64) float64

func IdentityActivationFunction

func IdentityActivationFunction(b float64) float64

func LogisticActivationFunction

func LogisticActivationFunction(b float64) float64

func ReciprocalActivationFunction

func ReciprocalActivationFunction(Z float64) float64

func RectifierActivationFunction

func RectifierActivationFunction(Z float64) float64

func SineActivationFunction

func SineActivationFunction(Z float64) float64

func SoftmaxNormalizationMethod

func SoftmaxNormalizationMethod(input ...float64) []float64

func SquareActivationFunction

func SquareActivationFunction(Z float64) float64

func TanhActivationFunction

func TanhActivationFunction(b float64) float64

Types

type ActivationFunction

type ActivationFunction func(float64) float64

func NewThresHoldFunction

func NewThresHoldFunction(a float64) ActivationFunction

type Contribution

type Contribution struct {
	From   string  `xml:"from,attr"`
	Weight float64 `xml:"weight,attr"`
}

type DerivedField

type DerivedField struct {
	DataType     string `xml:"dataType,attr"`
	FieldRef     FieldRef
	NormDiscrete NormDiscrete
}

func (*DerivedField) GetInputName

func (d *DerivedField) GetInputName() string

type FieldRef

type FieldRef struct {
	Field string `xml:"field,attr"`
}

type MiningField

type MiningField struct {
	Name string `xml:"name,attr"`
}

type NeuralInputs

type NeuralInputs struct {
	Input []Neuron `xml:"NeuralInput"`
}

type NeuralLayer

type NeuralLayer struct {
	Neuron              []Neuron `xml:"Neuron"`
	ActivationFunction  string   `xml:"activationFunction,attr"`
	NormalizationMethod string   `xml:"normalizationMethod,attr"`
	Threshold           float64  `xml:"threshold,attr"`
}

type NeuralNetWorkStructure

type NeuralNetWorkStructure struct {
}

type NeuralNetwork

type NeuralNetwork struct {
	XMLName xml.Name
	//Struct  NeuralNetWorkStructure `xml:"PMML>NeuralNetwork"`
	InputLayer          NeuralInputs  `xml:"NeuralInputs"`
	NeuralOutputs       NeuralOutputs `xml:"NeuralOutputs"`
	OutputLayer         Outputs       `xml:"Output"`
	Fields              []MiningField `xml:"MiningSchema>MiningField"`
	Layers              []NeuralLayer `xml:"NeuralLayer"`
	ActivationFunction  string        `xml:"activationFunction,attr"`
	NormalizationMethod string        `xml:"normalizationMethod,attr"`
	Threshold           float64       `xml:"threshold,attr"`
}

func NewNeuralNetwork

func NewNeuralNetwork(source []byte) (*NeuralNetwork, error)

func NewNeuralNetworkFromReader

func NewNeuralNetworkFromReader(source io.Reader) (*NeuralNetwork, error)

func (*NeuralNetwork) Score

func (nn *NeuralNetwork) Score(feature map[string]interface{}, outputName string) (float64, error)

type NeuralOutput

type NeuralOutput struct {
	OutputNeuron string       `xml:"outputNeuron,attr"`
	DerivedField DerivedField `xml:"DerivedField"`
}

type NeuralOutputs

type NeuralOutputs struct {
	NeuralOutput []NeuralOutput `xml:"NeuralOutput"`
}

type Neuron

type Neuron struct {
	Id               string         `xml:"id,attr"`
	DerivedFieldType DerivedField   `xml:"DerivedField"`
	Bias             float64        `xml:"bias,attr"`
	Contribution     []Contribution `xml:"Con"`
}

type Node

type Node struct {
	XMLName            xml.Name
	Attrs              []xml.Attr         `xml:",any,attr"`
	Content            []byte             `xml:",innerxml"`
	Nodes              []Node             `xml:",any"`
	True               truePredicate      `xml:"True"`
	DummyMiningSchema  dummyMiningSchema  `xml:"MiningSchema"`
	SimplePredicate    SimplePredicate    `xml:"SimplePredicate"`
	SimpleSetPredicate SimpleSetPredicate `xml:"SimpleSetPredicate"`
}

Node - PMML tree node

func (Node) TraverseTree

func (n Node) TraverseTree(features map[string]interface{}) (score float64, err error)

TraverseTree - traverses Node predicates with features and returns score by terminal node

type NormDiscrete

type NormDiscrete struct {
	Value string `xml:"value,attr"`
}

type NormalizationMethod

type NormalizationMethod func(...float64) []float64

type OutputField

type OutputField struct {
	Name  string `xml:"name,attr"`
	Value string `xml:"value,attr"`
}

type Outputs

type Outputs struct {
	OutputField []OutputField `xml:"OutputField"`
}

type PMMLNN

type PMMLNN struct {
	NeuralNetwork NeuralNetwork `xml:"NeuralNetwork"`
}

type SimplePredicate

type SimplePredicate struct {
	Field    string `xml:"field,attr"`
	Operator string `xml:"operator,attr"`
	Value    string `xml:"value,attr"`
}

SimplePredicate - PMML simple predicate

func (SimplePredicate) True

func (p SimplePredicate) True(features map[string]interface{}) bool

True - Evaluates to true if features input is true for SimplePredicate

type SimpleSetPredicate

type SimpleSetPredicate struct {
	Field    string `xml:"field,attr"`
	Operator string `xml:"booleanOperator,attr"`
	Values   string `xml:"Array"`
}

SimpleSetPredicate - PMML simple set predicate

func (SimpleSetPredicate) True

func (p SimpleSetPredicate) True(features map[string]interface{}) bool

True - Evaluates to true if features input is true for SimpleSetPredicate

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL