国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

嶺回歸和lasso回歸的r語言代碼

2019-11-08 02:04:54
字體:
供稿:網(wǎng)友

本篇博文為轉(zhuǎn)載,轉(zhuǎn)載自 li603060971的博客 http://blog.csdn.net/li603060971/article/details/49508279 原文內(nèi)容: setwd(“C:/Users/IBM/Desktop/研一課程/2.2回歸分析/回歸作業(yè)”) #設(shè)定當(dāng)前的工作目錄 shuju=read.table(“shuju.txt”,header=T) shuju #讀取數(shù)據(jù)

使用lm.ridge來進行嶺回歸,其好處是可通過GCV自動選擇調(diào)節(jié)系數(shù),但運算結(jié)果與書上不同

library(MASS) #lm.ridge在MASS包中 sx1<-scale(shujux1)  #先標(biāo)準(zhǔn)化數(shù)據(jù)  sx2<-scale(shujux2) sx3<-scale(shujux3)sx4<?scale(shujux4) sx5<-scale(shujux5)sx6<?scale(shujux6) sx7<-scale(shujux7)sy<?scale(shujuy) shuju.x <- cbind(sx1,sx2,sx3,sx4,sx5,sx6,sx7) la<-seq(0,1,0.05) shuju.ridge<-lm.ridge(sy~sx1+sx2+sx3+sx4+sx5+sx6+sx7-1,lambda=la) #標(biāo)準(zhǔn)化數(shù)據(jù)要-1沒截距項 coef(shuju.ridge)

刪除x4

fly.ridge1<-lm.ridge(sy~sx1+sx2+sx3+sx5+sx6+sx7-1,lambda=seq(0,1,0.001))#嶺回歸

再刪除x5

fly.ridge2<-lm.ridge(sy~sx1+sx2+sx3+sx6+sx7-1,lambda=seq(0,1,0.001))#嶺回歸


setwd(“C:/Users/IBM/Desktop/研一課程/2.2回歸分析/回歸作業(yè)”) #設(shè)定當(dāng)前的工作目錄 shuju=read.table(“shuju.txt”,header=T) shuju #讀取數(shù)據(jù)

使用glmnet函數(shù)求Lasso

library(glmnet) sx1<-scale(shujux1)  #先標(biāo)準(zhǔn)化數(shù)據(jù)  sx2<-scale(shujux2) sx3<-scale(shujux3)sx4<?scale(shujux4) sx5<-scale(shujux5)sx6<?scale(shujux6) sx7<-scale(shujux7)sy<?scale(shujuy) shuju.x <- cbind(sx1,sx2,sx3,sx4,sx5,sx6,sx7) shuju.lasso <- glmnet(shuju.x,sy,alpha=1,lambda=la) coef(shuju.lasso)

附錄數(shù)據(jù)

years y x1 x2 x3 x4 x5 x6 x7 1974 172.9 11246 681 105.9 10183 4110 11242 9 1975 352.94 10335 791 107.4 10414 3996 12693 6.5 1976 447.67 13156 607 114.4 13134 4689 16681 6 1977 404.02 6127 714 110.8 15033 6876 22131 4.75 1978 409.51 27419 911 99.4 17389 8636 31353 4.75 1979 619.71 25633 1231 91.4 21715 12339 43528 9.5 1980 1121.17 95684 2760 90.8 27075 16623 70752 10 1981 1506.94 105987 2651 86.3 31827 19937 125989 16 1982 1105.79 46230 2105 125.3 35393 24787 99468 10.5 1983 933.03 37165 3030 107.4 38823 25112 82478 10.5 1984 1008.54 48787 2810 106.6 46079 24414 54936 8.5 1985 1567.56 75808 2649 115.7 47871 22970 87135 6 1986 1960.06 123128 3031 110.1 54372 24403 129884 6.5 1987 2884.88 371406 3644 105.8 65602 30531 153044 5 1988 2556.72 198569 3690 101.6 74917 37861 215033 5.25


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 明星| 富阳市| 崇礼县| 永昌县| 张家港市| 阿瓦提县| 凯里市| 色达县| 昌吉市| 宁德市| 阿克| 九寨沟县| 什邡市| 舟曲县| 涿鹿县| 望奎县| 阿拉善左旗| 靖州| 峨眉山市| 桐乡市| 灌阳县| 福州市| 哈巴河县| 灵璧县| 宜良县| 阿拉善左旗| 永胜县| 浦北县| 黎川县| 砀山县| 建昌县| 连城县| 丰原市| 吉林市| 宁陕县| 通化市| 盘锦市| 永年县| 崇州市| 定西市| 玉田县|