Repository: fdtomasi/regain

Issue:
Datasets NoModuleFound Error
Hello!

I have just found that it is not possible to generate synthetic data using your functionalities in `regain/datasets/base.py`

The reason is a recent sklearn update of datasets module, you might want to change line 36 in the file above as following `from sklearn.utils import Bunch`

I'm interested in your graphical lasso with latent variables, would be cool if you can check this issue.
Currently, I have the following error when try to reproduce your example:

`--------------------------------------------------------------------------
ModuleNotFoundError                      Traceback (most recent call last)
<ipython-input-10-c8863a4ca7fc> in <module>
----> 1 from regain.datasets import datasets

~/opt/anaconda3/envs/gglasso/lib/python3.8/site-packages/regain/datasets/__init__.py in <module>
     28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---> 30 from .base import make_dataset

~/opt/anaconda3/envs/gglasso/lib/python3.8/site-packages/regain/datasets/base.py in <module>
     34 
     35 import numpy as np
---> 36 from sklearn.datasets.base import Bunch
     37 
     38 from .gaussian import (

ModuleNotFoundError: No module named 'sklearn.datasets.base'`



Comments:

Patch:
diff --git a/regain/datasets/base.py b/regain/datasets/base.py
index 8613f13..878842e 100644
--- a/regain/datasets/base.py
+++ b/regain/datasets/base.py
@@ -33,15 +33,24 @@ from __future__ import division
 from functools import partial
 
 import numpy as np
-from sklearn.datasets.base import Bunch
-
-from .gaussian import (
-    data_Meinshausen_Yuan, data_Meinshausen_Yuan_sparse_latent,
-    make_covariance, make_fede, make_fixed_sparsity, make_ma_xue_zou,
-    make_ma_xue_zou_rand_k, make_sin, make_sin_cos, make_sparse_low_rank)
-from .ising import ising_sampler, ising_theta_generator
-from .kernels import make_exp_sine_squared, make_ticc
-from .poisson import poisson_sampler, poisson_theta_generator
+from sklearn.utils import Bunch
+
+from regain.datasets.gaussian import data_Meinshausen_Yuan
+from regain.datasets.gaussian import data_Meinshausen_Yuan_sparse_latent
+from regain.datasets.gaussian import make_covariance
+from regain.datasets.gaussian import make_fede
+from regain.datasets.gaussian import make_fixed_sparsity
+from regain.datasets.gaussian import make_ma_xue_zou
+from regain.datasets.gaussian import make_ma_xue_zou_rand_k
+from regain.datasets.gaussian import make_sin
+from regain.datasets.gaussian import make_sin_cos
+from regain.datasets.gaussian import make_sparse_low_rank
+from regain.datasets.ising import ising_sampler
+from regain.datasets.ising import ising_theta_generator
+from regain.datasets.kernels import make_exp_sine_squared
+from regain.datasets.kernels import make_ticc
+from regain.datasets.poisson import poisson_sampler
+from regain.datasets.poisson import poisson_theta_generator
 
 
 def _gaussian_case(
@@ -77,7 +86,8 @@ def _gaussian_case(
     #         normalize_starting_matrices=normalize_starting_matrices,
     #         degree=degree, epsilon=epsilon, keep_sparsity=keep_sparsity,
     #         proportional=proportional)
-    thetas, thetas_obs, ells = func(n_dim_obs=n_dim_obs, n_dim_lat=n_dim_lat, T=T, **kwargs)
+    thetas, thetas_obs, ells = func(
+        n_dim_obs=n_dim_obs, n_dim_lat=n_dim_lat, T=T, **kwargs)
     sigmas = list(map(np.linalg.inv, thetas_obs))
     # map(normalize_matrix, sigmas)  # in place
 
diff --git a/regain/datasets/gaussian.py b/regain/datasets/gaussian.py
index 6aa8ecf..c092cde 100644
--- a/regain/datasets/gaussian.py
+++ b/regain/datasets/gaussian.py
@@ -37,8 +37,10 @@ from scipy.spatial.distance import squareform
 from scipy.stats import norm
 from sklearn.utils import check_random_state
 
-from regain.utils import (
-    ensure_posdef, is_pos_def, is_pos_semidef, normalize_matrix)
+from regain.utils import ensure_posdef
+from regain.utils import is_pos_def
+from regain.utils import is_pos_semidef
+from regain.utils import normalize_matrix
 
 
 def _compute_probabilities(locations, random_state, mask=None):
diff --git a/regain/datasets/kernels.py b/regain/datasets/kernels.py
index 90e81af..b514e73 100644
--- a/regain/datasets/kernels.py
+++ b/regain/datasets/kernels.py
@@ -29,19 +29,19 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """Generate data for kernel-based classes as `KernelTimeGraphicalLasso`."""
 
-from itertools import chain, combinations
+from itertools import chain
+from itertools import combinations
 
 import numpy as np
 from scipy import linalg
 from scipy.spatial.distance import squareform
 from sklearn.cluster import AgglomerativeClustering
-from sklearn.datasets.base import Bunch
+from sklearn.utils import Bunch
 
+from regain.datasets.gaussian import make_ell
 from regain.norm import l1_od_norm
 from regain.utils import is_pos_def
 
-from .gaussian import make_ell
-
 
 def make_exp_sine_squared(n_dim_obs=5, n_dim_lat=0, T=1, **kwargs):
     """Make precision matrices using a temporal sine kernel."""
diff --git a/regain/datasets/multi_class.py b/regain/datasets/multi_class.py
index eb1a7bb..c4e1871 100644
--- a/regain/datasets/multi_class.py
+++ b/regain/datasets/multi_class.py
@@ -28,14 +28,12 @@
 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-import numpy as np
 import networkx as nx
+import numpy as np
+from sklearn.utils import Bunch
 
-
-from sklearn.datasets.base import Bunch
-
-from regain.datasets.poisson import poisson_sampler
 from regain.datasets.ising import ising_sampler
+from regain.datasets.poisson import poisson_sampler
 
 
 def make_multiclass_dataset(


Test patch:
diff --git a/regain/tests/test_datasets.py b/regain/tests/test_datasets.py
index c4f44c6..0ff8598 100644
--- a/regain/tests/test_datasets.py
+++ b/regain/tests/test_datasets.py
@@ -54,7 +54,6 @@ def test_make_dataset_gaussian():
 #     data = datasets.make_dataset(mode='my')
 #     data.X, data.y, data.thetas
 
-
 # def test_make_dataset_gaussian_mys():
 #     """Test Gaussian make_dataset (MYS)."""
 #     data = datasets.make_dataset(mode='mys')
@@ -108,20 +107,22 @@ def test_make_dataset_gaussian_ma():
 #     data = datasets.make_dataset(mode='mak')
 #     data.X, data.y, data.thetas
 
-
 # def test_make_dataset_gaussian_ticc():
 #     """Test Gaussian make_dataset (ticc)."""
 #     data = datasets.make_dataset(mode='ticc', n_dim_lat=0)
 #     data.X, data.y, data.thetas
 
 
-# def test_make_dataset_ising():
-#     """Test default make_dataset with Ising distribution."""
-#     data = datasets.make_dataset(distribution='ising')
-#     data.X, data.y, data.thetas
+def test_make_dataset_ising():
+    """Test default make_dataset with Ising distribution."""
+    data = datasets.make_dataset(
+        distribution='ising', n_samples=10, n_dim_obs=3, n_dim_lat=1, T=1)
+    data.X, data.y, data.thetas
 
 
 def test_make_dataset_poisson():
     """Test default make_dataset with Poisson distribution."""
-    data = datasets.make_dataset(distribution='poisson', update_theta='l1')
+    data = datasets.make_dataset(
+        distribution='poisson', update_theta='l1', n_samples=10, n_dim_obs=3,
+        n_dim_lat=1, T=1)
     data.X, data.y, data.thetas