@@ -39,7 +39,7 @@ def __init__(
39
39
self .multiclass = multiclass
40
40
41
41
def predict_values (self , x : sparse .csr_matrix ) -> np .ndarray :
42
- """Calculates the decision values associated with x.
42
+ """Calculate the decision values associated with x.
43
43
44
44
Args:
45
45
x (sparse.csr_matrix): A matrix with dimension number of instances * number of features.
@@ -79,7 +79,7 @@ def train_1vsrest(
79
79
options : str = "" ,
80
80
verbose : bool = True ,
81
81
) -> FlatModel :
82
- """Trains a linear model for multi-label data using a one-vs-rest strategy.
82
+ """Train a linear model for multi-label data using a one-vs-rest strategy.
83
83
84
84
Args:
85
85
y (sparse.csr_matrix): A 0/1 matrix with dimensions number of instances * number of classes.
@@ -169,9 +169,9 @@ def train_thresholding(
169
169
options : str = "" ,
170
170
verbose : bool = True ,
171
171
) -> FlatModel :
172
- """Trains a linear model for multi-label data using a one-vs-rest strategy
172
+ """Train a linear model for multi-label data using a one-vs-rest strategy
173
173
and cross-validation to pick decision thresholds optimizing the sum of Macro-F1 and Micro-F1.
174
- Outperforms train_1vsrest in most aspects at the cost of higher time complexity
174
+ Outperform train_1vsrest in most aspects at the cost of higher time complexity
175
175
due to an internal cross-validation.
176
176
177
177
This method is the micromacro-freq approach from this CIKM 2023 paper:
@@ -235,7 +235,7 @@ def _micromacro_one_label(
235
235
negatives, and the number of labels processed.
236
236
237
237
Returns:
238
- tuple[np.ndarray, float, dict]: the weights, threshold, and the updated stats for calculating
238
+ tuple[np.ndarray, float, dict]: The weights, threshold, and the updated stats for calculating
239
239
Micro-F1.
240
240
"""
241
241
@@ -319,7 +319,7 @@ def micro_plus_macro(tp, fp, fn):
319
319
320
320
321
321
def _do_train (y : np .ndarray , x : sparse .csr_matrix , options : str ) -> np .matrix :
322
- """Wrapper around liblinear.liblinearutil.train.
322
+ """Wrap around liblinear.liblinearutil.train.
323
323
Forcibly suppresses all IO regardless of options.
324
324
325
325
Args:
@@ -328,7 +328,7 @@ def _do_train(y: np.ndarray, x: sparse.csr_matrix, options: str) -> np.matrix:
328
328
options (str): The option string passed to liblinear.
329
329
330
330
Returns:
331
- np.matrix: the weights.
331
+ np.matrix: The weights.
332
332
"""
333
333
if y .shape [0 ] == 0 :
334
334
return np .matrix (np .zeros ((x .shape [1 ], 1 )))
@@ -376,11 +376,11 @@ def _fmeasure(y_true: np.ndarray, y_pred: np.ndarray) -> float:
376
376
"""Calculate F1 score.
377
377
378
378
Args:
379
- y_true (np.ndarray): array of +1/-1.
380
- y_pred (np.ndarray): array of +1/-1.
379
+ y_true (np.ndarray): Array of +1/-1.
380
+ y_pred (np.ndarray): Array of +1/-1.
381
381
382
382
Returns:
383
- float: the F1 score.
383
+ float: The F1 score.
384
384
"""
385
385
tp = np .sum (np .logical_and (y_true == 1 , y_pred == 1 ))
386
386
fn = np .sum (np .logical_and (y_true == 1 , y_pred == - 1 ))
@@ -399,10 +399,10 @@ def train_cost_sensitive(
399
399
options : str = "" ,
400
400
verbose : bool = True ,
401
401
) -> FlatModel :
402
- """Trains a linear model for multi-label data using a one-vs-rest strategy
402
+ """Train a linear model for multi-label data using a one-vs-rest strategy
403
403
and cross-validation to pick an optimal asymmetric misclassification cost
404
404
for Macro-F1.
405
- Outperforms train_1vsrest in most aspects at the cost of higher
405
+ Outperform train_1vsrest in most aspects at the cost of higher
406
406
time complexity.
407
407
See user guide for more details.
408
408
@@ -416,7 +416,7 @@ def train_cost_sensitive(
416
416
Returns:
417
417
A model which can be used in predict_values.
418
418
"""
419
- # Follows the MATLAB implementation at https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/multilabel/
419
+ # Follow the MATLAB implementation at https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/multilabel/
420
420
x , options , bias = _prepare_options (x , options )
421
421
422
422
y = y .tocsc ()
@@ -449,7 +449,7 @@ def _cost_sensitive_one_label(y: np.ndarray, x: sparse.csr_matrix, options: str)
449
449
options (str): The option string passed to liblinear.
450
450
451
451
Returns:
452
- np.ndarray: the weights.
452
+ np.ndarray: The weights.
453
453
"""
454
454
455
455
l = y .shape [0 ]
@@ -503,10 +503,10 @@ def train_cost_sensitive_micro(
503
503
options : str = "" ,
504
504
verbose : bool = True ,
505
505
) -> FlatModel :
506
- """Trains a linear model for multi-label data using a one-vs-rest strategy
506
+ """Train a linear model for multi-label data using a one-vs-rest strategy
507
507
and cross-validation to pick an optimal asymmetric misclassification cost
508
508
for Micro-F1.
509
- Outperforms train_1vsrest in most aspects at the cost of higher
509
+ Outperform train_1vsrest in most aspects at the cost of higher
510
510
time complexity.
511
511
See user guide for more details.
512
512
@@ -574,7 +574,7 @@ def train_binary_and_multiclass(
574
574
options : str = "" ,
575
575
verbose : bool = True ,
576
576
) -> FlatModel :
577
- """Trains a linear model for binary and multi-class data.
577
+ """Train a linear model for binary and multi-class data.
578
578
579
579
Args:
580
580
y (sparse.csr_matrix): A 0/1 matrix with dimensions number of instances * number of classes.
@@ -628,7 +628,7 @@ def train_binary_and_multiclass(
628
628
629
629
630
630
def predict_values (model , x : sparse .csr_matrix ) -> np .ndarray :
631
- """Calculates the decision values associated with x, equivalent to model.predict_values(x).
631
+ """Calculate the decision values associated with x, equivalent to model.predict_values(x).
632
632
633
633
Args:
634
634
model: A model returned from a training function.
0 commit comments