Skip to content

Commit a19398f

Browse files
Volodymyr OrlovVolodymyr Orlov
authored andcommitted
fix: code and documentation cleanup
1 parent 750015b commit a19398f

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

src/linalg/lu.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ mod tests {
287287
let expected =
288288
DenseMatrix::from_2d_array(&[&[-6.0, 3.6, 1.4], &[5.0, -3.0, -1.0], &[-1.0, 0.8, 0.2]]);
289289
let a_inv = a.lu().and_then(|lu| lu.inverse()).unwrap();
290-
println!("{}", a_inv);
291290
assert!(a_inv.approximate_eq(&expected, 1e-4));
292291
}
293292
}

src/math/distance/mahalanobis.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ impl<T: RealNumber, M: Matrix<T>> Distance<Vec<T>, T> for Mahalanobis<T, M> {
108108
);
109109
}
110110

111-
println!("{}", self.sigmaInv);
112-
113111
let n = x.len();
114112
let mut z = vec![T::zero(); n];
115113
for i in 0..n {

src/metrics/cluster_hcv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use crate::math::num::RealNumber;
55
use crate::metrics::cluster_helpers::*;
66

77
#[derive(Serialize, Deserialize, Debug)]
8-
/// Mean Absolute Error
8+
/// Homogeneity, completeness and V-Measure scores.
99
pub struct HCVScore {}
1010

1111
impl HCVScore {
12-
/// Computes mean absolute error
13-
/// * `y_true` - Ground truth (correct) target values.
14-
/// * `y_pred` - Estimated target values.
12+
/// Computes Homogeneity, completeness and V-Measure scores at once.
13+
/// * `labels_true` - ground truth class labels to be used as a reference.
14+
/// * `labels_pred` - cluster labels to evaluate.
1515
pub fn get_score<T: RealNumber, V: BaseVector<T>>(
1616
&self,
1717
labels_true: &V,

src/metrics/cluster_helpers.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,17 @@ mod tests {
106106
let v1 = vec![0.0, 0.0, 1.0, 1.0, 2.0, 0.0, 4.0];
107107
let v2 = vec![1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0];
108108

109-
println!("{:?}", contingency_matrix(&v1, &v2));
109+
assert_eq!(
110+
vec!(vec!(1, 2), vec!(2, 0), vec!(1, 0), vec!(1, 0)),
111+
contingency_matrix(&v1, &v2)
112+
);
110113
}
111114

112115
#[test]
113116
fn entropy_test() {
114117
let v1 = vec![0.0, 0.0, 1.0, 1.0, 2.0, 0.0, 4.0];
115118

116-
println!("{:?}", entropy(&v1));
119+
assert!((1.2770f32 - entropy(&v1).unwrap()).abs() < 1e-4);
117120
}
118121

119122
#[test]
@@ -122,6 +125,6 @@ mod tests {
122125
let v2 = vec![1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0];
123126
let s: f32 = mutual_info_score(&contingency_matrix(&v1, &v2));
124127

125-
println!("{}", s);
128+
assert!((0.3254 - s).abs() < 1e-4);
126129
}
127130
}

src/metrics/mean_absolute_error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ mod tests {
6262
let score1: f64 = MeanAbsoluteError {}.get_score(&y_pred, &y_true);
6363
let score2: f64 = MeanAbsoluteError {}.get_score(&y_true, &y_true);
6464

65-
println!("{}", score1);
66-
6765
assert!((score1 - 0.5).abs() < 1e-8);
6866
assert!((score2 - 0.0).abs() < 1e-8);
6967
}

src/metrics/mean_squared_error.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ mod tests {
6262
let score1: f64 = MeanSquareError {}.get_score(&y_pred, &y_true);
6363
let score2: f64 = MeanSquareError {}.get_score(&y_true, &y_true);
6464

65-
println!("{}", score1);
66-
6765
assert!((score1 - 0.375).abs() < 1e-8);
6866
assert!((score2 - 0.0).abs() < 1e-8);
6967
}

src/metrics/mod.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//!
99
//! * [Classification metrics](struct.ClassificationMetrics.html)
1010
//! * [Regression metrics](struct.RegressionMetrics.html)
11+
//! * [Clustering metrics](struct.ClusterMetrics.html)
1112
//!
1213
//! Example:
1314
//! ```
@@ -54,6 +55,7 @@
5455
pub mod accuracy;
5556
/// Computes Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores.
5657
pub mod auc;
58+
/// Compute the homogeneity, completeness and V-Measure scores.
5759
pub mod cluster_hcv;
5860
pub(crate) mod cluster_helpers;
5961
/// F1 score, also known as balanced F-score or F-measure.
@@ -126,7 +128,7 @@ impl RegressionMetrics {
126128
}
127129

128130
impl ClusterMetrics {
129-
/// Mean squared error, see [mean squared error](mean_squared_error/index.html).
131+
/// Homogeneity and completeness and V-Measure scores at once.
130132
pub fn hcv_score() -> cluster_hcv::HCVScore {
131133
cluster_hcv::HCVScore {}
132134
}
@@ -188,27 +190,29 @@ pub fn r2<T: RealNumber, V: BaseVector<T>>(y_true: &V, y_pred: &V) -> T {
188190
RegressionMetrics::r2().get_score(y_true, y_pred)
189191
}
190192

191-
/// Computes R2 score, see [R2](r2/index.html).
192-
/// * `y_true` - Ground truth (correct) target values.
193-
/// * `y_pred` - Estimated target values.
193+
/// Homogeneity metric of a cluster labeling given a ground truth (range is between 0.0 and 1.0).
194+
/// A cluster result satisfies homogeneity if all of its clusters contain only data points which are members of a single class.
195+
/// * `labels_true` - ground truth class labels to be used as a reference.
196+
/// * `labels_pred` - cluster labels to evaluate.
194197
pub fn homogeneity_score<T: RealNumber, V: BaseVector<T>>(labels_true: &V, labels_pred: &V) -> T {
195198
ClusterMetrics::hcv_score()
196199
.get_score(labels_true, labels_pred)
197200
.0
198201
}
199202

200-
/// Computes R2 score, see [R2](r2/index.html).
201-
/// * `y_true` - Ground truth (correct) target values.
202-
/// * `y_pred` - Estimated target values.
203+
///
204+
/// Completeness metric of a cluster labeling given a ground truth (range is between 0.0 and 1.0).
205+
/// * `labels_true` - ground truth class labels to be used as a reference.
206+
/// * `labels_pred` - cluster labels to evaluate.
203207
pub fn completeness_score<T: RealNumber, V: BaseVector<T>>(labels_true: &V, labels_pred: &V) -> T {
204208
ClusterMetrics::hcv_score()
205209
.get_score(labels_true, labels_pred)
206210
.1
207211
}
208212

209-
/// Computes R2 score, see [R2](r2/index.html).
210-
/// * `y_true` - Ground truth (correct) target values.
211-
/// * `y_pred` - Estimated target values.
213+
/// The harmonic mean between homogeneity and completeness.
214+
/// * `labels_true` - ground truth class labels to be used as a reference.
215+
/// * `labels_pred` - cluster labels to evaluate.
212216
pub fn v_measure_score<T: RealNumber, V: BaseVector<T>>(labels_true: &V, labels_pred: &V) -> T {
213217
ClusterMetrics::hcv_score()
214218
.get_score(labels_true, labels_pred)

0 commit comments

Comments
 (0)