glmnet 在使用预测时产生错误

glmnet produces an error while using prediction

我似乎对 glmnet 有疑问。我想 运行 一个常规的 LASSO 回归来了解 10 个变量(Dim1Dim2...)中哪个变量对预测我的连续变量 ptScores 的贡献最大。 所有变量都是连续的,validInd是一个data.frame,trainingDatavalidationData都是长度为95的字符向量。

运行以下代码:

lambda_seq <- 10^seq(2, -2, by = -.1)
trainingData = sample(rownames(validInd), 190/2)
validationData = subjects$ID[subjects$ID %in% trainingData]

LASSO = cv.glmnet(data.matrix(validInd[trainingData,-11]), validInd[trainingData,11], lambda = lambda_seq)
plot(LASSO)

predictLASSO = predict.glmnet(object = LASSO, s = "lambda.min", 
                              newx = data.matrix(validInd[validationData,-11]))

glmnet output

并在最后一步后出现此错误:

Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),  : 
  'data' must be of a vector type, was 'NULL'

我也试过在预测中使用所有数据,但得到了同样的错误。

可重现的例子:

科目是这个table:

ID  Name    Year    Dim#1   Dim#2   Dim#3   Dim#4   Dim#5   Dim#6   Dim#7   Dim#8   Dim#9   Dim#10  ptScore
X004 y7 X004    y7  14.2594361560831    1.76025391802766    -0.668570729483714  -1.64432433500694   -3.11101507888161   -2.93744325366336   2.39088933956153    -0.632863861457362  -2.01542044174992   0.397373751034953   0.205293413285948
X006 y7 X006    y7  7.36769839988443    1.40189322331541    -1.51699477009677   -2.11631615238169   2.44537900196125    0.281302344948175   1.04396856774743    -1.21825370453226   9.62767430413176E-02    -4.34274219927117E-02   0.402603441521971
X010 y7 X010    y7  -2.19534888488862   -5.71552997812972   -2.54798524356995   -5.46532854493649   2.0349871802497 1.86977495475099    1.0102785949972 -0.648213341255023  1.19509421829095    -0.474244031626319  0.255199305410578
X011 y7 X011    y7  4.47733296227365    4.41612174858369E-02    1.04199108489624    0.507709900129822   -1.49702171420879   0.562924762828593   -2.09921985421718   -1.10136884350998   -1.14148162529434   -1.87562935354984   0.541577519851939
X012 y7 X012    y7  -6.3214287141386    1.75365412184414    -0.623570056714132  2.62771487690855    -0.755944893491157  1.11946631740662    0.377908536769657   -0.375206246075601  -0.158315945250462  1.60467668360538    0.723807672288481
X015 y7 X015    y7  4.43675650235116    0.125831659587608   -1.63660536215786   0.704457166310484   -0.485788420367662  -1.23623362303915   -2.94185073254018   0.371005042652702   0.390480922397501   -0.751322935004845  0.566289988658306
X016 y7 X016    y7  2.22481961161996    -0.495782079794814  -0.936901673888438  3.46441249413796    -0.299713046858658  1.35032843918957E-02    -0.446639771849217  -2.34040678094425   0.413652502415691   0.352777159566364   0.643054677259255
X022 y7 X022    y7  10.4159916313874    0.363807261537086   2.21572539303282    2.39473567103644    -8.21247405890959E-02   0.121713032667271   -0.172976208049391  0.399694378320414   0.813322631516825   -1.34474965111697   0.177545698165701
X023 y7 X023    y7  -4.8775402107091    -4.12501756265517   -2.27881222191454   -1.86202209268234   -0.502096138361181  1.7091075290976 -0.377341826579625  -0.361068200236776  -1.04929174692168   -1.83743917666367   0.441999945490185
X024 y7 X024    y7  -13.6186193549591   4.53794647377105    -1.1640424147117    0.853074420261857   3.00276105179634    2.2621696100755 1.54863273082483    1.46874484773545    0.642079320801509   -1.17894488952068   0.740868185192386
X025 y7 X025    y7  -8.28369499974165   0.795185031920821   3.36606773135854    1.30335423715504    1.31846438526884    1.92128352973198    0.119247908530787   1.98937148422595    0.98667359874469    0.742089792025553   0.638259141472873
X026 y7 X026    y7  -9.126960905357 1.08725723261223    -0.573951041914609  1.67782607044232    0.198336623247584   -2.86953122246331   1.68852114521665    0.549962201982335   -0.380286483868369  1.01628826947139    0.759959459159294
X028 y7 X028    y7  -5.25213145411614   -1.96999472344059   1.42004682865149    -0.91455749550075   0.53138842064767    0.372108093120868   0.999674017662924   0.983440963089232   -0.45271465928228   1.52238785156272    0.672605306141995
X029 y7 X029    y7  -3.93494816396007   6.84260030634352    4.84132536930456    -0.703242523684553  1.27001300421836    2.88402236252198    -1.41616084473683   0.18558627899548    -0.255520180512287  -0.11825893347637   0.656308969574663
X031 y7 X031    y7  -6.16292963856133   4.85060509570318    4.2126847620166 -2.43553872291154   -0.43435465583943   1.37553276359068    -0.579643934018511  1.17488164948438    1.32392129023095    2.71520764572902    0.718541909152817
X032 y7 X032    y7  -1.7152551073983    -0.234688383679724  1.26286864412284    -1.86322100220324   1.63507032962317    1.94284519738854    -0.367428571302029  -1.62696732853019   -1.20990245118527   1.05664015163771    0.583917996518399
X033 y7 X033    y7  -10.9148039117832   -3.36356028164647   -1.34182187001758   -2.07743121838056   3.3930211353689 -1.69081847936732   1.50845514067627    0.649001132628532   1.8237842283369 1.06407445448196    0.711772373386066
X034 y7 X034    y7  -10.4794967653808   7.01058540479745    2.12270784102553    1.92426221678289    -3.81951360261083   1.98320703989698    0.344382033696651   1.69608467068158    7.70807524085422E-02    0.281493387449773   0.746483819273614
X035 y7 X035    y7  -0.38702071945627   -0.037845940584369  0.253390462384328   2.45809313523985    1.3912538136    0.396616621403596   -0.652711117741324  -2.02482113921603   0.735140206294811   0.114276526211146   0.694123571039207
X036 y7 X036    y7  -3.34295132184417   -4.41772971639855   -2.42496546304556   1.43539718446744    0.24081427494968    1.27215110035618    1.57122124745865    -9.07926785309553E-02   -0.500599334998908  0.3526156338948 0.482638053394283
X037 y7 X037    y7  1.36505270190872    0.154232922168672   3.72787626189391    -3.58555329515882   -0.258287182557876  3.77695923237513    2.06363274503012    -7.44424212333302E-02   -0.243026580519433  0.754189664133906   0.570798239999777
X038 y7 X038    y7  -7.57715353844738   1.49530333294752    -1.3618206776225    0.285673183897211   -2.00257652679547   -2.9316605063682    -5.78101977945745E-02   1.21490778203858    -1.41511921486559   0.910320527049355   0.717900142262124
X040 y7 X040    y7  -3.71657538478269   2.9915033382211 -2.37358232145532   -1.74140110557328   0.879562060220561   -0.186006811914471  -3.03422383938489   7.09245387496289E-02    1.69266042104312    9.11003346977334E-02    0.664458698220819
X041 y7 X041    y7  3.56870600204357    1.89948021381691    -1.18807030156106   -5.11225314209496   -1.72892843911463   0.836946514430054   0.825742473828449   2.18107132564707    -1.41175755455589   -3.15021775639787E-02   0.434972906089723
X046 y7 X046    y7  -3.2070611126168    1.9658134244394 -4.96699587273018   2.58507257721916    0.677391573876038   -0.794142281429037  1.76204196290053    -1.24528928618193   1.30435133802695    -0.348545696553259  0.731839649682648
X048 y7 X048    y7  -8.76908227910536   -2.58866919749497   -3.47359591232635   2.39032746268097    -0.435285448011596  -0.611678098455047  -0.387857745557412  7.5630308277455E-04 2.82150278577457    -1.05165750982245   0.554033843744992
X050 y7 X050    y7  0.475793940378902   0.532527233132171   1.09069683661794    -0.273929007898906  3.56606669789417    -5.32586521203006E-03   -2.06199829748345   0.916218309187297   -0.511609127771478  -0.829866398097593  0.586056512557182
X052 y7 X052    y7  0.437961232041306   -0.525296154559809  4.12777505698584    0.928000030902302   1.50933898151927    0.536752855000547   -1.35328387942828   -3.45343510641525E-02   0.342800240728446   -1.36024230292128   0.503553558040187
X053 y7 X053    y7  -6.35893956287975   -0.481951608723444  4.49223165394607    -0.170823560932413  1.07820528949514    1.90426407261065    1.6976781544118 1.60663679082296    0.377536827292087   -4.32712770127625E-02   0.694829758520922
X054 y7 X054    y7  -1.6173741934411    -0.78544603543625   -1.5586277454018    0.276715960571991   -1.37115552595115   -1.43527489189538   -0.944340962417392  -0.215524444567615  -1.44942417414991   1.11503418539154    0.635810834838745
X058 y7 X058    y7  -0.533953659527016  -3.59419670524299   -6.21847389392613E-02   3.12248184904771    -0.970549462282703  1.73600706110163    0.716076363110235   -2.03157502654338   -0.185983613882669  -1.13023192445807   0.544695504576695
X060 y7 X060    y7  -9.33029002765201   -7.33684242872651   0.251727648993351   1.61228307501029    1.58272329429705    -1.0149446684102    -0.271252146648448  1.44859865101697    0.401334428833948   1.56787478926467    0.591928043482019
X062 y7 X062    y7  4.97202858939999    -0.405994077513881  -4.7355765771677    0.371412533877246   -1.33579080581324   0.341680698379248   0.373782667456135   -1.36795891418662   0.201812628898999   -0.509864200796645  0.412265678072685
X064 y7 X064    y7  1.56303493507485    1.05410634364062    -1.11670857011548   -2.77203704570765   -1.32949528606372   -1.61433165655895   1.32918153646877    -0.312768874242464  -0.688931739007988  0.734214203780031   0.453251813757181
X065 y7 X065    y7  5.05828924636548    0.908758251845031   3.62690379671223    0.164838132208794   0.221854014751618   0.643668333644285   -0.382838756002362  0.676441843706409   1.7103682845196 0.853707219236365   0.32293905373328
X066 y7 X066    y7  -2.40603983747625   7.318117319931  -8.68510001944344E-02   -0.397226292933707  0.152339697912322   2.09248669870129    -0.26977707763143   -1.62178289672658   0.848545563744191   -1.38664444002672   0.700043422915476
X067 y7 X067    y7  -6.62949725610905   1.68523719992851    0.851585358021073   0.951786423099745   -0.616021491459863  -2.82842995392253   1.16159509426505    0.493196821437061   -2.39793328950165   -1.38433590850038   0.601160811740337
X069 y7 X069    y7  1.47542719023891    13.0641832135398    -0.581357473415856  -0.714399303360872  -1.79962725645702   -1.81831420473663   0.610502113121055   -2.706236099573 0.347757363707449   0.293755342189694   0.754695271073973
X070 y7 X070    y7  -1.72139117485005   -3.59264407072097   -1.12987545996396   2.78410751589509    1.18420494996691    -1.66990029841491   -1.31210755888876   -1.64519705582319   -1.17749982138072   -0.789854195043032  0.596281826903686
X072 y7 X072    y7  5.31181586621353    -1.76062594156829   0.978811817696108   0.805416187256626   -0.101536944556724  0.733573760323421   -0.685405370241293  -0.807975536080938  -0.63928589312435   -0.776631166896858  0.342870418080616
X073 y7 X073    y7  -6.83154542538091   -3.92242822624881   -1.30735562714719   -3.13070017851774   -1.07012896190267   1.61291603617646    -0.447759632130991  -0.214244993352655  -0.585066675773694  -0.565011919418235  0.596791110310168
X079 y7 X079    y7  6.19683396427599    -0.45015295862773   -0.589001379439875  -2.85912975635691   -1.96069465183664   -1.33320367366084   2.38154698610703    -0.138158506908214  -1.00374447348715   1.1321702238712 0.29798849247412
X080 y7 X080    y7  6.20901800903392    5.43939505549203    -3.98672804043326   -1.6983742019417    -2.17242534555216   -3.89485271347152   1.60686298747452    -1.5078090986148    -1.05199703793871   -1.5862334877556    0.502676441557364
X082 y7 X082    y7  0.6510182495572 -3.82029305675754   6.14830660856756    2.39568264624447    1.51859911006723    3.43748132085452    2.98300921884542E-03    1.02046197057199E-03    -3.25206786681409E-02   1.37307432097495    0.512226253331402
X084 y7 X084    y7  -5.05915610597868   1.28231684653798    -3.16813452113816   3.81398978942311E-02    -0.26056658322319   -0.607570108068939  -2.26895660622817   -0.280121103992718  1.1581557206668 0.70719181665203    0.758975946511367
X087 y7 X087    y7  -2.87440758130519   -1.56614425216859   -0.214685578900002  2.61868788902779    -0.549949439830095  1.99035737918547    -0.307185247663762  -2.17612427977269   -1.07670874867566   -0.302842450831714  0.639111357004194
X089 y7 X089    y7  -7.2321169776611    -3.45940607493965   -0.896630636558091  -0.624289080870102  3.37973009314874    -0.660949568507029  -1.28382758970168   1.61495582985708    -0.236546232606131  0.743689477887689   0.684182777346267
X090 y7 X090    y7  5.8759449122214 3.27805104437807    -4.07645642306576   1.31539148541223    -0.266021698028939  -0.695419677613201  0.889055163828194   2.32893377555772E-02    1.20358476072801    1.29387076400352    0.419446528984698
X092 y7 X092    y7  5.77420047603891    -1.17329563768878   0.445047009024658   1.2028311977189 -2.09516788500395   -0.503860560134249  -0.440837437962766  1.85501315350221    -0.834761299098988  0.456883238407818   0.343706388464323
X093 y7 X093    y7  9.24685096556148    2.0100787128997 1.681436650306  3.03348652975405    -1.08811689969173   -1.13694466537189   -1.27936614497546   0.348021793918123   -0.429656061648232  -2.27609340681847   0.310623710348242
X094 y7 X094    y7  13.4618107876782    -3.94822016837025   5.05159247878004    1.97556287390166    3.73953089973484    -0.646746115568399  0.965160056105702   0.676367876074884   2.28436942504023    0.537227025430724   0
X100 y7 X100    y7  -5.88798347467999   -2.25570846537281   -2.27257310819712   2.25978831635043    -1.87020337507398   -0.349201035751804  0.244248986726665   -1.55416432151377   -0.903176091406223  0.439194502863558   0.648524886958248
X102 y7 X102    y7  -0.719752186559132  8.18956111960742    2.67845648218982    -2.71471106207068   1.42202429189887    -0.524542225331085  0.447062271900674   0.686175123124667   -1.29836166579492   -0.308340551448655  0.719861271366769
X103 y7 X103    y7  13.2478766364026    0.752585450596604   2.0853104095222 -0.737709229030171  -1.17014153049354   -2.15743132778219   0.654373324873155   -0.927636291502917  -1.85545309230693   -8.19019392079715E-02   0.270433756274452
X105 y7 X105    y7  2.90005648557469    1.7193255259151 -1.21587523209629   -0.427177101578488  -0.627556210423172  -3.99113235385036   1.25742312331302    0.040912848245426   -0.785061544873709  0.493921235479174   0.602263270046018
X106 y7 X106    y7  -4.60472917537252   -5.56640545961895   0.770010852917855   -3.01183314585768   -0.975570824177974  1.73607501284895    -1.28369536274259   0.137828528824118   -1.10854706826854   -0.165315956464549  0.448934375317496
X108 y7 X108    y7  6.5459572482018 -0.792755406433753  -1.95714624076072   -9.50434640321064E-02   -5.30063096031214E-02   -0.38580608118101   -4.11031240875448E-02   0.279569541388208   1.1895509027746 -0.255145074826884  0.113352115264063
X111 y7 X111    y7  -2.42539983228739   -5.41900054828541   1.17653088275733    -0.590160767698779  1.72503186163854    2.01686477861317    1.37795156556941    9.42444506993529E-02    1.63959299252878    -1.18845953874891   0.360989555160435
X112 y7 X112    y7  5.3250172913726 -3.66332040322174   3.3538680995316 2.0479624176086 1.24410020087761    -8.44328442600435E-02   -0.106295599600603  2.30338122773556    0.115211699931763   -0.330963225779836  0.303887289044354
X114 y7 X114    y7  7.24362142680027    -2.04523989830419   -1.68861850924316   1.05488084601232    -2.16757878870729   -1.56116361874208   1.15901958361976    1.51582102854526    -1.77539431197779   0.148843856238521   0.396856395957134
X115 y7 X115    y7  9.70789576557706    2.15415360808665    -0.774767736625052  -2.02622786105656   -6.83272897932898E-03   -1.25979936594413   -0.619358064016897  1.48545525633581    1.23881666328091    -0.473892068691094  0.15763059917753
X118 y7 X118    y7  5.20719333032362    -2.37368717020733   -1.32574911013336   -2.70910591219905   0.945739499835788   -0.394056048048146  -0.299532916420157  0.403463903751592   0.930547005874251   -0.686518257590447  0.192687438493111
X119 y7 X119    y7  0.599963880759262   -1.04269222058587   4.27204142269578    3.20972399672777    -1.33346444179932   -1.23379841268799   -0.514526033076736  -4.03518177966058E-02   -2.20437447323995   -0.155625307891573  0.603501689047888
X120 y7 X120    y7  5.03891337622233    -4.37958479507978   -3.75958410005882   -2.41737564483433   -2.65093584245105   6.38678877360447E-02    -3.76307051597622   -0.306951328262414  5.06385240379942E-02    1.80418407493883    0.352064145163263
X121 y7 X121    y7  2.94579461165834    -1.53944682079578   -2.18511806792739   8.52317889470527E-02    0.773374097566854   0.908527198741026   -1.06436773077894   -0.106908974206049  3.77291796895366    -1.43914893232295   0.485354296934085

validInd 是 table(我已经从 190 行中删除了 125 行,行名在第一列中 - 它不是变量):

rownames    Dim#1   Dim#2   Dim#3   Dim#4   Dim#5   Dim#6   Dim#7   Dim#8   Dim#9   Dim#10  ptScore
X033 y7 -10.9148039117832   -3.36356028164647   -1.34182187001758   -2.07743121838056   3.3930211353689 -1.69081847936732   1.50845514067627    0.649001132628532   1.8237842283369 1.06407445448196    0.711772373386066
X069 y7 1.47542719023891    13.0641832135398    -0.581357473415856  -0.714399303360872  -1.79962725645702   -1.81831420473663   0.610502113121055   -2.706236099573 0.347757363707449   0.293755342189694   0.754695271073973
X118 y7 5.20719333032362    -2.37368717020733   -1.32574911013336   -2.70910591219905   0.945739499835788   -0.394056048048146  -0.299532916420157  0.403463903751592   0.930547005874251   -0.686518257590447  0.192687438493111
X067 y7 -6.62949725610905   1.68523719992851    0.851585358021073   0.951786423099745   -0.616021491459863  -2.82842995392253   1.16159509426505    0.493196821437061   -2.39793328950165   -1.38433590850038   0.601160811740337
X054 y7 -1.6173741934411    -0.78544603543625   -1.5586277454018    0.276715960571991   -1.37115552595115   -1.43527489189538   -0.944340962417392  -0.215524444567615  -1.44942417414991   1.11503418539154    0.635810834838745
X038 y7 -7.57715353844738   1.49530333294752    -1.3618206776225    0.285673183897211   -2.00257652679547   -2.9316605063682    -5.78101977945745E-02   1.21490778203858    -1.41511921486559   0.910320527049355   0.717900142262124
X080 y7 6.20901800903392    5.43939505549203    -3.98672804043326   -1.6983742019417    -2.17242534555216   -3.89485271347152   1.60686298747452    -1.5078090986148    -1.05199703793871   -1.5862334877556    0.502676441557364
X060 y7 -9.33029002765201   -7.33684242872651   0.251727648993351   1.61228307501029    1.58272329429705    -1.0149446684102    -0.271252146648448  1.44859865101697    0.401334428833948   1.56787478926467    0.591928043482019
X112 y7 5.3250172913726 -3.66332040322174   3.3538680995316 2.0479624176086 1.24410020087761    -8.44328442600435E-02   -0.106295599600603  2.30338122773556    0.115211699931763   -0.330963225779836  0.303887289044354
X079 y7 6.19683396427599    -0.45015295862773   -0.589001379439875  -2.85912975635691   -1.96069465183664   -1.33320367366084   2.38154698610703    -0.138158506908214  -1.00374447348715   1.1321702238712 0.29798849247412
X103 y7 13.2478766364026    0.752585450596604   2.0853104095222 -0.737709229030171  -1.17014153049354   -2.15743132778219   0.654373324873155   -0.927636291502917  -1.85545309230693   -8.19019392079715E-02   0.270433756274452
X064 y7 1.56303493507485    1.05410634364062    -1.11670857011548   -2.77203704570765   -1.32949528606372   -1.61433165655895   1.32918153646877    -0.312768874242464  -0.688931739007988  0.734214203780031   0.453251813757181
X114 y7 7.24362142680027    -2.04523989830419   -1.68861850924316   1.05488084601232    -2.16757878870729   -1.56116361874208   1.15901958361976    1.51582102854526    -1.77539431197779   0.148843856238521   0.396856395957134
X034 y7 -10.4794967653808   7.01058540479745    2.12270784102553    1.92426221678289    -3.81951360261083   1.98320703989698    0.344382033696651   1.69608467068158    7.70807524085422E-02    0.281493387449773   0.746483819273614
X041 y7 3.56870600204357    1.89948021381691    -1.18807030156106   -5.11225314209496   -1.72892843911463   0.836946514430054   0.825742473828449   2.18107132564707    -1.41175755455589   -3.15021775639787E-02   0.434972906089723
X119 y7 0.599963880759262   -1.04269222058587   4.27204142269578    3.20972399672777    -1.33346444179932   -1.23379841268799   -0.514526033076736  -4.03518177966058E-02   -2.20437447323995   -0.155625307891573  0.603501689047888
X004 y7 14.2594361560831    1.76025391802766    -0.668570729483714  -1.64432433500694   -3.11101507888161   -2.93744325366336   2.39088933956153    -0.632863861457362  -2.01542044174992   0.397373751034953   0.205293413285948
X106 y7 -4.60472917537252   -5.56640545961895   0.770010852917855   -3.01183314585768   -0.975570824177974  1.73607501284895    -1.28369536274259   0.137828528824118   -1.10854706826854   -0.165315956464549  0.448934375317496
X092 y7 5.77420047603891    -1.17329563768878   0.445047009024658   1.2028311977189 -2.09516788500395   -0.503860560134249  -0.440837437962766  1.85501315350221    -0.834761299098988  0.456883238407818   0.343706388464323
X105 y7 2.90005648557469    1.7193255259151 -1.21587523209629   -0.427177101578488  -0.627556210423172  -3.99113235385036   1.25742312331302    0.040912848245426   -0.785061544873709  0.493921235479174   0.602263270046018
X028 y7 -5.25213145411614   -1.96999472344059   1.42004682865149    -0.91455749550075   0.53138842064767    0.372108093120868   0.999674017662924   0.983440963089232   -0.45271465928228   1.52238785156272    0.672605306141995
X102 y7 -0.719752186559132  8.18956111960742    2.67845648218982    -2.71471106207068   1.42202429189887    -0.524542225331085  0.447062271900674   0.686175123124667   -1.29836166579492   -0.308340551448655  0.719861271366769
X031 y7 -6.16292963856133   4.85060509570318    4.2126847620166 -2.43553872291154   -0.43435465583943   1.37553276359068    -0.579643934018511  1.17488164948438    1.32392129023095    2.71520764572902    0.718541909152817
X053 y7 -6.35893956287975   -0.481951608723444  4.49223165394607    -0.170823560932413  1.07820528949514    1.90426407261065    1.6976781544118 1.60663679082296    0.377536827292087   -4.32712770127625E-02   0.694829758520922
X026 y7 -9.126960905357 1.08725723261223    -0.573951041914609  1.67782607044232    0.198336623247584   -2.86953122246331   1.68852114521665    0.549962201982335   -0.380286483868369  1.01628826947139    0.759959459159294
X037 y7 1.36505270190872    0.154232922168672   3.72787626189391    -3.58555329515882   -0.258287182557876  3.77695923237513    2.06363274503012    -7.44424212333302E-02   -0.243026580519433  0.754189664133906   0.570798239999777
X015 y7 4.43675650235116    0.125831659587608   -1.63660536215786   0.704457166310484   -0.485788420367662  -1.23623362303915   -2.94185073254018   0.371005042652702   0.390480922397501   -0.751322935004845  0.566289988658306
X115 y7 9.70789576557706    2.15415360808665    -0.774767736625052  -2.02622786105656   -6.83272897932898E-03   -1.25979936594413   -0.619358064016897  1.48545525633581    1.23881666328091    -0.473892068691094  0.15763059917753
X084 y7 -5.05915610597868   1.28231684653798    -3.16813452113816   3.81398978942311E-02    -0.26056658322319   -0.607570108068939  -2.26895660622817   -0.280121103992718  1.1581557206668 0.70719181665203    0.758975946511367
X089 y7 -7.2321169776611    -3.45940607493965   -0.896630636558091  -0.624289080870102  3.37973009314874    -0.660949568507029  -1.28382758970168   1.61495582985708    -0.236546232606131  0.743689477887689   0.684182777346267
X070 y7 -1.72139117485005   -3.59264407072097   -1.12987545996396   2.78410751589509    1.18420494996691    -1.66990029841491   -1.31210755888876   -1.64519705582319   -1.17749982138072   -0.789854195043032  0.596281826903686
X121 y7 2.94579461165834    -1.53944682079578   -2.18511806792739   8.52317889470527E-02    0.773374097566854   0.908527198741026   -1.06436773077894   -0.106908974206049  3.77291796895366    -1.43914893232295   0.485354296934085
X040 y7 -3.71657538478269   2.9915033382211 -2.37358232145532   -1.74140110557328   0.879562060220561   -0.186006811914471  -3.03422383938489   7.09245387496289E-02    1.69266042104312    9.11003346977334E-02    0.664458698220819
X050 y7 0.475793940378902   0.532527233132171   1.09069683661794    -0.273929007898906  3.56606669789417    -5.32586521203006E-03   -2.06199829748345   0.916218309187297   -0.511609127771478  -0.829866398097593  0.586056512557182
X048 y7 -8.76908227910536   -2.58866919749497   -3.47359591232635   2.39032746268097    -0.435285448011596  -0.611678098455047  -0.387857745557412  7.5630308277455E-04 2.82150278577457    -1.05165750982245   0.554033843744992
X024 y7 -13.6186193549591   4.53794647377105    -1.1640424147117    0.853074420261857   3.00276105179634    2.2621696100755 1.54863273082483    1.46874484773545    0.642079320801509   -1.17894488952068   0.740868185192386
X029 y7 -3.93494816396007   6.84260030634352    4.84132536930456    -0.703242523684553  1.27001300421836    2.88402236252198    -1.41616084473683   0.18558627899548    -0.255520180512287  -0.11825893347637   0.656308969574663
X058 y7 -0.533953659527016  -3.59419670524299   -6.21847389392613E-02   3.12248184904771    -0.970549462282703  1.73600706110163    0.716076363110235   -2.03157502654338   -0.185983613882669  -1.13023192445807   0.544695504576695
X111 y7 -2.42539983228739   -5.41900054828541   1.17653088275733    -0.590160767698779  1.72503186163854    2.01686477861317    1.37795156556941    9.42444506993529E-02    1.63959299252878    -1.18845953874891   0.360989555160435
X100 y7 -5.88798347467999   -2.25570846537281   -2.27257310819712   2.25978831635043    -1.87020337507398   -0.349201035751804  0.244248986726665   -1.55416432151377   -0.903176091406223  0.439194502863558   0.648524886958248
X016 y7 2.22481961161996    -0.495782079794814  -0.936901673888438  3.46441249413796    -0.299713046858658  1.35032843918957E-02    -0.446639771849217  -2.34040678094425   0.413652502415691   0.352777159566364   0.643054677259255
X032 y7 -1.7152551073983    -0.234688383679724  1.26286864412284    -1.86322100220324   1.63507032962317    1.94284519738854    -0.367428571302029  -1.62696732853019   -1.20990245118527   1.05664015163771    0.583917996518399
X025 y7 -8.28369499974165   0.795185031920821   3.36606773135854    1.30335423715504    1.31846438526884    1.92128352973198    0.119247908530787   1.98937148422595    0.98667359874469    0.742089792025553   0.638259141472873
X065 y7 5.05828924636548    0.908758251845031   3.62690379671223    0.164838132208794   0.221854014751618   0.643668333644285   -0.382838756002362  0.676441843706409   1.7103682845196 0.853707219236365   0.32293905373328
X036 y7 -3.34295132184417   -4.41772971639855   -2.42496546304556   1.43539718446744    0.24081427494968    1.27215110035618    1.57122124745865    -9.07926785309553E-02   -0.500599334998908  0.3526156338948 0.482638053394283
X022 y7 10.4159916313874    0.363807261537086   2.21572539303282    2.39473567103644    -8.21247405890959E-02   0.121713032667271   -0.172976208049391  0.399694378320414   0.813322631516825   -1.34474965111697   0.177545698165701
X062 y7 4.97202858939999    -0.405994077513881  -4.7355765771677    0.371412533877246   -1.33579080581324   0.341680698379248   0.373782667456135   -1.36795891418662   0.201812628898999   -0.509864200796645  0.412265678072685
X046 y7 -3.2070611126168    1.9658134244394 -4.96699587273018   2.58507257721916    0.677391573876038   -0.794142281429037  1.76204196290053    -1.24528928618193   1.30435133802695    -0.348545696553259  0.731839649682648
X120 y7 5.03891337622233    -4.37958479507978   -3.75958410005882   -2.41737564483433   -2.65093584245105   6.38678877360447E-02    -3.76307051597622   -0.306951328262414  5.06385240379942E-02    1.80418407493883    0.352064145163263
X010 y7 -2.19534888488862   -5.71552997812972   -2.54798524356995   -5.46532854493649   2.0349871802497 1.86977495475099    1.0102785949972 -0.648213341255023  1.19509421829095    -0.474244031626319  0.255199305410578
X087 y7 -2.87440758130519   -1.56614425216859   -0.214685578900002  2.61868788902779    -0.549949439830095  1.99035737918547    -0.307185247663762  -2.17612427977269   -1.07670874867566   -0.302842450831714  0.639111357004194
X066 y7 -2.40603983747625   7.318117319931  -8.68510001944344E-02   -0.397226292933707  0.152339697912322   2.09248669870129    -0.26977707763143   -1.62178289672658   0.848545563744191   -1.38664444002672   0.700043422915476
X073 y7 -6.83154542538091   -3.92242822624881   -1.30735562714719   -3.13070017851774   -1.07012896190267   1.61291603617646    -0.447759632130991  -0.214244993352655  -0.585066675773694  -0.565011919418235  0.596791110310168
X094 y7 13.4618107876782    -3.94822016837025   5.05159247878004    1.97556287390166    3.73953089973484    -0.646746115568399  0.965160056105702   0.676367876074884   2.28436942504023    0.537227025430724   0
X023 y7 -4.8775402107091    -4.12501756265517   -2.27881222191454   -1.86202209268234   -0.502096138361181  1.7091075290976 -0.377341826579625  -0.361068200236776  -1.04929174692168   -1.83743917666367   0.441999945490185
X035 y7 -0.38702071945627   -0.037845940584369  0.253390462384328   2.45809313523985    1.3912538136    0.396616621403596   -0.652711117741324  -2.02482113921603   0.735140206294811   0.114276526211146   0.694123571039207
X052 y7 0.437961232041306   -0.525296154559809  4.12777505698584    0.928000030902302   1.50933898151927    0.536752855000547   -1.35328387942828   -3.45343510641525E-02   0.342800240728446   -1.36024230292128   0.503553558040187
X090 y7 5.8759449122214 3.27805104437807    -4.07645642306576   1.31539148541223    -0.266021698028939  -0.695419677613201  0.889055163828194   2.32893377555772E-02    1.20358476072801    1.29387076400352    0.419446528984698
X006 y7 7.36769839988443    1.40189322331541    -1.51699477009677   -2.11631615238169   2.44537900196125    0.281302344948175   1.04396856774743    -1.21825370453226   9.62767430413176E-02    -4.34274219927117E-02   0.402603441521971
X012 y7 -6.3214287141386    1.75365412184414    -0.623570056714132  2.62771487690855    -0.755944893491157  1.11946631740662    0.377908536769657   -0.375206246075601  -0.158315945250462  1.60467668360538    0.723807672288481
X108 y7 6.5459572482018 -0.792755406433753  -1.95714624076072   -9.50434640321064E-02   -5.30063096031214E-02   -0.38580608118101   -4.11031240875448E-02   0.279569541388208   1.1895509027746 -0.255145074826884  0.113352115264063
X072 y7 5.31181586621353    -1.76062594156829   0.978811817696108   0.805416187256626   -0.101536944556724  0.733573760323421   -0.685405370241293  -0.807975536080938  -0.63928589312435   -0.776631166896858  0.342870418080616
X011 y7 4.47733296227365    4.41612174858369E-02    1.04199108489624    0.507709900129822   -1.49702171420879   0.562924762828593   -2.09921985421718   -1.10136884350998   -1.14148162529434   -1.87562935354984   0.541577519851939
X093 y7 9.24685096556148    2.0100787128997 1.681436650306  3.03348652975405    -1.08811689969173   -1.13694466537189   -1.27936614497546   0.348021793918123   -0.429656061648232  -2.27609340681847   0.310623710348242
X082 y7 0.6510182495572 -3.82029305675754   6.14830660856756    2.39568264624447    1.51859911006723    3.43748132085452    2.98300921884542E-03    1.02046197057199E-03    -3.25206786681409E-02   1.37307432097495    0.512226253331402

好的,感谢提供数据。现在有点清楚了。问题是您使用的是 cv.glmnet 对象,而不是 glmnet 对象,如果您这样做:

class(LASSO)
[1] "cv.glmnet"

所以要进行预测,您需要做到:

predictLASSO = predict(object = LASSO, s = "lambda.min", 
               newx = data.matrix(validInd[validationData,-11]))

当你这样做时,调用的函数实际上是 glmnet:::predict.cv.glmnet 你也可以试试:

pred2 = glmnet:::predict.cv.glmnet(LASSO,s="lambda.min",data.matrix(validInd[validationData,-11]))

table(pred2==predictLASSO)

TRUE 
  32