truelearn.learning.MajorityClassifier#

class truelearn.learning.MajorityClassifier(*, engagement: int = 0, non_engagement: int = 0, threshold: float = 0.5)[source]#

Bases: BaseClassifier

A classifier that predicts based on the number of learner’s engagement and non-engagement.

If the number of engagements on the training data is greater than the number of non-engagement, the classifier predicts Engage (True); otherwise, it predicts Non-Engage (False).

Examples

>>> from truelearn.learning import MajorityClassifier
>>> from truelearn.models import EventModel
>>> majority = MajorityClassifier()
>>> majority
MajorityClassifier()
>>> # prepare an event model with empty knowledge
>>> events = [EventModel(), EventModel(), EventModel()]
>>> engage_stats = [False, True, True]
>>> for event, engage_stats in zip(events, engage_stats):
...     majority = majority.fit(event, engage_stats)
...     print(majority.predict(event))
...
False
False
True

Methods

__init__(*[, engagement, non_engagement, ...])

Init MajorityClassifier object.

fit(x, y)

Train the model.

get_params([deep])

Get parameters for this Classifier.

predict(x)

Predict whether the learner will engage in the learning event.

predict_proba(x)

Predict the probability that the learner will engage in the learning event.

set_params(**args)

Set the parameters of this Classifier.

__init__(*, engagement: int = 0, non_engagement: int = 0, threshold: float = 0.5) None[source]#

Init MajorityClassifier object.

Parameters:
  • * – Use to reject positional arguments.

  • engagement – The number of learner’s engagements.

  • non_engagement – The number of learner’s non_engagements.

  • threshold – A float that determines the classification threshold.

Raises:
  • TrueLearnTypeError – Types of parameters do not satisfy their constraints.

  • TrueLearnValueError – Values of parameters do not satisfy their constraints.

fit(x: EventModel, y: bool) Self[source]#

Train the model.

Parameters:
  • x – A representation of a learning event.

  • y – A bool indicating whether the learner engages in the learning event.

Returns:

The updated classifier object.

get_params(deep: bool = True) Dict[str, Any][source]#

Get parameters for this Classifier.

Parameters:

deep – If True, will return the parameters for this Classifier and contained sub-objects that inherit BaseClassifier class.

Returns:

A dict mapping variable names to the corresponding objects.

predict(x: EventModel) bool[source]#

Predict whether the learner will engage in the learning event.

Parameters:

x – A representation of a learning event.

Returns:

A bool indicating whether the learner will engage in the learning event.

predict_proba(x: EventModel) float[source]#

Predict the probability that the learner will engage in the learning event.

Parameters:

x – A representation of a learning event.

Returns:

A float indicating the probability that the learner will engage in the learning event.

set_params(**args) Self[source]#

Set the parameters of this Classifier.

A value can be reset only if the given parameter has the same type as the original value.

Parameters:

**args – Keyword arguments. The key should match the parameter names of the classifier. The arguments should have the correct type.

Returns:

The updated classifier.

Raises:
  • TrueLearnTypeError – Types of parameters do not satisfy their constraints.

  • TrueLearnValueError – Values of parameters do not satisfy their constraints.

  • InvalidArgumentError – If the given argument name is not in the class.