ctr

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AUC

func AUC(posPrediction, negPrediction []float32) float32

func Accuracy

func Accuracy(posPrediction, negPrediction []float32) float32

func LoadLibFMFile

func LoadLibFMFile(path string) (features [][]lo.Tuple2[int32, float32], targets []float32, maxLabel int32, err error)

LoadLibFMFile loads libFM format file.

func MarshalModel

func MarshalModel(w io.Writer, m FactorizationMachines) error

func Precision

func Precision(posPrediction, negPrediction []float32) float32

func Recall

func Recall(posPrediction, _ []float32) float32

Types

type BaseFactorizationMachines

type BaseFactorizationMachines struct {
	model.BaseModel
	Index dataset.UnifiedIndex
}

func (*BaseFactorizationMachines) Init

func (b *BaseFactorizationMachines) Init(trainSet dataset.CTRSplit)

type BatchInference

type BatchInference interface {
	BatchPredict(inputs []lo.Tuple4[string, string, []Label, []Label], jobs int) []float32
	BatchInternalPredict(x []lo.Tuple2[[]int32, []float32], jobs int) []float32
}

type Dataset

type Dataset struct {
	Index                  dataset.UnifiedIndex
	UserLabels             [][]lo.Tuple2[int32, float32]
	ItemLabels             [][]lo.Tuple2[int32, float32]
	ContextLabels          [][]lo.Tuple2[int32, float32]
	Users                  []int32
	Items                  []int32
	Target                 []float32
	ItemEmbeddings         [][][]float32
	ItemEmbeddingDimension []int
	ItemEmbeddingIndex     *dataset.Index
	PositiveCount          int
	NegativeCount          int
}

Dataset for click-through-rate models.

func LoadDataFromBuiltIn

func LoadDataFromBuiltIn(name string) (train, test *Dataset, err error)

LoadDataFromBuiltIn loads built-in dataset.

func (*Dataset) Count

func (dataset *Dataset) Count() int

Count returns the number of samples.

func (*Dataset) CountContextLabels

func (dataset *Dataset) CountContextLabels() int

func (*Dataset) CountItemLabels

func (dataset *Dataset) CountItemLabels() int

func (*Dataset) CountItems

func (dataset *Dataset) CountItems() int

CountItems returns the number of items.

func (*Dataset) CountNegative

func (dataset *Dataset) CountNegative() int

func (*Dataset) CountPositive

func (dataset *Dataset) CountPositive() int

func (*Dataset) CountUserLabels

func (dataset *Dataset) CountUserLabels() int

func (*Dataset) CountUsers

func (dataset *Dataset) CountUsers() int

CountUsers returns the number of users.

func (*Dataset) Get

func (dataset *Dataset) Get(i int) ([]int32, []float32, float32)

Get returns the i-th sample.

func (*Dataset) GetIndex

func (dataset *Dataset) GetIndex() dataset.UnifiedIndex

func (*Dataset) GetTarget

func (dataset *Dataset) GetTarget(i int) float32

func (*Dataset) Split

func (dataset *Dataset) Split(ratio float32, seed int64) (*Dataset, *Dataset)

Split a dataset to training set and test set.

type Embedding

type Embedding struct {
	Name  string
	Value []float32
}

func ConvertEmbeddings

func ConvertEmbeddings(o any) []Embedding

type FMV2

type FMV2 struct {
	BaseFactorizationMachines

	// parameters
	B *nn.Tensor
	W nn.Layer
	V nn.Layer
	// contains filtered or unexported fields
}

func NewFMV2

func NewFMV2(params model.Params) *FMV2

func (*FMV2) BatchInternalPredict

func (fm *FMV2) BatchInternalPredict(x []lo.Tuple2[[]int32, []float32], jobs int) []float32

func (*FMV2) BatchPredict

func (fm *FMV2) BatchPredict(inputs []lo.Tuple4[string, string, []Label, []Label], jobs int) []float32

func (*FMV2) Clear

func (fm *FMV2) Clear()

func (*FMV2) Fit

func (fm *FMV2) Fit(ctx context.Context, trainSet, testSet dataset.CTRSplit, config *FitConfig) Score

func (*FMV2) Forward

func (fm *FMV2) Forward(indices, values *nn.Tensor, jobs int) *nn.Tensor

func (*FMV2) Init

func (fm *FMV2) Init(trainSet dataset.CTRSplit)

func (*FMV2) InternalPredict

func (fm *FMV2) InternalPredict(_ []int32, _ []float32) float32

func (*FMV2) Invalid

func (fm *FMV2) Invalid() bool

func (*FMV2) Marshal

func (fm *FMV2) Marshal(w io.Writer) error

func (*FMV2) Parameters

func (fm *FMV2) Parameters() []*nn.Tensor

func (*FMV2) Predict

func (fm *FMV2) Predict(_, _ string, _, _ []Label) float32

func (*FMV2) SetParams

func (fm *FMV2) SetParams(params model.Params)

func (*FMV2) SuggestParams

func (fm *FMV2) SuggestParams(trial goptuna.Trial) model.Params

func (*FMV2) Unmarshal

func (fm *FMV2) Unmarshal(r io.Reader) error

type FactorizationMachineCloner

type FactorizationMachineCloner interface {
	Clone() FactorizationMachines
}

type FactorizationMachineSpawner

type FactorizationMachineSpawner interface {
	Spawn() FactorizationMachines
}

type FactorizationMachines

type FactorizationMachines interface {
	model.Model
	Predict(userId, itemId string, userFeatures, itemFeatures []Label) float32
	InternalPredict(x []int32, values []float32) float32
	Fit(ctx context.Context, trainSet, testSet dataset.CTRSplit, config *FitConfig) Score
	Marshal(w io.Writer) error
}

func UnmarshalModel

func UnmarshalModel(r io.Reader) (FactorizationMachines, error)

type FitConfig

type FitConfig struct {
	Jobs     int
	Verbose  int
	Patience int
}

func NewFitConfig

func NewFitConfig() *FitConfig

func (*FitConfig) LoadDefaultIfNil

func (config *FitConfig) LoadDefaultIfNil() *FitConfig

func (*FitConfig) SetJobs

func (config *FitConfig) SetJobs(jobs int) *FitConfig

func (*FitConfig) SetPatience

func (config *FitConfig) SetPatience(patience int) *FitConfig

func (*FitConfig) SetVerbose

func (config *FitConfig) SetVerbose(verbose int) *FitConfig

type Label

type Label struct {
	Name  string
	Value float32
}

func ConvertLabels

func ConvertLabels(o any) []Label

type ModelCreator

type ModelCreator func() FactorizationMachines

type ModelSearch

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

func NewModelSearch

func NewModelSearch(models map[string]ModelCreator, trainSet, testSet dataset.CTRSplit, config *FitConfig) *ModelSearch

func (*ModelSearch) Objective

func (ms *ModelSearch) Objective(trial goptuna.Trial) (float64, error)

func (*ModelSearch) Result

func (ms *ModelSearch) Result() meta.Model[Score]

func (*ModelSearch) WithContext

func (ms *ModelSearch) WithContext(ctx context.Context) *ModelSearch

func (*ModelSearch) WithSpan

func (ms *ModelSearch) WithSpan(span *monitor.Span) *ModelSearch

type Score

type Score struct {
	RMSE      float32
	Precision float32
	Recall    float32
	Accuracy  float32
	AUC       float32
}

func EvaluateClassification

func EvaluateClassification(estimator FactorizationMachines, testSet dataset.CTRSplit, jobs int) Score

EvaluateClassification evaluates factorization machines in classification task.

func EvaluateRegression

func EvaluateRegression(estimator FactorizationMachines, testSet *Dataset) Score

EvaluateRegression evaluates factorization machines in regression task.

func (Score) BetterThan

func (score Score) BetterThan(s Score) bool

func (Score) GetValue

func (score Score) GetValue() float32

func (Score) ZapFields

func (score Score) ZapFields() []zap.Field

Jump to

Keyboard shortcuts

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