hacarus / spm-image

Sparse modeling and Compressive sensing in Python
103 stars 29 forks source link

ValueError occurs for multi dimension target in ADMM when fit_itercept is true. #39

Closed syamamori closed 6 years ago

syamamori commented 6 years ago

Issue Description

If fit_intercept flag is True, The below error was called in _set_interept function. This function is inheritance method from sklearn.linearmodel.base. It is problem that the coef shape is matrix in spite of vector assumption in linear_model

This bug is happened in FusedLassoADMM too.

bug code

import numpy as np
from spmimage.linear_model import LassoADMM

X = np.eye(4)  
y = np.array([[1, 1],  
              [1, 0],  
              [0, 1],  
              [0, 0]])  
clf = LassoADMM(fit_intercept=True).fit(X, y)
Traceback (most recent call last): 
File "/Users/yamamoris/hacarus/spm-image/test.py", line 16, in <module> 
    clf = LassoADMM().fit(X, y) 
  File "/Users/yamamoris/hacarus/spm-image/spmimage/linear_model/admm.py", line 126, in fit
    self._set_intercept(X_offset, y_offset, X_scale) 
  File "/Users/yamamoris/.pyenv/versions/hacarus/lib/python3.6/site-packages/sklearn/linear_model/base.py", line 264, in _set_intercept 
    self.coef_ = self.coef_ / X_scale  
ValueError: operands could not be broadcast together with shapes (4,2) (4,)   
tksmd commented 6 years ago

@syamamori This was caused by invalid shape of coef_ and transposing it solved the issue.