| Did you know ... | Search Documentation: |
| Pack logtalk -- logtalk-3.100.1/docs/handbook/_sources/libraries/sgd_classifier.rst.txt |
.. _library_sgd_classifier:
sgd_classifierLinear stochastic-gradient classifier for tabular datasets using a one-vs-rest scheme with configurable losses. The implementation reuses the shared linear encoder pipeline so continuous and categorical features, including missing values, are represented consistently with the existing linear classifiers.
The library implements the classifier_protocol defined in the
classification_protocols library. It provides predicates for
learning a classifier from a dataset, using it to make predictions,
estimating class probabilities, and exporting it 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. Continuous, categorical, and mixed-feature datasets are
supported.
Open the `../../docs/library_index.html#sgd_classifier <../../docs/library_index.html#sgd_classifier>`__ link in a web browser.
To load this library, load the loader.lgt file:
::
| ?- logtalk_load(sgd_classifier(loader)).
To test this library predicates, load the tester.lgt file:
::
| ?- logtalk_load(sgd_classifier(tester)).
log_loss, hinge,
squared_hinge, modified_huber, and perceptron losses.The learn/3 predicate supports these options:
log_loss, hinge,
squared_hinge, modified_huber, or perceptron (default:
log_loss)0.05)constant
or inverse_scaling(Power) (default: constant)100)1.0e-5)0.0001)true)Learning a classifier ~~~~~~~~~~~~~~~~~~~~~
::
| ?- sgd_classifier::learn(weather, Classifier).
| ?- sgd_classifier::learn(mixed, Classifier, [loss(hinge), maximum_iterations(250)]).
Making predictions ~~~~~~~~~~~~~~~~~~
::
| ?- sgd_classifier::learn(weather, Classifier),
sgd_classifier::predict(Classifier, [outlook-rainy, temperature-mild, humidity-normal, windy-false], Class).
| ?- sgd_classifier::learn(missing_mixed, Classifier),
sgd_classifier::predict_probabilities(Classifier, [age-38, income-72000, student-yes, credit_rating-fair], Probabilities).
Exporting the classifier ~~~~~~~~~~~~~~~~~~~~~~~~
::
| ?- sgd_classifier::learn(weather, Classifier),
sgd_classifier::export_to_clauses(weather, Classifier, classify, Clauses).
| ?- sgd_classifier::learn(weather, Classifier),
sgd_classifier::export_to_file(weather, Classifier, classify, 'classifier.pl').
The learned classifier is represented as a compound term with the form:
::
sgd_classifier(Classes, Encoders, Loss, Models, Options)
Where:
Classes: list of class labelsEncoders: list of continuous scaling descriptors and categorical
value encodersLoss: selected optimization lossModels: list of class_model(Class, Bias, Weights) termsOptions: merged training options used to learn the classifier
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.