modelfox
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
ModelFox for Go
The ModelFox Go module makes it easy to make predictions with your ModelFox machine learning model from Go.
Usage
$ go get -u github.com/modelfoxdotdev/modelfox-go
import "github.com/modelfoxdotdev/modelfox-go"model, _ := modelfox.LoadModelFromPath("./heart_disease.modelfox", nil)defer model.Destroy()input := modelfox.PredictInput{ "age": 63, "gender": "male", // ...}output := model.PredictOne(input, nil)fmt.Println("Output:", output.ClassName)
For more information,read the docs.
Platform Support
ModelFox for Go is currently supported on the following combinations of$GOARCH
and$GOOS
:
amd64
linux
arm64
linux
amd64
darwin
arm64
darwin
amd64
windows
Are you interested in another platform?Open an issue or send us an email athelp@modelfox.dev.
ModelFox for Go links to the modelfox C library, so cgo is required. The modelfox C library will be linked statically into your executable, so when you rungo build
you will still get a statically linked executable you can run anywhere without having to worry about dynamic linking errors.
Examples
The source for this package contains a number of examples in theexamples
directory. Each example has aREADME.md
explaining how to run it.
Documentation¶
Index¶
- Constants
- func Version() string
- type BagOfWordsCosineSimilarityFeatureContribution
- type BagOfWordsFeatureContribution
- type Bigram
- type BinaryClassificationPredictOutput
- type FeatureContributionEntry
- type FeatureContributionType
- type FeatureContributions
- type IdentityFeatureContribution
- type LoadModelOptions
- type LogPredictionArgs
- type LogTrueValueArgs
- type Model
- func (m Model) Destroy()
- func (m Model) EnqueueLogPrediction(args LogPredictionArgs)
- func (m Model) EnqueueLogTrueValue(args LogTrueValueArgs)
- func (m Model) FlushLogQueue() error
- func (m Model) ID() string
- func (m Model) LogPrediction(args LogPredictionArgs) error
- func (m Model) LogTrueValue(args LogTrueValueArgs) error
- func (m Model) Predict(input []PredictInput, options *PredictOptions) []PredictOutput
- func (m Model) PredictOne(input PredictInput, options *PredictOptions) PredictOutput
- type MulticlassClassificationPredictOutput
- type NGram
- type NormalizedFeatureContribution
- type OneHotEncodedFeatureContribution
- type PredictInput
- type PredictOptions
- type PredictOutput
- type RegressionPredictOutput
- type TaskType
- type Unigram
- type WordEmbeddingFeatureContribution
Constants¶
const (RegressionTaskType =iotaBinaryClassificationTaskTypeMulticlassClassificationTaskType)
const (// IdentityFeatureContributionType is the feature contribution type of an identity feature group.IdentityFeatureContributionType =iota// NormalizedFeatureContributionType is the feature contribution type of a normalized feature group.NormalizedFeatureContributionType// OneHotEncodedFeatureContributionType is the feature contribution type of a one hot encoded feature group.OneHotEncodedFeatureContributionType// BagOfWordsFeatureContributionType is the feature contribution type of a bag of words feature group.BagOfWordsFeatureContributionType// BagOfWordsCosineSimilarityFeatureContributionType is the feature contribution type of a bag of words cosine similarity feature group.BagOfWordsCosineSimilarityFeatureContributionType// WordEmbeddingFeatureContributionType is the feature contribution type of a word embedding feature group.WordEmbeddingFeatureContributionType)
const (UnigramType =iotaBigramType)
Variables¶
This section is empty.
Functions¶
Types¶
typeBagOfWordsCosineSimilarityFeatureContribution¶
type BagOfWordsCosineSimilarityFeatureContribution struct {// This is the name of the source column a for the feature group.ColumnNameAstring// This is the name of the source column b for the feature group.ColumnNameBstring// This is the value of the feature.FeatureValuefloat32// This is the amount that the feature contributed to the output.FeatureContributionValuefloat32}
This describes the contribution of a feature from a bag of words cosine similarity feature group.
typeBagOfWordsFeatureContribution¶
type BagOfWordsFeatureContribution struct {// This is the name of the source column for the feature group.ColumnNamestring// This is the ngram for the feature.NGramNGram// This is the value of the feature.FeatureValuefloat32// This is the amount that the feature contributed to the output.FeatureContributionValuefloat32}
This describes the contribution of a feature from a bag of words feature group.
typeBigram¶
type Bigram struct {// This is the first token in the bigram.TokenAstring// This is the second token in the bigram.TokenBstring}
This describes a bigram ngram.
typeBinaryClassificationPredictOutput¶
type BinaryClassificationPredictOutput struct {// This is the name of the predicted class.ClassNamestring `json:"className"`// This is the probability the model assigned to the predicted class.Probabilityfloat32 `json:"probability"`// If computing feature contributions was enabled in the predict options, this value will explain the model's output, showing how much each feature contributed to the output.FeatureContributionsFeatureContributions `json:"-"`}
`Predict` outputs `BinaryClassificationPredictOutput` when the model's task is regression.
typeFeatureContributionEntry¶
type FeatureContributionEntry interface {// contains filtered or unexported methods}
FeatureContribution represents a feature contribution.
typeFeatureContributionType¶
type FeatureContributionTypeint
This identifies the type of a feature contribution.
typeFeatureContributions¶
type FeatureContributions struct {// This is the value the model would output if all features had baseline values.BaselineValuefloat32// This is the value the model output. Any difference from the `baseline_value` is because of the deviation of the features from their baseline values.OutputValuefloat32// This list will contain one entry for each of the model's features. Note that features are computed from columns, so there will likely be more features than columns.Entries []FeatureContributionEntry}
This is a description of the feature contributions for the prediction if the task is regression or binary classification, or for a single class if the task is multiclass classification.
typeIdentityFeatureContribution¶
type IdentityFeatureContribution struct {// This is the name of the source column for the feature group.ColumnNamestring// This is the value of the feature.FeatureValuefloat32// This is the amount that the feature contributed to the output.FeatureContributionValuefloat32}
This describes the contribution of a feature from an identity feature group
typeLoadModelOptions¶
type LoadModelOptions struct {// If you are running the app locally or on your own server, use this field to provide the url to it. If not specified, the default value ishttps://app.modelfox.dev.ModelFoxURLstring}
These are the options passed when loading a model.
typeLogPredictionArgs¶
type LogPredictionArgs struct {// This is a unique identifier for the prediction, which will associate it with a true value event and allow you to look it up in the app.Identifierstring// This is the same `PredictInput` value that you passed to `model.Predict`.InputPredictInput// This is the same `PredictOptions` value that you passed to `model.Predict`.OptionsPredictOptions// This is the output returned by `model.Predict`.OutputPredictOutput}
This is the type of the argument to `model.LogPrediction` and `model.EnqueueLogPrediction` which specifies the details of the prediction to log.
typeLogTrueValueArgs¶
type LogTrueValueArgs struct {// This is a unique identifier for the prediction, which will associate it with a true value event and allow you to look it up in the app.Identifierstring// This is the true value for the prediction.TrueValue interface{}}
This is the type of the argument to `model.LogTrueValue` and `model.EnqueueLogTrueValue` which specifies the details of the true value to log.
typeModel¶
type Model struct {// contains filtered or unexported fields}
Use this struct to load a model, make predictions, and log events to the app.
funcLoadModelFromBytes¶
func LoadModelFromBytes(data []byte, options *LoadModelOptions) (*Model,error)
Load a model from bytes instead of a file. You should use this only if you already have a `.modelfox` loaded into memory. Otherwise, use `model.LoadModelFromPath`, which is faster because it memory maps the file.
funcLoadModelFromPath¶
func LoadModelFromPath(pathstring, options *LoadModelOptions) (*Model,error)
Load a model from a `.modelfox` file at `path`.
func (Model)Destroy¶
func (mModel) Destroy()
Destroy frees up the memory used by the model. You should call this with defer after loading your model.
func (Model)EnqueueLogPrediction¶
func (mModel) EnqueueLogPrediction(argsLogPredictionArgs)
Add a prediction event to the queue. Remember to call `model.FlushLogQueue` at a later point to send the event to the app.
func (Model)EnqueueLogTrueValue¶
func (mModel) EnqueueLogTrueValue(argsLogTrueValueArgs)
Add a true value event to the queue. Remember to call `model.FlushLogQueue` at a later point to send the event to the app.
func (Model)FlushLogQueue¶
Send all events in the queue to the app.
func (Model)LogPrediction¶
func (mModel) LogPrediction(argsLogPredictionArgs)error
Send a prediction event to the app. If you want to batch events, you can use `model.EnqueueLogPrediction` instead.
func (Model)LogTrueValue¶
func (mModel) LogTrueValue(argsLogTrueValueArgs)error
Send a true value event to the app. If you want to batch events, you can use `model.EnqueueLogTrueValue` instead.
func (Model)Predict¶
func (mModel) Predict(input []PredictInput, options *PredictOptions) []PredictOutput
Make a prediction with multiple inputs.
func (Model)PredictOne¶
func (mModel) PredictOne(inputPredictInput, options *PredictOptions)PredictOutput
Make a prediction with a single input.
typeMulticlassClassificationPredictOutput¶
type MulticlassClassificationPredictOutput struct {// This is the name of the predicted class.ClassNamestring `json:"className`// This is the probability the model assigned to the predicted class.Probabilityfloat32 `json:"probability"`// This value maps from class names to the probability the model assigned to each class.Probabilities map[string]float32 `json:"probabilities"`// If computing feature contributions was enabled in the predict options, this value will explain the model's output, showing how much each feature contributed to the output. This value maps from class names to `FeatureContributions` values for each class. The class with the `FeatureContributions` value with the highest `output_value` is the predicted class.FeatureContributions map[string]FeatureContributions `json:"-"`}
`Predict` outputs `MulticlassClassificationPredictOutput` when the model's task is regression.
typeNGram¶
type NGram interface {// contains filtered or unexported methods}
NGram is the token type in a bag of words feature group.
typeNormalizedFeatureContribution¶
type NormalizedFeatureContribution struct {// This is the name of the source column for the feature group.ColumnNamestring// This is the value of the feature.FeatureValuefloat32// This is the amount that the feature contributed to the output.FeatureContributionValuefloat32}
This describes the contribution of a feature from a normalized feature group.
typeOneHotEncodedFeatureContribution¶
type OneHotEncodedFeatureContribution struct {// This is the name of the source column for the feature group.ColumnNamestring// This is the enum variant the feature indicates the presence of.Variantstring// This is the value of the feature.FeatureValuebool// This is the amount that the feature contributed to the output.FeatureContributionValuefloat32}
This describes the contribution of a feature from a one hot encoded feature group.
typePredictInput¶
type PredictInput map[string]interface{}
This is the input type of `Predict`. A predict input is a map from strings to strings or floats. The keys should match the columns in the CSV file you trained your model with.
typePredictOptions¶
type PredictOptions struct {// If your model is a binary classifier, use this field to make predictions using a threshold chosen on the tuning page of the app. The default value is `0.5`.Thresholdfloat32 `json:"threshold"`// Computing feature contributions is disabled by default. If you set this field to `true`, you will be able to access the feature contributions with the `feature_contributions` field of the predict output.ComputeFeatureContributionsbool `json:"computeFeatureContributions"`}
These are the options passed to `Predict`.
typePredictOutput¶
type PredictOutput interface {// contains filtered or unexported methods}
This is the return type of `Predict`.
typeRegressionPredictOutput¶
type RegressionPredictOutput struct {// This is the predicted value.Valuefloat32 `json:"value"`// If computing feature contributions was enabled in the predict options, this value will explain the model's output, showing how much each feature contributed to the output.FeatureContributionsFeatureContributions `json:"-"`}
`Predict` outputs `RegressionPredictOutput` when the model's task is regression.
typeTaskType¶
type TaskTypeint
TaskType is the type of the task corresponding to the model task, one of RegressionTaskType, BinaryClassificationTaskType, and MulticlassClassificationTaskType.
typeWordEmbeddingFeatureContribution¶
type WordEmbeddingFeatureContribution struct {// This is the name of the source column for the feature group.ColumnNamestring// This is the index of the feature in the word embedding.ValueIndexint// This is the amount that the feature contributed to the output.FeatureContributionValuefloat32}
This describes the contribution of a feature from a word embedding feature group.