I am trying to predict a label based on some features and I have some training data.
Searching for ordinal regression in python, I found http://pythonhosted.org/mord/ but I could not figure out how to use it.
It would be great if someone has an example code to demonstrate how to use this module. Here are the classes in the mord module:
>>>import mord
>>>dir(mord)
['LAD',
'LogisticAT',
'LogisticIT',
'LogisticSE',
'OrdinalRidge',
'__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'__path__',
'__version__',
'base',
'check_X_y',
'grad_margin',
'linear_model',
'log_loss',
'metrics',
'np',
'obj_margin',
'optimize',
'propodds_loss',
'regression_based',
'sigmoid',
'svm',
'threshold_based',
'threshold_fit',
'threshold_predict',
'utils']
I believe it follows the API of Scikit-learn. So here is an example:
import numpy as np
import mord as m
c = m.LogisticIT() #Default parameters: alpha=1.0, verbose=0, maxiter=10000
c.fit(np.array([[0,0,0,1],[0,1,0,0],[1,0,0,0]]), np.array([1,2,3]))
c.predict(np.array([0,0,0,1]))
c.predict(np.array([0,1,0,0]))
c.predict(np.array([1,0,0,0]))
The output will be as follows:
array([1])
array([2])
array([3])
Hope it was helpful
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With