Skip to content

trainFunctions

phs.trainFunctions

Classes:

Name Description
Experts

Convenience Class for a Mixture of Experts Classifier.

Ksplit

Convenience Class k-Split (for k-fold CV).

Functions:

Name Description
getTrainedModel

Train a model using Linear SVM Classifier.

Experts dataclass

Convenience Class for a Mixture of Experts Classifier.

Methods:

Name Description
__get__

Predict the class of X based on "opinion" of

__getitem__

Convenience subscript access for experts.

acc

Convenience function of naïve accuracy

Attributes:

Name Type Description
classes list[int]
experts list[dict]

classes = field(default_factory=lambda: [0, 1]) class-attribute instance-attribute

experts instance-attribute

__get__(X)

Predict the class of X based on "opinion" of experts. Y = self(X)

__getitem__(idx)

Convenience subscript access for experts.

self[i] is the same as self.experts[i]

acc(X, Y)

Convenience function of naïve accuracy calculator.

acc = np.mean(self(X)==Y)

Ksplit dataclass

Convenience Class k-Split (for k-fold CV).

Split a dataset with \(N\) samples into \(k\) parts. Only maintain indices so that ksplit[i] provides a set of indices subscriptable to the original dataset, e.g. iTrain, iVal = ksplit[i]; xTrain = X[iTrain] creates a train data subset for i-th fold of validation.

On initialisation, create a random shuffled set of indices if not already provided.

[i] subscript access will fetch the i-th pair of indices corresponding to train and val split respectively.

Attributes:

Name Type Description
N int
indices list[int]
k int

N instance-attribute

indices = field(default_factory=list) class-attribute instance-attribute

k instance-attribute

getTrainedModel(xTrain, yTrain, xVal, yVal, hparams)

Train a model using Linear SVM Classifier.

hparams is a dict with key 'C'