Class LogisticRegressionClassifier<U>
java.lang.Object
es.uam.eps.ir.relison.links.linkprediction.supervised.classifiers.LogisticRegressionClassifier<U>
- Type Parameters:
U
- type of the users.
- All Implemented Interfaces:
Classifier<U>
public class LogisticRegressionClassifier<U> extends java.lang.Object implements Classifier<U>
Classifier that applies a logistic regression (i.e. finds a linear separation between
elements in both positive and negative classes).
Reference: Bishop,C.M.Instance Recognition and Machine Learning, Springer, 2006, pp. 205-207
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.Integer>
classes
List of classes.private int
dimension
Number of attributes of the problem, including the class.private double
eta
Learning coefficient of the classifier.private int
maxEpochs
Maximum number of iterations which the algorithm will run during training.private boolean
normalize
True if the patterns have to be normalized.private Vector
omega
Vector that determines the hyperplane which separates both classes.private static double
RANGEMAX
Maximum possible initial value for each coordinate of the omega vectorprivate static double
RANGEMIN
Minimum possible initial value for each coordinate of the omega vectorprivate java.util.List<es.uam.eps.ir.ranksys.core.util.Stats>
stats
The list of stats for each attribute.private static double
THRESHOLD
When the difference between the previous iteration of the algorithm and the current is smaller than this value, the algorithm stops.private boolean
trained
Indicates if the classifier has been trained. -
Constructor Summary
Constructors Constructor Description LogisticRegressionClassifier(double eta, int maxEpochs)
Constructor.LogisticRegressionClassifier(double eta, int maxEpochs, boolean normalize)
Constructor. -
Method Summary
Modifier and Type Method Description int
classify(Instance<U> instance)
Obtains the most likely class for a certain instance.double
computeScore(Instance<U> instance, int category)
Gets the score for an individual pattern in a certain category.java.util.Map<java.lang.Integer,java.lang.Double>
computeScores(Instance<U> instance)
Computes the scores for an individual instance (once the training has been done).void
train(InstanceSet<U> trainSet)
Trains the classifier.
-
Field Details
-
dimension
private int dimensionNumber of attributes of the problem, including the class. -
omega
Vector that determines the hyperplane which separates both classes. -
eta
private final double etaLearning coefficient of the classifier. Controls the convergence speed of the classifier. Greater values may lead to bad convergence, but very small values make the convergence very slow. -
maxEpochs
private final int maxEpochsMaximum number of iterations which the algorithm will run during training. -
RANGEMIN
private static final double RANGEMINMinimum possible initial value for each coordinate of the omega vector- See Also:
- Constant Field Values
-
RANGEMAX
private static final double RANGEMAXMaximum possible initial value for each coordinate of the omega vector- See Also:
- Constant Field Values
-
THRESHOLD
private static final double THRESHOLDWhen the difference between the previous iteration of the algorithm and the current is smaller than this value, the algorithm stops.- See Also:
- Constant Field Values
-
classes
private java.util.List<java.lang.Integer> classesList of classes. -
normalize
private final boolean normalizeTrue if the patterns have to be normalized. -
stats
private java.util.List<es.uam.eps.ir.ranksys.core.util.Stats> statsThe list of stats for each attribute. -
trained
private boolean trainedIndicates if the classifier has been trained.
-
-
Constructor Details
-
LogisticRegressionClassifier
public LogisticRegressionClassifier(double eta, int maxEpochs)Constructor.- Parameters:
eta
- the learning coefficient of the classifier.maxEpochs
- the maximum number of iterations.
-
LogisticRegressionClassifier
public LogisticRegressionClassifier(double eta, int maxEpochs, boolean normalize)Constructor.- Parameters:
eta
- the learning coefficient of the classifier.maxEpochs
- the maximum number of iterations.normalize
- indicates if the data has to be normalized.
-
-
Method Details
-
train
Description copied from interface:Classifier
Trains the classifier.- Specified by:
train
in interfaceClassifier<U>
- Parameters:
trainSet
- the training set.
-
computeScores
Description copied from interface:Classifier
Computes the scores for an individual instance (once the training has been done).- Specified by:
computeScores
in interfaceClassifier<U>
- Parameters:
instance
- the individual instance.- Returns:
- A score for each class.
-
computeScore
Description copied from interface:Classifier
Gets the score for an individual pattern in a certain category.- Specified by:
computeScore
in interfaceClassifier<U>
- Parameters:
instance
- the pattern.category
- the class.- Returns:
- the score.
-
classify
Description copied from interface:Classifier
Obtains the most likely class for a certain instance.- Specified by:
classify
in interfaceClassifier<U>
- Parameters:
instance
- the individual instance.- Returns:
- The most likely class.
-