New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
why the three number in 'yhat' is same #216
Comments
Hello, The issue is that your regularization strength, You can compute import numpy as np
from sklearn.metrics import r2_score
from sklearn.metrics import mean_squared_error
from celer.homotopy import _alpha_max_grp
from celer import GroupLasso
np.random.seed(0)
###############################################################################
# Set dataset parameters
# ----------------------
group_sizes = [3, 3, 2, 2, 2]
active_groups = np.ones(5)
active_groups[:3] = 2
np.random.shuffle(active_groups)
np.random.shuffle(active_groups)
groups = np.concatenate(
[size * [i] for i, size in enumerate(group_sizes)]
).reshape(-1, 1)
num_coeffs = sum(group_sizes)
num_datapoints = 3
print("group_sizes:", group_sizes)
print("active_groups:", active_groups)
print("groups:", groups.shape)
print("num_coeffs:", num_coeffs)
print("____________________________________________")
###############################################################################
# Generate data matrix
# --------------------
X = np.array([[0.571, 0.095, 0.767, 0.095, 0.105, 0.767, 0.571, 0.767, 0.095, 0.767, 0.105, 0.767],
[0.584, 0.258, 0.576, 0.258, 0.758, 0.576,
0.584, 0.576, 0.258, 0.576, 0.758, 0.576],
[0.577, 0.961, 0.284, 0.961, 0.644, 0.284, 0.577, 0.284, 0.961, 0.284, 0.644, 0.284]])
print("X:", X.shape)
print("____________________________________________")
###############################################################################
# Generate coefficients
# ---------------------k
w = np.concatenate(
[
np.random.standard_normal(group_size) * is_active
for group_size, is_active in zip(group_sizes, active_groups)
]
)
w = w.reshape(-1, 1)
true_coefficient_mask = w != 0
intercept = 2
print("w:", w.shape)
print("true_coefficient_mask:", true_coefficient_mask.sum())
print("____________________________________________")
###############################################################################
# Generate regression targets
# ---------------------------
y_true = X @ w
y = np.array([[-0.17997138],
[-0.15219182],
[-0.17062552]])
y_true = X @ w
print("y:", y)
MSE1 = mean_squared_error(y, y_true)
print("MSE_yt_y:", MSE1)
print("____________________________________________")
###############################################################################
# Generate estimator and train it
# -------------------------------
groups_celer = [[0, 1, 2], [3, 4, 5], [6, 7], [8, 9], [10, 11]]
X = np.asfortranarray(X)
y = y.squeeze()
alpha_max = _alpha_max_grp(X, y, groups_celer, center=True)
print(
f"Maximal value of regularization strength to get a non zero solution w_hat: {alpha_max:.3f}")
alpha = alpha_max/10
gl = GroupLasso(
groups=groups_celer,
alpha=alpha,
max_iter=1000,
tol=1e-3,
verbose=1,
)
gl.fit(X, y)
###############################################################################
# Extract results and compute performance metrics
# -----------------------------------------------
# Extract info from estimator
yhat = gl.predict(X) # not constant ! |
Hello, thank you for your patient reply. I'd like to apply the program you give to do 4 stains unmixing for an RGB image and only one group in
|
Hello, I don't understand what you mean by "But I found that group[3, 4, 5] in groups_celer = [[0, 1, 2], [3, 4, 5], [6, 7], [8, 9], [10, 11]] is always non-zero, so there's nothing in the image(CD8) after doing stain unmixing"
|
I mean that w_hat[3], w_hat[4] and w_hat[5] in my code is always non-zero, so it is always the situation “if w_hat[3] != 0” be used to unmix PanCK,PDL1 and Hema. Then CD8 is neglected. I have tried to change the value of the alpha parameter in GroupLasso, but w_hat[3], w_hat[4] and w_hat[5] always do contributions. |
This is not a problem of the solver, but of the data you have. My guess is that the features in this group are strongly correlated to your response Please be sure to cite/acknowledge our work if you end up using it in your application. |
OK. I will cite your work. Thank you for your patient answer! |
Hello! I found that |
Hi, the intercept is the constant term in the prediction function (also called bias). If you don't want to use it, you can set |
OK. I get it! Thank you. |
|
Yes, our Beware that we don't have a scaling by sqrt(n_g). More refined weighting of the group penalty should be implemented in the weeks to come, se #220 You can refer to the first lines of the docstring of the GroupLasso class for a math formulation of the objective function. |
Hello!
I don't know why the three number in 'yhat' is same and 'w_hat' is all zero. I'd like to get 'w_hat' with a few non-zero numbers so that I can know which group of 'X' is used. Can you help me with that? Thank you very much!
And the result of the program after running is as follows.
The text was updated successfully, but these errors were encountered: