Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update classes to use new features from liblinear 1.7.

  • Loading branch information...
commit 2a4adcb139f84f3ca81e900768f4b2b33116e56c 1 parent 4c9170d
@fabianp fabianp authored
View
13 scikits/learn/logistic.py
@@ -21,6 +21,10 @@ class LogisticRegression(BaseLibLinear, ClassifierMixin):
penalty : string, 'l1' or 'l2'
Used to specify the norm used in the penalization
+ dual : boolean
+ Dual or primal formulation. Dual formulation is only
+ implemented for l2 penalty.
+
C : float
Specifies the strength of the regularization. The smaller it is
the bigger in the regularization.
@@ -57,9 +61,12 @@ class LogisticRegression(BaseLibLinear, ClassifierMixin):
http://www.csie.ntu.edu.tw/~cjlin/liblinear/
"""
- def __init__(self, penalty='l2', eps=1e-4, C=1.0, fit_intercept=True):
- super(LogisticRegression, self).__init__ (penalty=penalty, loss='lr',
- dual=False, eps=eps, C=C, fit_intercept=fit_intercept)
+ def __init__(self, penalty='l2', dual=False, eps=1e-4, C=1.0,
+ fit_intercept=True):
+
+ super(LogisticRegression, self).__init__ (penalty=penalty,
+ dual=dual, loss='lr', eps=eps, C=C,
+ fit_intercept=fit_intercept)
def predict_proba(self, T):
T = np.asanyarray(T, dtype=np.float64, order='C')
View
22 scikits/learn/svm/base.py
@@ -234,17 +234,15 @@ class BaseLibLinear(BaseEstimator):
Base for classes binding liblinear (dense and sparse versions)
"""
- _weight_label = np.empty(0, dtype=np.int32)
- _weight = np.empty(0, dtype=np.float64)
-
_solver_type_dict = {
- 'PL2_LLR_D0' : 0, # L2 penalty logistic regression
- 'PL2_LL2_D1' : 1, # L2 penalty, L2 loss, dual problem
- 'PL2_LL2_D0' : 2, # L2 penalty, L2 loss, primal problem
- 'PL2_LL1_D1' : 3, # L2 penalty, L1 Loss, dual problem
+ 'PL2_LLR_D0' : 0, # L2 penalty, logistic regression
+ 'PL2_LL2_D1' : 1, # L2 penalty, L2 loss, dual form
+ 'PL2_LL2_D0' : 2, # L2 penalty, L2 loss, primal form
+ 'PL2_LL1_D1' : 3, # L2 penalty, L1 Loss, dual form
'MC_SVC' : 4, # Multi-class Support Vector Classification
- 'PL1_LL2_D0' : 5, # L1 penalty, L2 Loss, primal problem
- 'PL1_LLR_D0' : 6, # L1 penalty logistic regression
+ 'PL1_LL2_D0' : 5, # L1 penalty, L2 Loss, primal form
+ 'PL1_LLR_D0' : 6, # L1 penalty, logistic regression
+ 'PL2_LLR_D1' : 7, # L2 penalty, logistic regression, dual form
}
def __init__(self, penalty='l2', loss='l2', dual=True, eps=1e-4, C=1.0,
@@ -256,6 +254,10 @@ def __init__(self, penalty='l2', loss='l2', dual=True, eps=1e-4, C=1.0,
self.C = C
self.fit_intercept = fit_intercept
self.multi_class = multi_class
+
+ self._weight_label = np.empty(0, dtype=np.int32)
+ self._weight = np.empty(0, dtype=np.float64)
+
# Check that the arguments given are valid:
self._get_solver_type()
@@ -343,7 +345,7 @@ def coef_(self):
return self.raw_coef_
def predict_proba(self, T):
- # how can this be, logisitic *does* implement this
+ # only available for logistic regression
raise NotImplementedError(
'liblinear does not provide this functionality')
View
17 scikits/learn/svm/src/liblinear/liblinear_helper.c
@@ -250,10 +250,8 @@ int csr_copy_predict(npy_intp n_features, npy_intp *data_size, char *data,
int copy_prob_predict(char *predict, struct model *model_, npy_intp *predict_dims,
char *dec_values)
{
- double *t = (double *) dec_values;
struct feature_node **predict_nodes;
register int i;
- double temp;
int n, m;
n = predict_dims[0];
m = model_->nr_class;
@@ -270,17 +268,20 @@ int copy_prob_predict(char *predict, struct model *model_, npy_intp *predict_dim
}
-int csr_copy_predict_proba(char *predict, struct model *model_,
- npy_intp *predict_dims, char *dec_values)
+int csr_copy_predict_proba(npy_intp n_features, npy_intp *data_size,
+ char *data, npy_intp *index_size,
+ char *index, npy_intp *indptr_shape,
+ char *indptr, struct model *model_,
+ char *dec_values)
{
struct feature_node **predict_nodes;
register int i;
double temp;
int n, m;
- n = predict_dims[0];
- m = model_->nr_class;
- predict_nodes = csr_to_sparse((double *) predict,
- predict_dims, model_->bias);
+ predict_nodes = csr_to_sparse((double *) data, index_size,
+ (int *) index, indptr_shape,
+ (int *) indptr, model_->bias,
+ n_features);
if (predict_nodes == NULL)
return -1;
for(i=0; i<n; ++i) {
Please sign in to comment.
Something went wrong with that request. Please try again.