feat: adds F1 and roc_auc_score

This commit is contained in:
Volodymyr Orlov
2020-06-08 14:47:59 -07:00
parent ee581abf70
commit 14113b4152
10 changed files with 167 additions and 6 deletions
+2
View File
@@ -22,6 +22,8 @@ pub trait BaseVector<T: FloatExt>: Clone + Debug {
fn set(&mut self, i: usize, x: T);
fn len(&self) -> usize;
fn to_vec(&self) -> Vec<T>;
}
pub trait BaseMatrix<T: FloatExt>: Clone + Debug {
+5
View File
@@ -27,6 +27,11 @@ impl<T: FloatExt> BaseVector<T> for Vec<T> {
fn len(&self) -> usize {
self.len()
}
fn to_vec(&self) -> Vec<T> {
let v = self.clone();
v
}
}
#[derive(Debug, Clone)]
+10
View File
@@ -22,6 +22,10 @@ impl<T: FloatExt + 'static> BaseVector<T> for MatrixMN<T, U1, Dynamic> {
fn len(&self) -> usize {
self.len()
}
fn to_vec(&self) -> Vec<T> {
self.row(0).iter().map(|v| *v).collect()
}
}
impl<T: FloatExt + Scalar + AddAssign + SubAssign + MulAssign + DivAssign + Sum + 'static>
@@ -384,6 +388,12 @@ mod tests {
assert_eq!(5., BaseVector::get(&v, 1));
}
#[test]
fn vec_to_vec() {
let v = RowDVector::from_vec(vec![1., 2., 3.]);
assert_eq!(vec![1., 2., 3.], v.to_vec());
}
#[test]
fn get_set_dynamic() {
let mut m = DMatrix::from_row_slice(2, 3, &[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
+10
View File
@@ -27,6 +27,10 @@ impl<T: FloatExt> BaseVector<T> for ArrayBase<OwnedRepr<T>, Ix1> {
fn len(&self) -> usize {
self.len()
}
fn to_vec(&self) -> Vec<T> {
self.to_owned().to_vec()
}
}
impl<T: FloatExt + ScalarOperand + AddAssign + SubAssign + MulAssign + DivAssign + Sum>
@@ -351,6 +355,12 @@ mod tests {
assert_eq!(3, v.len());
}
#[test]
fn vec_to_vec() {
let v = arr1(&[1., 2., 3.]);
assert_eq!(vec![1., 2., 3.], v.to_vec());
}
#[test]
fn from_to_row_vec() {
let vec = arr1(&[1., 2., 3.]);