| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.100.1/docs/handbook/_sources/libraries/logistic_regression_classifier.rst.txt |
.. _library_logistic_regression_classifier:
logistic_regression_classifierLogistic regression classifier supporting both binary and multiclass classification. Multiclass classification is implemented using batch gradient descent to train a single multiclass softmax model. Binary classification is treated as a two-class special case of the same objective.
The library implements the classifier_protocol defined in the
classification_protocols library. It provides predicates for
learning a classifier from a dataset object, using it to make
predictions, returning class probabilities, and exporting the learned
model as a list of predicate clauses or to a file.
Datasets are represented as objects implementing the
dataset_protocol protocol from the classification_protocols
library. Existing datasets in classification_protocols/test_datasets
can be used for binary, multiclass, continuous, categorical, and
mixed-feature testing.
Open the `../../docs/library_index.html#logistic_regression_classifier <../../docs/library_index.html#logistic_regression_classifier>`__ link in a web browser.
To load this library, load the loader.lgt file:
::
| ?- logtalk_load(logistic_regression_classifier(loader)).
To test this library predicates, load the tester.lgt file:
::
| ?- logtalk_load(logistic_regression_classifier(tester)).
To run the performance benchmark suite, load the
tester_performance.lgt file:
::
| ?- logtalk_load(logistic_regression_classifier(tester_performance)).
weather, mixed, iris_small,
missing_mixed, and breast_cancer datasets with reported
training time, training accuracy, and mean log loss.The learn/3 predicate supports these options:
0.1)1000)1.0e-6)0.0)Learning a classifier ~~~~~~~~~~~~~~~~~~~~~
::
| ?- logistic_regression_classifier::learn(weather, Classifier).
| ?- logistic_regression_classifier::learn(iris_small, Classifier, [learning_rate(0.05), maximum_iterations(1500)]).
Making predictions ~~~~~~~~~~~~~~~~~~
::
| ?- logistic_regression_classifier::learn(mixed, Classifier),
logistic_regression_classifier::predict(Classifier, [age-45, income-75000, student-no, credit_rating-fair], Class).
| ?- logistic_regression_classifier::learn(iris_small, Classifier),
logistic_regression_classifier::predict_probabilities(Classifier, [sepal_length-6.4, sepal_width-3.0, petal_length-5.8, petal_width-2.2], Probabilities).
Exporting the classifier ~~~~~~~~~~~~~~~~~~~~~~~~
::
| ?- logistic_regression_classifier::learn(weather, Classifier),
logistic_regression_classifier::export_to_clauses(weather, Classifier, classify, Clauses).
| ?- logistic_regression_classifier::learn(weather, Classifier),
logistic_regression_classifier::export_to_file(weather, Classifier, classify, 'classifier.pl').
The learned classifier is represented as a compound term with the form:
::
lr_classifier(Classes, Encoders, Models, Options)
Where:
Classes: list of class labelsEncoders: list of continuous scaling descriptors and categorical
value listsModels: list of class_model(Class, Bias, Weights) termsOptions: merged training options used to learn the model
When exported using export_to_clauses/4 or export_to_file/4,
this classifier term is serialized directly as the single argument of
the generated predicate clause so that the exported model can be loaded
and reused as-is.