gemseo / mlearning / core

ml_algo module

Machine learning algorithm baseclass

Machine learning is the art of building models from data, the latter being samples of properties of interest that can sometimes be sorted by group, such as inputs, outputs, categories, …

In the absence of such groups, the data can be analyzed through a study of commonalities, leading to plausible clusters. This is referred to as clustering, a branch of unsupervised learning dedicated to the detection of patterns in unlabeled data.

See also

unsupervised, cluster

When data can be separated into at least two categories by a human, supervised learning can start with classification whose purpose is to model the relation between these categories and the properties of interest. Once trained, a classification model can predict the category corresponding to new property values.

When the distinction between inputs and outputs can be made among the data properties, another branch of supervised learning can be called: regression modeling. Once trained, a regression model can predict the outputs corresponding to new inputs values.

The quality of a machine learning algorithm can be measured using a MLQualityMeasure either with respect to the learning dataset or to a test dataset or using resampling methods, such as K-folds or leave-one-out cross-validation techniques. The challenge is to avoid over-learning the learning data leading to a loss of generality. We often want to build models that are not too dataset-dependent. For that, we want to maximize both a learning quality and a generalization quality. In unsupervised learning, a quality measure can represent the robustness of clusters definition while in supervised learning, a quality measure can be interpreted as an error, whether it is a misclassification in the case of the classification algorithms or a prediction one in the case of the regression algorithms. This quality can often be improved by building machine learning models from standardized data in such a way that the data properties have the same order of magnitude.

Lastly, a machine learning algorithm often depends on hyperparameters to carefully tune in order to maximize the generalization power of the model.

See also


class gemseo.mlearning.core.ml_algo.MLAlgo(data, transformer=None, **parameters)[source]

Bases: object

The MLAlgo abstract class implements the concept of machine learning algorithm. Such a model is built from a training dataset, data transformation options and parameters. This abstract class defines the MLAlgo.learn(), methods and the boolean property, MLAlgo.is_trained. It also offers a string representation for end user. Inheriting classes should overload the MLAlgo.learn(), MLAlgo._save_algo() and MLAlgo._load_algo() methods.


  • data (Dataset) – learning dataset

  • transformer (dict(str) or dict(Transformer)) – transformation strategy for data groups. If None, do not transform data. The dictionary keys are the groups to transform. The dictionary items are the transformers, either referenced by their names as strings, or provided directly. Default: None.

  • parameters – algorithm parameters

ABBR = 'MLAlgo'
class DataFormatters[source]

Bases: object

Decorators for internal MLAlgo methods.

FILENAME = 'ml_algo.pkl'
property is_trained

Check if algorithm is trained. :return: bool


Train machine learning algorithm on learning set, possibly filtered using the given parameters. :param list(int) samples: indices of training samples.


Load external machine learning algorithm.


directory (str) – algorithm directory.

save(directory=None, path='.', save_learning_set=False)[source]

Save the machine learning algorithm.

  • directory (str) – directory name

  • path (str) – path name


location of saved file

Return type