class_docstr: Field-weighted Factorization Machine for binary classification.
  
  The model equation is defined as:
  
  $$\hat{y}(x) = w_{0} + \sum_{j=1}^{p} w_{j} x_{j}  + \sum_{j=1}^{p} \sum_{j'=j+1}^{p} r_{f_j, f_{j'}} \langle \mathbf{v}_j, \mathbf{v}_{j'} \rangle x_{j} x_{j'}$$
  
  Where $f_j$ and $f_{j'}$ are $j$ and $j'$ fields, respectively, and $\mathbf{v}_j$ and
  $\mathbf{v}_{j'}$ are $j$ and $j'$ latent vectors, respectively.
  
  For more efficiency, this model automatically one-hot encodes strings features considering them
  as categorical variables. Field names are inferred from feature names by taking everything
  before the first underscore: `feature_name.split('_')[0]`.
  
  Parameters
  ----------
  n_factors
      Dimensionality of the factorization or number of latent factors.
  weight_optimizer
      The sequential optimizer used for updating the feature weights. Note that the intercept is
      handled separately.
  latent_optimizer
      The sequential optimizer used for updating the latent factors.
  int_weight_optimizer
      The sequential optimizer used for updating the field pairs interaction weights.
  loss
      The loss function to optimize for.
  sample_normalization
      Whether to divide each element of `x` by `x`'s L2-norm.
  l1_weight
      Amount of L1 regularization used to push weights towards 0.
  l2_weight
      Amount of L2 regularization used to push weights towards 0.
  l1_latent
      Amount of L1 regularization used to push latent weights towards 0.
  l2_latent
      Amount of L2 regularization used to push latent weights towards 0.
  intercept
      Initial intercept value.
  intercept_lr
      Learning rate scheduler used for updating the intercept. An instance of
      `optim.schedulers.Constant` is used if a `float` is passed. No intercept will be used
      if this is set to 0.
  weight_initializer
      Weights initialization scheme. Defaults to `optim.initializers.Zeros()`.
  latent_initializer
      Latent factors initialization scheme. Defaults to
      `optim.initializers.Normal(mu=.0, sigma=.1, random_state=self.random_state)`.
  clip_gradient
      Clips the absolute value of each gradient value.
  seed
      Randomization seed used for reproducibility.
  
  Attributes
  ----------
  weights
      The current weights assigned to the features.
  latents
      The current latent weights assigned to the features.
  interaction_weights
      The current interaction strengths of field pairs.
  
  Examples
  --------
  
  >>> from river import facto
  
  >>> dataset = (
  ...     ({'user': 'Alice', 'item': 'Superman'}, True),
  ...     ({'user': 'Alice', 'item': 'Terminator'}, True),
  ...     ({'user': 'Alice', 'item': 'Star Wars'}, True),
  ...     ({'user': 'Alice', 'item': 'Notting Hill'}, False),
  ...     ({'user': 'Alice', 'item': 'Harry Potter '}, True),
  ...     ({'user': 'Bob', 'item': 'Superman'}, True),
  ...     ({'user': 'Bob', 'item': 'Terminator'}, True),
  ...     ({'user': 'Bob', 'item': 'Star Wars'}, True),
  ...     ({'user': 'Bob', 'item': 'Notting Hill'}, False)
  ... )
  
  >>> model = facto.FwFMClassifier(
  ...     n_factors=10,
  ...     seed=42,
  ... )
  
  >>> for x, y in dataset:
  ...     model.learn_one(x, y)
  
  >>> model.predict_one({'Bob': 1, 'Harry Potter': 1})
  True
  
  References
  ----------
  [^1]: [Junwei Pan, Jian Xu, Alfonso Lobos Ruiz, Wenliang Zhao, Shengjun Pan, Yu Sun, and Quan Lu, 2018, April. Field-weighted Factorization Machines for Click-Through Rate Prediction in Display Advertising. In Proceedings of the 2018 World Wide Web Conference on World Wide Web. International World Wide Web Conferences Steering Committee, (pp. 1349–1357).](https://arxiv.org/abs/1806.03514)
class_docstr_tok: ["Field-weighted","Factorization","Machine","for","binary","classification",".","The","model","equation","is","defined","as",":","$","$","\\hat","{","y","}","(","x",")","=","w_","{","0","}","+","\\sum_","{","j=1","}","^","{","p","}","w_","{","j","}","x_","{","j","}","+","\\sum_","{","j=1","}","^","{","p","}","\\sum_","{","j'=j+1","}","^","{","p","}","r_","{","f_j",",","f_","{","j","'","}","}","\\langle","\\mathbf","{","v","}","_j",",","\\mathbf","{","v","}","_","{","j","'","}","\\rangle","x_","{","j","}","x_","{","j","'","}","$","$","Where","$","f_j","$","and","$","f_","{","j","'","}","$","are","$","j","$","and","$","j","'","$","fields",",","respectively",",","and","$","\\mathbf","{","v","}","_j","$","and","$","\\mathbf","{","v","}","_","{","j","'","}","$","are","$","j","$","and","$","j","'","$","latent","vectors",",","respectively",".","For","more","efficiency",",","this","model","automatically","one-hot","encodes","strings","features","considering","them","as","categorical","variables",".","Field","names","are","inferred","from","feature","names","by","taking","everything","before","the","first","underscore",":","`","feature_name.split","(","'","_","'",")","[","0","]","`",".","Parameters","--","--","--","--","--","n_factors","Dimensionality","of","the","factorization","or","number","of","latent","factors",".","weight_optimizer","The","sequential","optimizer","used","for","updating","the","feature","weights",".","Note","that","the","intercept","is","handled","separately",".","latent_optimizer","The","sequential","optimizer","used","for","updating","the","latent","factors",".","int_weight_optimizer","The","sequential","optimizer","used","for","updating","the","field","pairs","interaction","weights",".","loss","The","loss","function","to","optimize","for",".","sample_normalization","Whether","to","divide","each","element","of","`","x","`","by","`","x","`","'s","L2-norm",".","l1_weight","Amount","of","L1","regularization","used","to","push","weights","towards","0.","l2_weight","Amount","of","L2","regularization","used","to","push","weights","towards","0.","l1_latent","Amount","of","L1","regularization","used","to","push","latent","weights","towards","0.","l2_latent","Amount","of","L2","regularization","used","to","push","latent","weights","towards","0.","intercept","Initial","intercept","value",".","intercept_lr","Learning","rate","scheduler","used","for","updating","the","intercept",".","An","instance","of","`","optim.schedulers.Constant","`","is","used","if","a","`","float","`","is","passed",".","No","intercept","will","be","used","if","this","is","set","to","0.","weight_initializer","Weights","initialization","scheme",".","Defaults","to","`","optim.initializers.Zeros","(",")","`",".","latent_initializer","Latent","factors","initialization","scheme",".","Defaults","to","`","optim.initializers.Normal","(","mu=.0",",","sigma=.1",",","random_state=self.random_state",")","`",".","clip_gradient","Clips","the","absolute","value","of","each","gradient","value",".","seed","Randomization","seed","used","for","reproducibility",".","Attributes","--","--","--","--","--","weights","The","current","weights","assigned","to","the","features",".","latents","The","current","latent","weights","assigned","to","the","features",".","interaction_weights","The","current","interaction","strengths","of","field","pairs",".","Examples","--","--","--","--",">",">",">","from","river","import","facto",">",">",">","dataset","=","(","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Superman","'","}",",","True",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Terminator","'","}",",","True",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Star","Wars","'","}",",","True",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Notting","Hill","'","}",",","False",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Harry","Potter","'","}",",","True",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Superman","'","}",",","True",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Terminator","'","}",",","True",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Star","Wars","'","}",",","True",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Notting","Hill","'","}",",","False",")","...",")",">",">",">","model","=","facto.FwFMClassifier","(","...","n_factors=10",",","...","seed=42",",","...",")",">",">",">","for","x",",","y","in","dataset",":","...","model.learn_one","(","x",",","y",")",">",">",">","model.predict_one","(","{","'Bob","'",":","1",",","'Harry","Potter","'",":","1","}",")","True","References","--","--","--","--","--","[","^1","]",":","[","Junwei","Pan",",","Jian","Xu",",","Alfonso","Lobos","Ruiz",",","Wenliang","Zhao",",","Shengjun","Pan",",","Yu","Sun",",","and","Quan","Lu",",","2018",",","April",".","Field-weighted","Factorization","Machines","for","Click-Through","Rate","Prediction","in","Display","Advertising",".","In","Proceedings","of","the","2018","World","Wide","Web","Conference","on","World","Wide","Web",".","International","World","Wide","Web","Conferences","Steering","Committee",",","(","pp",".","1349\u20131357",")",".","]","(","https",":","\/\/arxiv.org\/abs\/1806.03514",")"]
code: def __init__(
      self,
      n_factors=10,
      weight_optimizer: optim.base.Optimizer | None = None,
      latent_optimizer: optim.base.Optimizer | None = None,
      int_weight_optimizer: optim.base.Optimizer | None = None,
      loss: optim.losses.BinaryLoss | None = None,
      sample_normalization=False,
      l1_weight=0.0,
      l2_weight=0.0,
      l1_latent=0.0,
      l2_latent=0.0,
      intercept=0.0,
      intercept_lr: optim.base.Scheduler | float = 0.01,
      weight_initializer: optim.initializers.Initializer | None = None,
      latent_initializer: optim.initializers.Initializer | None = None,
      clip_gradient=1e12,
      seed: int | None = None,
  ):
      super().__init__(
          n_factors=n_factors,
          weight_optimizer=weight_optimizer,
          int_weight_optimizer=int_weight_optimizer,
          latent_optimizer=latent_optimizer,
          loss=optim.losses.Log() if loss is None else loss,
          sample_normalization=sample_normalization,
          l1_weight=l1_weight,
          l2_weight=l2_weight,
          l1_latent=l1_latent,
          l2_latent=l2_latent,
          intercept=intercept,
          intercept_lr=intercept_lr,
          weight_initializer=weight_initializer,
          latent_initializer=latent_initializer,
          clip_gradient=clip_gradient,
          seed=seed,
      )
  
imports: from __future__ import annotations
  import collections
  import functools
  import itertools
  import numpy
  from river import base, optim, utils
  from .base import BaseFM
label_desc: Use image node_id 1 to create a new FwFMClassifier object from inherited base classes: FwFM, base with example: obj = FwFMClassifier(n_factors, weight_optimizer, latent_optimizer, int_weight_optimizer, loss, sample_normalization, l1_weight, l2_weight, l1_latent, l2_latent, intercept, intercept_lr, weight_initializer, latent_initializer, clip_gradient, seed)