public void TestSparsify() { string[] target = iris.Target.Select(t => iris.TargetNames[t]).ToArray(); var clf = new LogisticRegression <string>(random: new Random(0)); clf.Fit(iris.Data, target); Matrix <double> predDD = clf.DecisionFunction(iris.Data); clf.Sparsify(); Assert.IsInstanceOfType(clf.Coef, typeof(SparseMatrix)); Matrix <double> predSD = clf.DecisionFunction(iris.Data); Matrix spData = SparseMatrix.OfMatrix(iris.Data); Matrix <double> predSS = clf.DecisionFunction(spData); clf.Densify(); Matrix <double> predDS = clf.DecisionFunction(spData); Assert.IsTrue(predDD.AlmostEquals(predSD)); Assert.IsTrue(predDD.AlmostEquals(predSS)); Assert.IsTrue(predDD.AlmostEquals(predDS)); }
public void TestSparsify() { string[] target = iris.Target.Select(t => iris.TargetNames[t]).ToArray(); var clf = new LogisticRegression<string>(random: new Random(0)); clf.Fit(iris.Data, target); Matrix<double> predDD = clf.DecisionFunction(iris.Data); clf.Sparsify(); Assert.IsInstanceOfType(clf.Coef, typeof(SparseMatrix)); Matrix<double> predSD = clf.DecisionFunction(iris.Data); Matrix spData = SparseMatrix.OfMatrix(iris.Data); Matrix<double> predSS = clf.DecisionFunction(spData); clf.Densify(); Matrix<double> predDS = clf.DecisionFunction(spData); Assert.IsTrue(predDD.AlmostEquals(predSD)); Assert.IsTrue(predDD.AlmostEquals(predSS)); Assert.IsTrue(predDD.AlmostEquals(predDS)); }