Documentation

Overview

    Package classificationbox provides a client for accessing Classificationbox services.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Class

    type Class struct {
    	// ID is the class being predicted.
    	ID string `json:"id,omitempty"`
    	// Score is a numerical value indicating how this prediction relates
    	// to other predictions.
    	Score float64 `json:"score,omitempty"`
    }

      Class is a predicted choice.

      type ClassStats

      type ClassStats struct {
      	// Name is the name of the class.
      	Name string
      	// Examples is the number of examples of this class that
      	// the model has been taught.
      	Examples int
      }

        ClassStats contains per-class statistics.

        type Client

        type Client struct {
        	// contains filtered or unexported fields
        }

          Client is an HTTP client that can make requests to the box.

          func New

          func New(addr string) *Client

            New makes a new Client for the box at the specified address.

            func (*Client) CreateModel

            func (c *Client) CreateModel(ctx context.Context, model Model) (Model, error)

              CreateModel creates the Model in Classificationbox. If no ID is set, one will be assigned in the return Model.

              func (*Client) DeleteModel

              func (c *Client) DeleteModel(ctx context.Context, modelID string) error

                DeleteModel deletes a Model by its ID.

                func (*Client) GetModel

                func (c *Client) GetModel(ctx context.Context, modelID string) (Model, error)

                  GetModel gets a Model by its ID.

                  func (*Client) GetModelStats

                  func (c *Client) GetModelStats(ctx context.Context, modelID string) (ModelStats, error)

                    GetModelStats gets the statistics for the specified model.

                    func (*Client) Info

                    func (c *Client) Info() (*boxutil.Info, error)

                      Info gets the details about the box.

                      func (*Client) ListModels

                      func (c *Client) ListModels(ctx context.Context) ([]Model, error)

                        ListModels gets all models.

                        func (*Client) OpenState

                        func (c *Client) OpenState(ctx context.Context, modelID string) (io.ReadCloser, error)

                          OpenState opens the state file for the specified model for reading. Clients must call Close.

                          func (*Client) PostState

                          func (c *Client) PostState(ctx context.Context, r io.Reader, predictOnly bool) (Model, error)

                            PostState uploads new state data and returns the Model that was contained in the state file.

                            func (*Client) PostStateURL

                            func (c *Client) PostStateURL(ctx context.Context, stateURL *url.URL, predictOnly bool) (Model, error)

                              PostStateURL tells Classificationbox to download the state file specified by the URL and returns the Model that was contained in the state file.

                              func (*Client) Predict

                              func (c *Client) Predict(ctx context.Context, modelID string, request PredictRequest) (PredictResponse, error)

                                Predict asks a Model to make a prediction.

                                func (*Client) SetClient

                                func (c *Client) SetClient(client *http.Client)

                                  SetClient sets the http.Client to use when making requests.

                                  func (*Client) Teach

                                  func (c *Client) Teach(ctx context.Context, modelID string, example Example) error

                                    Teach gives an Example to a model for it to learn from.

                                    func (*Client) TeachMulti

                                    func (c *Client) TeachMulti(ctx context.Context, modelID string, examples []Example) error

                                      TeachMulti gives an multiple Example to a model for it to learn from.

                                      type Example

                                      type Example struct {
                                      	Class  string    `json:"class"`
                                      	Inputs []Feature `json:"inputs"`
                                      }

                                        Example is a set of Feature properties with their associated Class which is used to teach Classificationbox models.

                                        type Feature

                                        type Feature struct {
                                        	// Key is the name of the Feature.
                                        	Key string `json:"key"`
                                        	// Value is the string value of this Feature.
                                        	Value string `json:"value"`
                                        	// Type is the type of the Feature.
                                        	// Can be "number", "text", "keyword", "list", "image_url" or "image_base64"..
                                        	Type string `json:"type"`
                                        }

                                          Feature represents a single feature, to describe an input.

                                          func FeatureImageBase64

                                          func FeatureImageBase64(key string, data string) Feature

                                            FeatureImageBase64 makes a Feature that is a base64 encoded image.

                                            func FeatureImageURL

                                            func FeatureImageURL(key string, url string) Feature

                                              FeatureImageURL makes a Feature that points to a hosted image.

                                              func FeatureKeyword

                                              func FeatureKeyword(key string, keyword string) Feature

                                                FeatureKeyword makes a textual Feature that will not be tokenized. Use FeatureList to provide multiple keywords in a single Feature. Use Text for bodies of text that should be tokenized.

                                                func FeatureList

                                                func FeatureList(key string, keywords ...string) Feature

                                                  FeatureList makes a Feature made up of multiple keywords.

                                                  func FeatureNumber

                                                  func FeatureNumber(key string, value float64) Feature

                                                    FeatureNumber makes a numerical Feature.

                                                    func FeatureText

                                                    func FeatureText(key string, text string) Feature

                                                      FeatureText makes a textual Feature that will be tokenized. Use FeatureKeyword for values that should not be tokenized.

                                                      type Model

                                                      type Model struct {
                                                      	// ID is the ID of the model.
                                                      	ID string `json:"id,omitempty"`
                                                      	// Name is the human readable name of the Model.
                                                      	Name string `json:"name"`
                                                      	// Options are optional Model settings to adjust the behaviour
                                                      	// of this Model within Classificationbox.
                                                      	Options *ModelOptions `json:"options,omitempty"`
                                                      	// Classes are the classes that this model can learn.
                                                      	Classes []string `json:"classes,omitempty"`
                                                      }

                                                        Model represents a single model inside Classificationbox.

                                                        func NewModel

                                                        func NewModel(id, name string, classes ...string) Model

                                                          NewModel creates a new Model.

                                                          type ModelOptions

                                                          type ModelOptions struct {
                                                          	// Ngrams describes the n-grams for text analysis.
                                                          	Ngrams int `json:"ngrams,omitempty"`
                                                          	// Skipgrams describes the skip-grams for the text analysis.
                                                          	Skipgrams int `json:"skipgrams,omitempty"`
                                                          }

                                                            ModelOptions describes the behaviours of a Model.

                                                            type ModelStats

                                                            type ModelStats struct {
                                                            	// Predictions is the number of predictions this model has made.
                                                            	Predictions int
                                                            	// Examples is the total number of examples this model has
                                                            	// been taught.
                                                            	Examples int
                                                            	// Classes is a list of statistics per class.
                                                            	Classes []ClassStats
                                                            }

                                                              ModelStats are the statistics for a Model.

                                                              type PredictRequest

                                                              type PredictRequest struct {
                                                              	// Limit sets the maximum number of classes that will be returned
                                                              	// in a prediction.
                                                              	Limit int `json:"limit"`
                                                              	// Inputs is a list of Feature objects that will be used when
                                                              	// making the prediction.
                                                              	Inputs []Feature `json:"inputs,omitempty"`
                                                              }

                                                                PredictRequest contains information about the prediction that Classificationbox will make.

                                                                type PredictResponse

                                                                type PredictResponse struct {
                                                                	// Classes contains the predictions.
                                                                	Classes []Class `json:"classes,omitempty"`
                                                                }

                                                                  PredictResponse contains prediction choices.