मुझे एक ही समस्या है। मुझे लगता है कि ग्लैमनेट गैर-स्थिर श्रृंखला को संभाल नहीं सकता है, यानी जब श्रृंखला एकीकृत या यादृच्छिक चलती है। जब मैं स्थिर डेटा अनुकरण करता हूं, तो ग्लैमनेट और ओएलएस के परिणाम काफी करीब हैं। लेकिन, सैद्धांतिक रूप से, lambda = 0 के साथ glmnet को ओएलएस के समान परिणाम देना चाहिए, इस पर ध्यान दिए बिना कि श्रृंखला एकीकृत है या नहीं।
नीचे दिया गया कोड 1 99 0 से 1 999 तक कैलिफ़ोर्निया में काउंटी द्वारा Bureau of Labor Statistics Local Area database से समय अवधि कम करके बेरोजगारी का उपयोग करता है। मैंने सुविधा के लिए उस डेटा here की एक CSV प्रतिलिपि रखी। कोड अन्य सभी काउंटी के पिछले मूल्यों पर एक काउंटी के मूल्य को वापस लाता है। # 30, 34, और 36 (ऑरेंज काउंटी, सैक्रामेंटो काउंटी, और सैन बर्नार्डिनो काउंटी) में बेरोजगारी का प्रक्षेपण एकीकृत लगता है। ओएलएस एक स्वैच्छिक गुणांक देता है, जो कि 1 से छोटा होने के लिए बाएं हाथ की काउंटी के पिछले मूल्यों के अनुरूप प्रतिगमन गुणांक देता है। लेकिन ग्लैमनेट 1 से अधिक मान का एक रिटर्न देता है। 1 से बड़ा एक स्वैच्छिक गुणांक एक दे सकता है विस्फोटक पथ कोड परिवार, मानकीकरण, भार, और अवरोध के लिए डिफ़ॉल्ट मानों को बताता है। यह डिफ़ॉल्ट से कहीं अधिक कठोर अभिसरण मानदंड भी सेट करता है।
काउंटी # 30 (ऑरेंज काउंटी) के लिए यह कोड चलाना 0.9 का ओएलएस गुणांक और 1.2 का लासो गुणांक देता है। Not_bonferroni द्वारा सुझाव बिल्कुल वही परिणाम देता है (और यह अवलोकन की तुलना में अधिक regressors के साथ एक बिग के समस्या में लागू नहीं होगा)।
county_wide <- read.csv(file = "county_wide.csv")
# Problematic counties: #30, #34, #36
# All three look like their path is integrated rather than stationary
selected_county <- 30
# Get dimensions
num_entities <- dim(county_wide)[2]
num_observations <- dim(county_wide)[1]
# Dependent variable: most recent observations of selected county
Y <- as.matrix(county_wide[1:(num_observations - 1), selected_county])
# Independent variables: lagged observations of all counties
X <- as.matrix(county_wide[2:num_observations, ])
# Plot the county to show that it is integrated
plot(county_wide[, selected_county])
# Run OLS, which adds an intercept by default
ols <- lm(Y ~ X)
ols_coef <- coef(ols)
# Control glmnet settings
glmnet.control(factory = T)
glmnet.control(fdev = 1e-20)
glmnet.control(devmax = 0.99999999999999999)
# run glmnet with lambda = 0 and spelling out the
# default values for arguments, e.g. intercept
library("glmnet")
lasso0 <- glmnet(y = Y,
x = X,
intercept = T,
lambda = 0,
weights = rep(1, times = num_observations - 1),
alpha = 1,
standardize = T,
family = "gaussian")
lasso_coef <- coef(lasso0)
# compare OLS and LASSO
comparison <- data.frame(ols = ols_coef,
lasso = lasso_coef[1:length(lasso_coef)]
)
comparison$difference <- comparison$ols - comparison$lasso
# Show average difference
mean(comparison$difference)
# Show the two values for the autoregressive parameter
comparison[1 + selected_county, ]
# Note how different these are: glmnet returns a coefficient above 1, ols returns
# a coefficient below 1!!
# not_bonferroni's suggested solution returns exactly the same
# results with these data
mod1 <- lm(Y ~ X)
xmm <- model.matrix(mod1)
mod2 <- glmnet(xmm, Y, alpha = 1, lambda = 0, intercept = T)
coef(mod1)[selected_county + 1] # Index +1 for the intercept
coef(mod2)[selected_county + 2] # Index +2 for the intercepts of OLS and LASSO
आर में विशेष फ़ंक्शन पर ध्यान केंद्रित करने के बजाय, आप यह समझने से बेहतर होंगे कि आपको लगता है कि दो फिट बहुत समान क्यों होना चाहिए। जैसे कहें कि बिना किसी दंड के लासॉ को कुछ और नहीं देना चाहिए, लेकिन ओएलएस फिट होना चाहिए, अगर आपका यही मतलब है। आप यह भी बता सकते हैं कि सूत्रों का उपयोग करके आप ऐसा क्यों सोचते हैं। –
मैंने सोचा कि यह स्पष्ट रूप से स्पष्ट है LASSO बिना दंड के साथ और OLS को एक ही परिणाम देना चाहिए। मैं सोच रहा था कि दो एल्गोरिदम मुझे अलग-अलग अनुमान क्यों देते हैं। –
आपके लिए स्पष्ट क्या है कि आप सभी के लिए स्पष्ट नहीं हो सकते हैं, इसलिए यदि आप स्पष्ट और यथासंभव सटीक होना चाहते हैं। –