回答:
最後に、次のコードで同じ値を取得しました。
パイソン
# 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