Classifiers

_DEFAULT_CLASSIFIERS

A private dictionary containing the classes of the default classifiers that EasyFit provides in EasyClassifier.

The table contains the keys of the dictionary to access the models, and links to the documentation of each model.

Classifier (Dict Key)

Class (Dict Value)

DummyClassifier

sklearn.dummy.DummyClassifier

LogisticRegression

sklearn.linear_model.LogisticRegression

RidgeClassifier

sklearn.linear_model.RidgeClassifier

RidgeClassifierCV

sklearn.linear_model.RidgeClassifierCV

LinearSVC

sklearn.svm.LinearSVC

SupportVectorClassifier

sklearn.svm.SVC

DecisionTreeClassifier

sklearn.tree.DecisionTreeClassifier

RandomForestClassifier

sklearn.ensemble.RandomForestClassifier

KNeighborsClassifier

sklearn.neighbors.KNeighborsClassifier

MLPClassifier

sklearn.neural_network.MLPClassifier

AdaBoostClassifier

sklearn.ensemble.AdaBoostClassifier

SGDClassifier

sklearn.linear_model.SGDClassifier

GaussianNaiveBayes

sklearn.naive_bayes.GaussianNB

QuadraticDiscriminantAnalysis

sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis

easyfit.classifiers module

class easyfit.classifiers.EasyClassifier(*args, **kwargs)[source]

Bases: _EasyModel

Fit classifier models in
  • _DEFAULT_CLASSIFIERS (if include_defaults=True)

  • models_dict (if models_dict != None)

Parameters:
  • models_dict (Dictionary of additional models) –

    Can hold:
    • classes: models_dict = {‘LinearRegression’: LinearRegression}

    • objects: models_dict = {‘LinearRegression’: LinearRegression()}

    (Default value = None)

  • include_defaults (boolean) –

    Include _DEFAULT_CLASSIFIERS in trained models

    (Default value = True)

evaluate(X, y, as_df=True, model_first=True, from_preds=False)[source]

Returns models results on each of the metrics in self._METRICS dictionary

Parameters:
  • X (array of features) –

  • y (array of targets) –

  • as_df (boolean) –

    • if True: return results in pd.DataFrame

    • if False: return results in dictionary

    (Default value = True)

  • model_first (boolean) –

    • if True: returns models at axis=0 (rows), results at axis=1 (columns)

    • if False: returns models at axis=1 (columns), results at axis=0 (rows)

    (Default value = True)

  • from_preds (boolean) –

    • if True: make preditions then calacuate metrics (X holds input features)

    • if False: calcualte metrics from predictions (X holds predictions)

    (Default value = False)

Returns:

results

Return type:

Dict (as_df=False) or pd.Dataframe (as_df=True)

fit(X, y)[source]

Fit classifiers in self._models on features X with targets y

Calls method fit for each model in self._models

Parameters:
  • X (array of features) –

  • y (array of targets) –

Return type:

None

get_model(model_key)[source]

Get specific model from self._models

Parameters:

model_key (the key for model in self._models) –

Returns:

  • model object corrseponding to key if key exist

  • None if key does not exist

predict(X)[source]

Make predictions for features in X

Call predict method for each model in self._models

Parameters:

X (array of features) –

Returns:

preds – Dictionary with same keys in self._models and predictions for each model of features in X

Return type:

Dict

score(X, y, as_df=True, sort=True)[source]

Calculate score for each model in self._models

Calls score method for each model in self._models

Return mean accuracy for each model on the given data and labels

Parameters:
  • X (array of features) –

  • y (array of targets) –

  • as_df (boolean) –

    • if True: return results in pd.DataFrame

    • if False: return results in dictionary

    (Default value = True)

  • sort (boolean) –

    • if True: returns results sorted in discending order by score

    • if False: returns results in the original order of models

    (Default value = True)

Returns:

results

Return type:

Dict (as_df=False) or pd.Dataframe (as_df=True)