class watex.models.premodels.pModels(model='svm', target='bin', kernel=None, oob_score=False, objective='fr')[source]#

Bases: object

Pretrained Models class.

The pretrained model class is composed of estimators already trained in a case study region in West -Africa Bagoue region. Refer to Kouadio et al, 2022 for furher details. It is a set of support vector machines, decision tree`, k-nearest neighbors, Extreme ``gradient boosting machines, benchmart voting classifier, and `` bagging classifier. Each retrained model is considered as a class object and attributes compose the training parameters from cross-validation results.

Parameters:
model: str

Name of the pretrained model. Note that the pretrained SVMs is composed of 04 kernels such as the rbf for radial basis function , the poly for polynomial , sig for sigmoid and lin for linear. Default is rbf. Each kernel is a model attributes of SVM class. For instance to retrieve the pretrained model with kernel = ‘poly’, we must use after fitting pModels class:

>>> pModels(model='svm', kernel='poly').fit().SVM.poly.best_estimator_
... SVC(C=128.0, coef0=7, degree=5, gamma=0.00048828125, kernel='poly', tol=0.01)
>>> # or
>>> pModels(model='svm', kernel='poly').fit().estimator_
... SVC(C=128.0, coef0=7, degree=5, gamma=0.00048828125, kernel='poly', tol=0.01)
kernel: str

kernel refers to SVM machines kernels. It can be rbf for radial basis function , the poly for polynomial , sig for sigmoid and lin for linear. No need to provide since it can be retrieved as an attribute of the SVM model like:

>>> pModels(model='svm').fit().SVM.rbf # is an object instance
>>> # to retreive the rbf values use attribute `best_estimator_
>>> pModels(model='svm').fit().SVM.rbf.best_estimator_
...  SVC(C=2.0, coef0=0, degree=1, gamma=0.125)
target: str

Two types of classification is predicted. The binary classification bin and the multiclass classification multi. default is bin. When turning target to multi, be aware that only the SVMs are trained for multiclass prediction. Futhernore, the bin consisted to predict the flow rate (FR) with label {0} and {1} where {0} means the \(FR <=1 m^3/hr\) and {1} for \(FR> 1m^3/hr\). About multi, four classes are predicted such as:

\[FR0 & = & FR = 0 FR1 & = & 0 < FR <=1 m^3/hr FR2 & = & 1< FR <=3 m^3/hr FR3 & = & FR> 3 m^3/hr\]
oob_score: bool,

Out-of-bag. Setting oob_score to true, you will retrieve some pretrained model with obb_score set to true when training. The pretrained models with fine-tuned model with oob_score set to true are ‘RandomForest’ and ‘Extratrees’.

objective: str, default=’fr’

Is the prediction aim goal, the reason for storing the pretrained models. The default objective is ‘fr’ i.e. for flow rate prediction. Other objectives will be added as new engineering problems are solved and published.

. _Cote d’Ivoire: https://en.wikipedia.org/wiki/Ivory_Coast

fit(X=None, y=None, **fit_params)[source]#

Fit X and y with the pretrained models.

Note that to retrieve only the pretrained model, don’t pass anything in fit method. For instance to fetch the best SVM estimator with kernel = ‘sigmoid’, one just needs to fit:class:.pModels class as follow:

>>> pModels(model='svm', kernel='sigmoid').fit().estimator_
Out[24]: SVC(C=512.0, coef0=0, degree=1, gamma=0.001953125, kernel='sigmoid', tol=1.0)

If model=’svm’ and none kernel is passed, the rbf is used instead as default.

Parameters:
  • X (Ndarray of shape ( M x N), \(M=m-samples x N=n-features\)) – training set; Denotes data that is observed at training and prediction time, used as independent variables in learning. The notation is uppercase to denote that it is ordinarily a matrix. When a matrix, each sample may be represented by a feature vector, or a vector of precomputed (dis)similarity with each training sample. X may also not be a matrix, and may require a feature extractor or a pairwise metric to turn it into one before learning a model.

  • y (array-like of shape (M, ) :math:`M=m-samples) – train target; Denotes data that may be observed at training time as the dependent variable in learning, but which is unavailable at prediction time, and is usually the target of prediction.

Returns:

Returns self for easy method chaining.

Return type:

pModels instance

property inspect#

Inspect object whether is fitted or not

pdefaults_ = [('xgboost', 'ExtremeGradientBoosting'), ('svc', 'SupportVectorClassifier'), ('dtc', 'DecisionTreeClassifier'), ('stc', 'StackingClassifier'), ('bag', 'BaggingClassifier'), ('logit', 'LogisticRegression'), ('vtc', 'VotingClassifier'), ('rdf', 'RandomForestClassifier'), ('ada', 'AdaBoostClassifier'), ('extree', 'ExtraTreesClassifier'), ('knn', 'KNeighborsClassifier')]#
predict(X)[source]#

Predict object from the pretrained model

Parameters:

X (Ndarray of shape ( M x N), \(M=m-samples x N=n-features\)) – training set; Denotes data that is observed at training and prediction time, used as independent variables in learning. The notation is uppercase to denote that it is ordinarily a matrix. When a matrix, each sample may be represented by a feature vector, or a vector of precomputed (dis)similarity with each training sample. X may also not be a matrix, and may require a feature extractor or a pairwise metric to turn it into one before learning a model.

Returns:

y_pred – the predicted target values from X.

Return type:

Array-like, shape (M, )