Answers:
最后,我得到了与以下代码相同的值:
蟒蛇
# normalize function that gives the same with R
def mystandardize(D):
S = np.std(D, axis=0, ddof=1)
M = np.mean(D, axis = 0)
D_norm = (D-M)/S
return [D_norm, M, S]
Y_norm_train = pd.DataFrame(mystandardize(Y_train)[0])
glmnet_regr = linear_model.ElasticNet(alpha=1, l1_ratio = 0.01,
fit_intercept = True, normalize = False, tol=0.0000001, max_iter = 100000)
glmnet_regr.fit(X_train, Y_norm_train)
[R
y_norm_train <- scale(y[train_idx])
glmnet_obj_norm <- glmnet(x_train, y_norm_train, alpha=0.01, lambda = 1,
thresh = 1e-07, standardize = FALSE, intercept=TRUE, standardize.response = FALSE)
print_coef(glmnet_obj_norm)
glmnet
。这也应该获得与R中相同的结果。 github.com/civisanalytics/python-glmnet