pyconstruct.models.LinearModel

class pyconstruct.models.LinearModel(domain=None, w=None, features=None, **kwargs)

A linear model.

Represents a linear model of the type: F(x, y) = \langle \boldsymbol{w}, \boldsymbol{\phi}(x, y) \rangle.

The parameter features is a vector containing part of the features of the model that are directly handled into Python code. They could be, for instance, the result of some feature learning procedure. The rest of the feature vector is specified directly into the domain. The two arrays are complementary and, when using the solve macro from pyconstruct.pmzn, they are concatenated and used for computing the complete feature vector \boldsymbol{phi}. The size of the weights vector w must be equal to the sum of the size of the two feature arrays. Using this parameter is optional and in most cases it suffices to encode features into the pmzn domain.

Parameters:
  • domain (Domain) – The underlying domain.
  • w (np.ndarray) – The weight vector.
  • features (np.ndarray) – An optional array of additional features.

Methods

clear()
copy()
decision_function(X, Y, **kwargs) Computes the score assigned to the (x, y) by the model.
fromkeys Returns a new dict with keys from iterable and values equal to value.
get(k[,d])
items()
keys()
loss(X, Y, Y_pred, **kwargs) Computes the loss of the predictions with respect the model.
margin(X, Y, Y_pred, **kwargs) Computes the margin of the current model for the given data.
phi(X, Y, **kwargs)
pop(k[,d]) If key is not found, d is returned if given, otherwise KeyError is raised
popitem() 2-tuple; but raise KeyError if D is empty.
predict(X, *args, **kwargs) Makes a prediction based on the current model.
setdefault(k[,d])
update([E, ]**F) If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
values()

Attributes

params A dictionary of parameters of the model.