Main Content

Predict Sugar Content in Grape Berries Using PLS Regression on Hyperspectral Data

This example shows how to perform non-destructive testing (NDT) using hyperspectral data to predict sugar content in grape berries.

Hyperspectral images provide significant information about the quality and composition of the imaged materials. This makes hyperspectral imaging a useful tool for non-destructive testing (NDT) applications, such as maturity monitoring of fruits, without causing any damage to the items being imaged.

This example requires the Hyperspectral Imaging Library for Image Processing Toolbox™. You can install the Hyperspectral Imaging Library for Image Processing Toolbox from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons. The Hyperspectral Imaging Library for Image Processing Toolbox requires desktop MATLAB®, as MATLAB® Online™ and MATLAB® Mobile™ do not support the library.

About the Data Set

In this example, you use a spectral data set of grape berries of three varieties— Syrah, Fer Servadou, and Mauzac— obtained using hyperspectral imaging [1]. The sampling of grape berries started one or two weeks after veraison and preharvest, in the summer of 2020, in three plots in Gaillac, France. As grape berries mature, their density increases because of the increasing sugar content. The plucked grape berries were sorted based on their maturity using densimetric sorting. The grape berries were divided into 274 samples. Each sample of grape berries consists of 100 berries of the same variety and similar maturity level. The grape berries in a sample were arranged in a tray and a hyperspectral camera was set up to acquire top view images of the tray such that no grape berry is occluded. The hyperspectral image was segmented to identify the grape berries in the image.

Segmentation of hyperspectral image of grape berries.

The data set comprises the average spectrum of all 100 berries in each sample for different wavelengths computed from the hyperspectral image of each sample. The hyperspectral data provides information about the chemical composition of the grape berries.

Average spectrum of grape berries for all samples.

Load Data Set

Read the contents of the GrapeBerriesSpectralDataset.csv file, attached to this example as a supporting file, into the workspace as a table. The table contains 274 observations consisting of the data for the 274 samples across 207 variables. The first variable Var1 is the index of the sample, the second variable Variety is the variety of the grape berries in the sample, and the third variable SugarContent_g_l_ is the sugar content in the sample in grams per liter (g/L). The rest of the variables comprise the average spectrum of the sample for 204 different wavelengths.

warning off
T = readtable("GrapeBerriesSpectralDataset.csv")
T=274×207 table
    Var1     Variety     SugarContent_g_l_    x_397_32    x_400_2    x_403_09    x_405_97    x_408_85    x_411_74    x_414_63    x_417_52    x_420_4     x_423_29    x_426_19    x_429_08    x_431_97    x_434_87    x_437_76    x_440_66    x_443_56    x_446_45    x_449_35    x_452_25    x_455_16    x_458_06    x_460_96    x_463_87    x_466_77    x_469_68    x_472_59    x_475_5     x_478_41    x_481_32    x_484_23    x_487_14    x_490_06    x_492_97    x_495_89    x_498_8     x_501_72    x_504_64    x_507_56    x_510_48    x_513_4     x_516_33    x_519_25    x_522_18    x_525_1     x_528_03    x_530_96    x_533_89    x_536_82    x_539_75    x_542_68    x_545_62    x_548_55    x_551_49    x_554_43    x_557_36    x_560_3     x_563_24    x_566_18    x_569_12    x_572_07    x_575_01    x_577_96    x_580_9     x_583_85    x_586_8     x_589_75    x_592_7     x_595_65    x_598_6     x_601_55    x_604_51    x_607_46    x_610_42    x_613_38    x_616_34    x_619_3     x_622_26    x_625_22    x_628_18    x_631_15    x_634_11    x_637_08    x_640_04    x_643_01    x_645_98    x_648_95    x_651_92    x_654_89    x_657_87    x_660_84    x_663_81    x_666_79    x_669_77    x_672_75    x_675_73    x_678_71    x_681_69    x_684_67    x_687_65    x_690_64    x_693_62    x_696_61    x_699_6    x_702_58    x_705_57    x_708_57    x_711_56    x_714_55    x_717_54    x_720_54    x_723_53    x_726_53    x_729_53    x_732_53    x_735_53    x_738_53    x_741_53    x_744_53    x_747_54    x_750_54    x_753_55    x_756_56    x_759_56    x_762_57    x_765_58    x_768_6    x_771_61    x_774_62    x_777_64    x_780_65    x_783_67    x_786_68    x_789_7    x_792_72    x_795_74    x_798_77    x_801_79    x_804_81    x_807_84    x_810_86    x_813_89    x_816_92    x_819_95    x_822_98    x_826_01    x_829_04    x_832_07    x_835_11    x_838_14    x_841_18    x_844_22    x_847_25    x_850_29    x_853_33    x_856_37    x_859_42    x_862_46    x_865_5    x_868_55    x_871_6    x_874_64    x_877_69    x_880_74    x_883_79    x_886_84    x_889_9    x_892_95    x_896_01    x_899_06    x_902_12    x_905_18    x_908_24    x_911_3    x_914_36    x_917_42    x_920_48    x_923_55    x_926_61    x_929_68    x_932_74    x_935_81    x_938_88    x_941_95    x_945_02    x_948_1    x_951_17    x_954_24    x_957_32    x_960_4    x_963_47    x_966_55    x_969_63    x_972_71    x_975_79    x_978_88    x_981_96    x_985_05    x_988_13    x_991_22    x_994_31    x_997_4    x_1000_4    x_1003_5
    ____    _________    _________________    ________    _______    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    _______    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    _______    ________    ________    ________    ________    ________    ________    _______    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    _______    ________    _______    ________    ________    ________    ________    ________    _______    ________    ________    ________    ________    ________    ________    _______    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    _______    ________    ________    ________    _______    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    ________    _______    ________    ________

      1     {'SYRAH'}         144.74          0.14352     0.12199    0.10853     0.098045    0.090435    0.084515    0.078604    0.074226    0.070202    0.066113    0.062973     0.06103    0.058249     0.05695    0.055669    0.054468    0.053297    0.052331    0.051966    0.050817    0.050311    0.049195    0.048511    0.047603    0.046411    0.045673    0.044925    0.044238    0.043639    0.043185    0.042498    0.041802    0.041429    0.041135    0.040697    0.040195    0.040121      0.0398    0.039679    0.039507     0.03944    0.039293    0.039167    0.038939    0.038828    0.038569    0.038418     0.03825     0.03809    0.037976    0.037988    0.037776    0.037621    0.037418    0.037387    0.037258    0.037303    0.037248    0.037338    0.037343    0.037304    0.037437     0.03782    0.038009     0.03838    0.038679    0.039105    0.039613    0.040235    0.040832    0.041586     0.04237    0.043149    0.043909    0.044551    0.045223    0.046112    0.046956    0.047817    0.048573    0.049695    0.050492    0.051144    0.051761    0.052264    0.052524    0.053222    0.053937    0.054916    0.055152    0.054853    0.053983    0.053637    0.053591    0.054212    0.055731    0.057987    0.062159    0.069776    0.081673    0.097671     0.11577    0.13359     0.14994    0.16512     0.17908     0.19198     0.20339     0.21521     0.22529     0.23591     0.24542     0.25461     0.26295     0.27155     0.27897     0.28664      0.2939     0.30107      0.3079     0.31431      0.3213     0.32774     0.33251      0.3354     0.34154     0.34655    0.35065     0.35628     0.35999     0.36426     0.36872     0.37219     0.37606    0.38049     0.38415     0.38852     0.39138     0.39561      0.3984     0.40089      0.4029     0.40519     0.40706     0.40916     0.40969     0.40964     0.40936     0.40954     0.41082     0.41236     0.41475     0.41704     0.42148      0.4244      0.4254     0.42666     0.42625     0.42555    0.42578     0.42514    0.42649     0.42615     0.42554     0.42663       0.426     0.42516    0.42572     0.42531      0.4245     0.42491     0.42457     0.42486     0.42406     0.4234     0.42356     0.42067     0.41718     0.41373     0.40839     0.40271     0.39406      0.3859     0.37794     0.36805     0.35556    0.34312     0.32769     0.31661      0.3094    0.30607     0.30322     0.30686     0.30505     0.30583     0.31296     0.31595     0.32199     0.32836     0.33327     0.34317     0.35192    0.35996     0.34038 
      2     {'SYRAH'}         163.25          0.14203     0.12158     0.1076     0.096139    0.089941    0.083718    0.077647    0.072666    0.068645    0.064228    0.061463    0.059249    0.056922     0.05533    0.053839    0.052356     0.05144    0.050577    0.049504    0.048914    0.047966    0.047096    0.046179    0.045225    0.044439    0.043522    0.042784    0.042033    0.041502    0.040862    0.040222    0.039661    0.039288    0.038861    0.038468    0.038025    0.037809    0.037495    0.037441    0.037161    0.037109    0.036901    0.036692    0.036643    0.036443    0.036299     0.03609    0.035946    0.035645    0.035521    0.035637    0.035493     0.03522    0.034972    0.034867    0.034636    0.034749    0.034626    0.034503    0.034449    0.034558    0.034581    0.034695    0.034788    0.035088    0.035186     0.03532    0.035584    0.035982    0.036286    0.036685    0.037075    0.037571    0.038049    0.038474    0.038648    0.039148    0.039507    0.039914    0.040428    0.040915    0.041397    0.042062    0.042541    0.043017    0.043492     0.04422    0.045028    0.045964    0.046288    0.046483    0.046452    0.046805    0.047334    0.048376    0.050055    0.052404    0.056056    0.062173    0.071268    0.083469    0.097018    0.11076     0.12351    0.13625     0.14832     0.15991      0.1706     0.18137      0.1917     0.20228     0.21219     0.22166     0.23061     0.24008     0.24887     0.25744     0.26578     0.27408     0.28202     0.28991     0.29743     0.30548     0.31174     0.31591      0.3229     0.32918    0.33467     0.34164     0.34655     0.35208     0.35702     0.36231     0.36758    0.37308     0.37697     0.38305     0.38705      0.3921     0.39614     0.39997     0.40195     0.40624     0.40848     0.41065     0.41262     0.41438     0.41503     0.41564     0.41732     0.41924     0.42271     0.42587     0.43133     0.43462     0.43568     0.43701     0.43641     0.43645    0.43713     0.43833    0.43863     0.44012     0.43854      0.4392     0.43943     0.43939    0.43973     0.43881     0.43849     0.43899     0.43816     0.43818     0.43845    0.43767     0.43711     0.43528     0.43181     0.42742       0.423     0.41584     0.40912     0.40042     0.39148     0.38089     0.36905    0.35472     0.33882     0.32677     0.31838    0.31277     0.31256     0.31236     0.31304     0.31402     0.31576     0.32116     0.32547     0.33323     0.34021     0.35028     0.35794    0.36547     0.34206 
      3     {'SYRAH'}          178.4          0.15241     0.12848    0.11514      0.10437    0.097142    0.090982      0.0846    0.080265    0.076254    0.072553    0.069389    0.066697    0.064854    0.062721    0.061434     0.05986    0.058787    0.057749    0.056716    0.055729    0.055043    0.053938    0.053172    0.052053    0.050919    0.050077    0.049289    0.048376    0.047713    0.047176    0.046678    0.045928    0.045453    0.044994    0.044504    0.044093    0.043828    0.043506    0.043297    0.043184    0.043047    0.042781    0.042677    0.042518    0.042312    0.042084    0.041871    0.041531    0.041414    0.041363    0.041472    0.041271    0.040913    0.040518    0.040363    0.040225    0.040207    0.040109    0.040066    0.039969    0.039977    0.039982    0.040154    0.040216    0.040457    0.040478    0.040756    0.040984    0.041443    0.041863    0.042268    0.042741    0.043324    0.043771    0.044117    0.044347     0.04475    0.044964    0.045452    0.045748    0.046371    0.046634    0.047201    0.047554    0.048058    0.048658    0.049324    0.050129     0.05091    0.051587    0.052008     0.05203    0.052189    0.052493     0.05336      0.0547    0.056747    0.059845    0.065259    0.073386    0.083597    0.095119    0.10705     0.11805    0.12957     0.14059     0.15159     0.16165     0.17214     0.18194     0.19272     0.20261     0.21274      0.2221     0.23205     0.24131     0.25099     0.25996     0.26914     0.27856     0.28675     0.29548     0.30523     0.31324     0.32033     0.32747     0.33571    0.34227     0.34959     0.35734     0.36465     0.37081     0.37772     0.38395    0.39017     0.39617     0.40295     0.40962      0.4153     0.42099     0.42584     0.43023     0.43459     0.43865     0.44156     0.44514     0.44744     0.44863     0.45065     0.45287     0.45573     0.45942     0.46375     0.46956     0.47496     0.47898     0.48064     0.48117     0.48175    0.48235     0.48266    0.48421     0.48524      0.4859     0.48684     0.48627     0.48561    0.48709     0.48647     0.48695     0.48621     0.48674     0.48685     0.48575    0.48473     0.48305     0.48125     0.47683     0.47269     0.46499     0.45668     0.44716     0.43887     0.42931     0.41677     0.40067    0.38661     0.36793     0.35196     0.34411    0.33999     0.33436     0.33625     0.33527     0.33391     0.33924     0.34082     0.34757     0.35299     0.36137     0.37059     0.37614     0.3874     0.35448 
      4     {'SYRAH'}         193.54          0.15067     0.12968    0.11573      0.10583    0.097539    0.091167    0.085804    0.081407    0.077536    0.073961    0.071315    0.068573    0.066456    0.064907    0.063023    0.061727    0.060656    0.059686    0.058813    0.058057    0.057028    0.056062    0.055267    0.054235    0.053128     0.05226    0.051507    0.050742    0.050071    0.049359     0.04883    0.048067    0.047577    0.047008    0.046692    0.046218     0.04588    0.045661    0.045535    0.045415     0.04532    0.045042     0.04482    0.044751     0.04466    0.044356    0.044138     0.04386    0.043574    0.043537     0.04356    0.043283    0.043017    0.042697    0.042675    0.042467    0.042411    0.042305    0.042267    0.042107    0.042115    0.042103    0.042303    0.042315    0.042542    0.042575    0.042833    0.043031    0.043427    0.043698    0.044174    0.044492    0.044983    0.045391    0.045647    0.045754      0.0461    0.046371    0.046821    0.047071     0.04739    0.047741    0.048115    0.048462    0.048916    0.049469    0.050199    0.050862    0.051792     0.05245    0.052704     0.05283     0.05315    0.053667    0.054802    0.056372    0.058434    0.061504    0.066572    0.073598    0.082544    0.092403    0.10279      0.1125     0.1226     0.13268     0.14259     0.15197     0.16196     0.17129     0.18109     0.19057     0.20018     0.20908     0.21844     0.22776     0.23669     0.24561     0.25439     0.26302      0.2713     0.27946     0.28929     0.29722      0.3036     0.31089     0.31802    0.32449     0.33199     0.33925      0.3461      0.3521      0.3583     0.36442    0.37032     0.37628     0.38319     0.38903     0.39491     0.40059      0.4049     0.40904     0.41346     0.41722     0.42087     0.42378     0.42573     0.42766     0.42908     0.43207     0.43544     0.43746     0.44222     0.44704     0.45308     0.45678      0.4578      0.4576     0.45894    0.45971     0.46004    0.46152     0.46232      0.4631     0.46271     0.46313     0.46228    0.46393     0.46313     0.46351     0.46409     0.46371     0.46377     0.46265    0.46198     0.46198     0.45898     0.45511     0.45296     0.44634     0.43976     0.43135     0.42183     0.41335      0.4012     0.38944    0.37472     0.35766     0.34487     0.33529    0.33053     0.32944     0.32742     0.32624     0.32619     0.32961     0.33472     0.33743     0.34273     0.34818     0.35808     0.36281    0.37441     0.34218 
      5     {'SYRAH'}         156.52          0.14941     0.12574    0.11301       0.1014    0.093891    0.087433    0.081891    0.076906    0.072377    0.068974     0.06596    0.063036    0.060964    0.059301      0.0575    0.056183    0.055264    0.054196    0.053303    0.052386     0.05174    0.050648     0.04963    0.048762    0.047948    0.047022    0.046491    0.045702    0.045177    0.044522    0.043878    0.043236    0.042772    0.042416    0.041964    0.041629    0.041309    0.041169    0.041148    0.041121     0.04112    0.040922    0.040903    0.040837    0.040677    0.040451    0.040253    0.040064    0.039968    0.039971    0.040102    0.039887    0.039677    0.039344    0.039376     0.03932    0.039279    0.039285    0.039284    0.039265    0.039386    0.039487    0.039751    0.040001    0.040397    0.040628    0.041006    0.041503    0.042114    0.042581     0.04343      0.0442    0.045037    0.045796    0.046529    0.047007     0.04774    0.048312    0.049205    0.049927    0.050864    0.051513    0.052031    0.052719    0.053283    0.053841     0.05467    0.055527    0.056608    0.057265    0.057284    0.056738    0.056406    0.056423    0.057319    0.058661    0.060919    0.064857    0.071917    0.082818    0.097144     0.11311     0.1293     0.14401    0.15835     0.17153     0.18411     0.19555     0.20695     0.21761      0.2284     0.23846     0.24838     0.25744     0.26647     0.27536     0.28401     0.29223      0.3004     0.30826     0.31562     0.32304     0.33182     0.33878     0.34423     0.34959     0.35624    0.36125     0.36682     0.37262     0.37835     0.38348     0.38832     0.39298    0.39736     0.40175     0.40748     0.41164     0.41671     0.42025     0.42362      0.4256     0.42976     0.43152     0.43356     0.43472     0.43425     0.43528      0.4359      0.4369     0.43823     0.44081     0.44384     0.44771     0.45305      0.4551     0.45636     0.45518      0.4547    0.45511     0.45497    0.45558     0.45595     0.45486     0.45501     0.45507      0.4549    0.45469     0.45359     0.45343     0.45235     0.45287     0.45281     0.45248    0.45043     0.44803     0.44817     0.44362     0.43922     0.43189     0.42456     0.41554     0.40834      0.3988      0.3874     0.37368    0.35787     0.34307     0.33105     0.32248    0.31529     0.31469      0.3161     0.31664     0.31708     0.32285     0.32456     0.33147     0.33705     0.34468     0.35458     0.36018    0.37375     0.34212 
      6     {'SYRAH'}         161.57          0.16084     0.13783    0.12082      0.10868     0.10081    0.093185    0.087158    0.081672    0.076695    0.073037    0.069684    0.066359    0.063897    0.062556    0.060657    0.058564    0.057902     0.05677    0.055824    0.054813    0.053835    0.052594    0.051861    0.050677    0.049396    0.048561    0.047916    0.047067    0.046488    0.045774    0.045094    0.044407    0.044037    0.043507    0.043123    0.042658    0.042371    0.042214    0.042053    0.041883    0.041931    0.041649    0.041587    0.041393    0.041357    0.041031    0.040936    0.040609    0.040487    0.040364    0.040412    0.040334    0.040119     0.03984    0.039826    0.039665    0.039637    0.039734     0.03974    0.039705     0.03983    0.039904    0.040248    0.040421    0.040839    0.041077    0.041479    0.042027    0.042636    0.043246    0.044051    0.044795    0.045625    0.046447    0.047123    0.047592    0.048431    0.049146    0.050032    0.050751    0.051759    0.052477    0.053288    0.053818    0.054535    0.055002    0.055923    0.056958    0.058108    0.058805     0.05885    0.058509     0.05842    0.058557    0.059625    0.061438    0.064195    0.068612    0.076346    0.087937     0.10282     0.11937    0.13601     0.15128    0.16585      0.1799      0.1928     0.20507     0.21737     0.22856     0.24044     0.25143     0.26206     0.27198     0.28266     0.29226     0.30193     0.31107     0.32003     0.32877     0.33688     0.34497     0.35485       0.362     0.36869     0.37532     0.38221    0.38815     0.39513      0.4018     0.40802     0.41397     0.41989     0.42529    0.43156     0.43646     0.44273     0.44806     0.45379     0.45909     0.46292     0.46747     0.47066     0.47418     0.47668     0.47889     0.48006     0.48161     0.48316     0.48492     0.48719     0.49069     0.49473       0.499     0.50548     0.50884     0.51014     0.50941     0.50956    0.51097      0.5122    0.51234     0.51366     0.51185     0.51279     0.51324     0.51375    0.51285     0.51215     0.51256     0.51341     0.51312     0.51355     0.51255    0.51209     0.51031     0.50908     0.50507     0.50308      0.4935     0.48551     0.47577     0.46774     0.45623     0.44297     0.43006    0.41332     0.39348     0.37828     0.37086    0.36355     0.36138     0.36096     0.36102     0.36446     0.36474     0.37159     0.37497      0.3831     0.38993     0.39988     0.40616    0.41912     0.38283 
      7     {'SYRAH'}         166.62          0.14462     0.12211    0.10695     0.095976    0.088384    0.081747    0.076841    0.071082    0.067949    0.064671    0.061443    0.058034    0.056287    0.054407    0.053002    0.051462    0.050352     0.04959     0.04873    0.047557     0.04684    0.046031    0.044983    0.043931    0.043248    0.042232    0.041592    0.040952    0.040122    0.039478    0.039079    0.038502    0.037915    0.037599    0.037235    0.036895    0.036684    0.036408    0.036321    0.036207    0.036201     0.03591    0.035787     0.03549    0.035405     0.03535    0.035207    0.034947    0.034736    0.034535    0.034831    0.034653    0.034501    0.034232    0.034044    0.034007    0.034028    0.033932    0.033967    0.033935    0.033969    0.034063    0.034222     0.03445    0.034643    0.034888    0.035231     0.03559    0.036114    0.036583    0.037198    0.037886    0.038473    0.039146    0.039771    0.040029    0.040658     0.04119    0.041958    0.042618    0.043267    0.043863    0.044486    0.044816    0.045421    0.045999    0.046717    0.047409    0.048405    0.049019    0.049009    0.048739    0.048587    0.048784    0.049709    0.050996    0.053217    0.057081    0.063575    0.073504    0.086485     0.10081    0.11525     0.12856    0.14147     0.15358     0.16496     0.17565     0.18617     0.19607     0.20655     0.21589     0.22546     0.23398      0.2427     0.25113     0.25933     0.26721     0.27526      0.2829     0.29009     0.29723     0.30572     0.31185     0.31759     0.32304     0.32959    0.33453      0.3402     0.34589     0.35167     0.35698     0.36145     0.36644     0.3713     0.37532      0.3809      0.3853      0.3898      0.3942      0.3971     0.40014     0.40361     0.40575     0.40763     0.41027      0.4103     0.41075     0.41197     0.41366     0.41541     0.41746      0.4216     0.42511     0.43078     0.43323     0.43318      0.4325     0.43367    0.43351     0.43349    0.43483     0.43425     0.43397     0.43482      0.4338     0.43425    0.43435     0.43214     0.43264     0.43361     0.43269     0.43317     0.43216    0.42977     0.43018     0.42726     0.42356     0.41982     0.41364     0.40697     0.39925     0.39057     0.38255     0.37151     0.35812    0.34354     0.32752     0.31708     0.30787    0.30478     0.30373     0.30261     0.30282      0.3033     0.30826     0.30968     0.31357     0.31992     0.32686     0.33501      0.3414    0.35435     0.32589 
      8     {'SYRAH'}         169.98          0.16365     0.13879    0.12246      0.10988      0.1015    0.094093    0.087427    0.082324    0.077943    0.073791    0.069677    0.066982     0.06492    0.062796    0.060874    0.059313    0.058041     0.05705    0.055847     0.05478    0.054116    0.052764    0.051346    0.050447    0.049595    0.048325    0.047587    0.046755    0.046063    0.045308    0.044688     0.04409    0.043626    0.043014     0.04262    0.042158    0.041787    0.041474    0.041257    0.041117    0.041116    0.040767    0.040776    0.040495     0.04033    0.040068    0.039838    0.039474    0.039471    0.039409    0.039538    0.039378    0.038984    0.038663    0.038595    0.038412    0.038452     0.03835    0.038312    0.038338    0.038378    0.038403    0.038624    0.038834     0.03907    0.039221    0.039585     0.03999    0.040349     0.04088    0.041478    0.042143    0.042728    0.043368    0.043963    0.044232    0.044902    0.045356    0.046037    0.046701    0.047338    0.047959    0.048674    0.049227    0.049889    0.050496    0.051373    0.052281    0.053305    0.054237    0.054571    0.054361    0.054686    0.055158    0.056374    0.058064    0.060801    0.064997    0.071825    0.081651    0.094118     0.10809    0.12224     0.13516    0.14823     0.16069     0.17282     0.18415     0.19567     0.20666     0.21788     0.22862      0.2398     0.24974     0.26024     0.27012     0.28021     0.28988     0.29964     0.30871     0.31735     0.32673     0.33693     0.34485     0.35168     0.35957     0.36813    0.37427     0.38219     0.38981     0.39733     0.40403       0.411      0.4175    0.42391      0.4299     0.43755     0.44377     0.45026     0.45663     0.46143      0.4656      0.4708     0.47385     0.47759     0.48097     0.48305     0.48492     0.48675     0.48972     0.49278     0.49646     0.50074     0.50665     0.51318     0.51649     0.51855      0.5189     0.51999       0.52     0.52196    0.52295      0.5233     0.52383     0.52556     0.52522     0.52499    0.52558     0.52421     0.52532     0.52514     0.52508     0.52615     0.52575    0.52357     0.52241     0.52148     0.51545     0.51135     0.50403     0.49589      0.4865     0.47618     0.46376     0.45033     0.43375    0.41717     0.39685     0.38331     0.37303    0.36521     0.36426     0.36377     0.36401     0.36525     0.36594     0.37223     0.37629     0.38482     0.39078     0.39805     0.40542    0.41912     0.37999 
      9     {'SYRAH'}         176.72          0.14929     0.12357     0.1102      0.10046    0.092379    0.085111    0.079623    0.074674    0.070239    0.067097    0.063361    0.060997    0.058657    0.057144    0.055334    0.054356    0.052931    0.052217    0.051317    0.050251    0.049262    0.048289    0.047267    0.046357    0.045544    0.044601    0.043875    0.043031    0.042614    0.041904    0.041484    0.040626    0.040272    0.039652    0.039345     0.03902    0.038669    0.038521    0.038317     0.03827    0.038342    0.038006    0.037891    0.037856    0.037673    0.037494    0.037261    0.036919    0.036849    0.036802    0.036843    0.036637    0.036319    0.036122    0.036129    0.035973    0.035841    0.035793     0.03579    0.035812    0.035907    0.035978    0.036143    0.036162    0.036537    0.036699    0.036963    0.037326    0.037832    0.038187    0.038736    0.039217    0.039849    0.040363    0.040843     0.04108    0.041682    0.042026    0.042657    0.043071    0.043674    0.044087    0.044554    0.045002    0.045485    0.045998     0.04676    0.047527    0.048383    0.048974    0.049155    0.049161    0.049317    0.049733    0.050707    0.052309    0.054788    0.058343    0.064212    0.072573    0.083031    0.094649    0.10646     0.11742    0.12854     0.13926     0.14977      0.1596      0.1696     0.17923     0.18907     0.19876     0.20828     0.21715     0.22634     0.23494     0.24401     0.25233     0.26106     0.26945     0.27716     0.28509     0.29413       0.301     0.30735     0.31378     0.32088    0.32665     0.33318     0.34036     0.34638     0.35208     0.35813     0.36303    0.36853     0.37394      0.3803     0.38536     0.39138     0.39589     0.40027     0.40364     0.40778     0.41078     0.41359       0.416     0.41728     0.41896      0.4199     0.42184     0.42406     0.42718     0.43135     0.43621     0.44154     0.44366     0.44485     0.44542     0.44543    0.44531     0.44646    0.44776     0.44775     0.44817     0.44853     0.44754     0.44787    0.44758     0.44638     0.44657     0.44724     0.44608     0.44563     0.44599     0.4449     0.44489     0.44292     0.43799      0.4352     0.42784      0.4204     0.41303     0.40526     0.39561     0.38522     0.36908    0.35614     0.34016     0.32695     0.31561     0.3128     0.30968     0.30959     0.31088     0.30804     0.31349     0.31577     0.32202     0.32425     0.33111     0.34091     0.34837    0.35784      0.3328 
     10     {'SYRAH'}         183.45          0.16152     0.13784     0.1209      0.10973     0.10038    0.093568    0.087626     0.08191     0.07705    0.073116    0.069792    0.066448     0.06443    0.062808    0.060363    0.058848    0.058194      0.0572    0.056101    0.054764    0.053268    0.052491     0.05171    0.050627    0.049367    0.048449    0.047633    0.046832    0.046205    0.045395    0.044868    0.044092    0.043529    0.043054    0.042558    0.042125    0.041885     0.04162    0.041482    0.041298    0.041146     0.04087    0.040746    0.040636    0.040488    0.040154    0.039975    0.039607    0.039529    0.039376    0.039349    0.039272    0.039007    0.038679    0.038494    0.038332    0.038335     0.03824    0.038176    0.038145     0.03821    0.038335    0.038404    0.038625    0.038825    0.038939    0.039169    0.039416    0.039899    0.040208    0.040726    0.041212    0.041689    0.042327    0.042661    0.042936    0.043346    0.043709    0.044288    0.044647    0.045273    0.045646    0.046148    0.046593    0.047251    0.047831      0.0485    0.049291    0.050326    0.051007     0.05136    0.051355    0.051708    0.052101    0.053074    0.054784    0.057117    0.060766    0.066851     0.07529    0.086037    0.097882    0.11013     0.12145    0.13303     0.14455     0.15568     0.16618     0.17716     0.18755     0.19845     0.20875     0.21932     0.22887     0.23978      0.2493     0.25925     0.26887     0.27843     0.28807     0.29699     0.30589     0.31694     0.32521     0.33306     0.34063     0.34882    0.35614     0.36419     0.37202        0.38      0.3869     0.39395     0.40059    0.40801     0.41445     0.42201     0.42823     0.43578     0.44159     0.44633      0.4512      0.4569     0.46074     0.46486     0.46805     0.47074     0.47224     0.47529      0.4777     0.48137      0.4856     0.49033     0.49579     0.50309     0.50672     0.50823       0.509     0.50956    0.51097     0.51223    0.51365     0.51572     0.51495      0.5157     0.51727      0.5177    0.51726     0.51746     0.51748     0.51784      0.5181     0.51777     0.51757     0.5159     0.51494      0.5123     0.50877     0.50505     0.49593     0.48792      0.4791     0.46899     0.45717     0.44413     0.42811    0.40989     0.39103     0.37551     0.36558    0.36048     0.35494     0.35497     0.35415     0.35592     0.36079     0.36321     0.36638      0.3735     0.38237     0.38778     0.40013    0.40677     0.37688 
     11     {'SYRAH'}         161.57          0.15107     0.12769    0.11283       0.1021    0.094121    0.085879    0.080362    0.075438    0.071305    0.067135    0.063958     0.06086    0.058893    0.056974    0.054965    0.053768    0.052606     0.05192    0.050603    0.049837    0.048783    0.048014    0.047106    0.045965    0.045107    0.044081    0.043421    0.042728    0.041968    0.041452     0.04073    0.040233     0.03979    0.039234    0.038863    0.038436    0.038119    0.038001    0.038041    0.037917    0.037802    0.037397    0.037462    0.037278    0.037188    0.036942    0.036856    0.036624    0.036482    0.036451    0.036485    0.036339    0.036138    0.035956    0.035842     0.03577    0.035687    0.035624    0.035836    0.035727     0.03584    0.035828    0.036117    0.036358    0.036792    0.037003    0.037369    0.037758    0.038326    0.039002    0.039592    0.040298    0.041116    0.041688    0.042284    0.042705    0.043565    0.044049    0.044812    0.045351    0.046195    0.046809    0.047428    0.047961    0.048524    0.049104    0.049787    0.050639    0.051732     0.05227    0.052287    0.051979    0.051833    0.052187    0.053219    0.054717    0.057107    0.061181    0.068052    0.078065    0.091092     0.10547    0.11999     0.13336    0.14642     0.15883     0.17038     0.18125     0.19213      0.2024     0.21297      0.2229     0.23255     0.24162     0.25082     0.25951     0.26844     0.27658     0.28473     0.29239      0.2997     0.30716     0.31589     0.32219     0.32778     0.33367      0.3398    0.34508     0.35051     0.35685     0.36267     0.36768     0.37231     0.37707      0.382     0.38618     0.39194     0.39699     0.40163     0.40538      0.4087     0.41196     0.41458     0.41701     0.41888      0.4214     0.42172     0.42271     0.42291     0.42546      0.4266     0.42852     0.43186     0.43612     0.44103     0.44358     0.44528     0.44438      0.4442    0.44324     0.44391    0.44498     0.44548     0.44488     0.44512     0.44403     0.44417    0.44389     0.44386      0.4439     0.44293     0.44348     0.44337     0.44146    0.44025     0.44029     0.43785     0.43313     0.43054     0.42551      0.4178     0.40887     0.40106     0.39164     0.38062     0.36666    0.35323     0.33694     0.32413     0.31665    0.31065     0.31144     0.30992     0.30974     0.31262     0.31429       0.317     0.32033     0.32903     0.33578     0.34221     0.34938    0.36339     0.33925 
     12     {'SYRAH'}         164.93          0.16505     0.13903    0.12255      0.11103     0.10126    0.094408    0.087234    0.081801    0.077233    0.073324    0.070119    0.066285    0.064126    0.062554    0.060528     0.05904     0.05777    0.057012    0.055628    0.054755    0.053716    0.052519     0.05154    0.050405    0.049507    0.048564      0.0475    0.046609    0.045994    0.045443    0.044666    0.044123    0.043696    0.043037    0.042573     0.04216    0.041936    0.041552    0.041411    0.041411    0.041392    0.041205    0.041041    0.040756    0.040735    0.040516    0.040313    0.040073    0.040015    0.039885    0.039957    0.039767    0.039592    0.039251    0.039157    0.039188    0.039221    0.039158    0.039301    0.039195    0.039329     0.03947    0.039793    0.040005    0.040422    0.040665    0.041092    0.041671    0.042266    0.042994    0.043697    0.044475    0.045342    0.046132     0.04682    0.047406    0.048177    0.048765    0.049849    0.050703    0.051609    0.052413    0.053303    0.053885    0.054575    0.055227     0.05611    0.057071    0.058229    0.059064     0.05903    0.058644    0.058659    0.058894    0.060052    0.062195    0.065287    0.070089    0.078227    0.090051     0.10519     0.12153    0.13805     0.15292    0.16735     0.18113     0.19416     0.20602     0.21832     0.22944     0.24135     0.25246     0.26315     0.27307     0.28345     0.29363     0.30333     0.31272     0.32159     0.33068     0.33876     0.34779     0.35784     0.36477     0.37131     0.37841     0.38599      0.392     0.39867     0.40582     0.41279     0.41904     0.42453     0.43033    0.43618     0.44177     0.44901     0.45479     0.46009     0.46617     0.46973     0.47353     0.47763     0.48103     0.48413     0.48643      0.4873     0.48884     0.49097     0.49267      0.4956     0.49877     0.50301     0.50874     0.51399     0.51709     0.51881     0.51888     0.51954    0.51947     0.52008    0.52105     0.52137     0.52182     0.52352     0.52136     0.52147     0.5223     0.52215     0.52186     0.52346     0.52339      0.5229     0.52252    0.52059     0.51985     0.51892     0.51327     0.50892     0.50232     0.49216     0.48309     0.47278     0.46331     0.45105     0.43569    0.41875     0.39992     0.38419     0.37413     0.3665     0.36543     0.36852     0.36455     0.36614     0.37132     0.37355     0.37852     0.38476     0.39119     0.40246      0.4098    0.41636     0.38522 
     13     {'SYRAH'}          168.3          0.14617     0.12542    0.11053     0.099629    0.092235    0.085458    0.079833    0.074771    0.071013    0.067414    0.063814    0.061694     0.05956    0.057847    0.055968    0.054678      0.0537     0.05268    0.051814    0.050738    0.049961    0.049089    0.048006    0.047188    0.046368    0.045439    0.044731    0.043846     0.04336    0.042766    0.042179     0.04136    0.041065    0.040619    0.040228    0.039924    0.039668    0.039422    0.039379    0.039245    0.039131    0.038963    0.038793    0.038571    0.038636    0.038349    0.038201    0.037983    0.037897    0.037718    0.037766    0.037621    0.037451    0.037191    0.037235    0.036959    0.037096    0.037041    0.037077    0.037037    0.037163    0.037248    0.037384    0.037596    0.037994    0.038219    0.038519    0.039002    0.039521     0.04009    0.040846    0.041514     0.04221    0.042896    0.043397     0.04388    0.044558    0.045079    0.045874    0.046459    0.047276    0.047747    0.048383    0.048776    0.049384    0.049956    0.050669    0.051508    0.052545    0.053084    0.053183    0.052826    0.052932    0.053255     0.05437    0.056111    0.058832    0.062953    0.069771    0.079662    0.092388     0.10627    0.12029     0.13311    0.14556     0.15767     0.16905     0.17957      0.1902     0.20033     0.21074     0.22057     0.23039     0.23923     0.24889     0.25749     0.26621     0.27433     0.28299     0.29079     0.29833     0.30598     0.31487     0.32134     0.32712     0.33323     0.34009    0.34519     0.35149     0.35758     0.36376     0.36898     0.37379     0.37898    0.38475     0.38943     0.39492     0.39988     0.40503     0.40972     0.41307     0.41631     0.41992     0.42262     0.42533     0.42662     0.42822     0.42825     0.43018     0.43194     0.43467     0.43681     0.44033     0.44449     0.45028     0.45293     0.45387     0.45416     0.45418    0.45319     0.45418    0.45526     0.45611     0.45537     0.45573     0.45455     0.45493    0.45532     0.45425     0.45464     0.45528     0.45449     0.45461     0.45303     0.4525     0.45101     0.44968     0.44563     0.44153     0.43431     0.42739     0.41898     0.41161     0.40082     0.38958     0.37748    0.36147     0.34482     0.33233     0.32479    0.31977     0.31788     0.31758     0.31702     0.31937      0.3212     0.32695     0.32966     0.33598      0.3417     0.35141     0.35544    0.36661     0.33483 
     14     {'SYRAH'}         175.03          0.15369     0.13393    0.11643      0.10465    0.097385    0.088729     0.08357    0.077779    0.073886    0.069832    0.066285    0.063427    0.061276    0.059821    0.057666    0.055914    0.054783    0.054028    0.053167    0.052083    0.050917    0.049824    0.048963    0.047939    0.046925     0.04587    0.045215    0.044514    0.043848    0.043174    0.042461    0.041754    0.041338    0.040805    0.040482    0.040094    0.039748    0.039341    0.039415     0.03921    0.039065    0.038934    0.038836    0.038559    0.038411    0.038264    0.038065     0.03786    0.037689    0.037576    0.037546    0.037341    0.037236    0.036947    0.036807     0.03679    0.036791    0.036658     0.03668    0.036671    0.036818    0.036866    0.036999    0.037175    0.037443    0.037637    0.037835    0.038299    0.038679    0.039127     0.03963    0.040135    0.040823    0.041378    0.041763    0.042109    0.042662    0.043038    0.043559    0.044025     0.04475    0.045264    0.045833    0.046424    0.047053    0.047664    0.048568    0.049432    0.050504    0.051375    0.051733    0.051795    0.052167    0.052747    0.053727    0.055504    0.058105    0.062044    0.068768    0.078488    0.090681     0.10397     0.1176     0.13024    0.14298     0.15546     0.16743     0.17871     0.19002     0.20116     0.21229     0.22313     0.23384     0.24392     0.25455     0.26462     0.27468     0.28422     0.29397     0.30317     0.31216      0.3212     0.33145     0.33989     0.34714     0.35427     0.36301    0.36962     0.37667     0.38473     0.39186      0.3988     0.40562     0.41226    0.41846     0.42476     0.43182     0.43857     0.44476     0.45091     0.45587     0.46052      0.4652     0.46888     0.47184      0.4757     0.47743     0.47889     0.48122      0.4836     0.48712     0.49028     0.49481     0.50007     0.50716      0.5109     0.51346     0.51326     0.51399    0.51544     0.51566    0.51721     0.51836     0.51781     0.51892     0.51807     0.51872     0.5188     0.51774     0.51983     0.51911     0.51973      0.5184     0.51926    0.51808     0.51661     0.51496     0.50981      0.5071     0.49952     0.49087      0.4807     0.46964     0.45925     0.44508     0.43111    0.41279     0.39301     0.37863     0.36834    0.36293     0.35994     0.35902     0.35667     0.36115     0.36461     0.36599     0.37414     0.37954     0.38745     0.39541     0.40156    0.41569     0.37264 
     15     {'SYRAH'}          168.3          0.14286     0.11993    0.10663     0.097183    0.088758    0.081789    0.076941    0.072091    0.067824    0.064185    0.060482    0.058388    0.055893    0.054449    0.052796      0.0516    0.050245    0.049505    0.048455    0.048058    0.047052    0.046095    0.045341    0.044335    0.043062    0.042384    0.041535    0.040889    0.040567    0.039896    0.039212    0.038625    0.038166    0.037785    0.037503    0.037109    0.036871    0.036668    0.036396    0.036426    0.036454    0.036157    0.036152    0.035953    0.035783    0.035506    0.035338    0.035262     0.03522    0.035133    0.035135    0.035016    0.034841    0.034602    0.034584    0.034359    0.034426     0.03438    0.034459    0.034449    0.034628    0.034575    0.034916    0.035005    0.035346    0.035655    0.035837    0.036235     0.03679    0.037317     0.03787    0.038417    0.039113    0.039815    0.040363    0.040687    0.041297    0.041801    0.042498    0.043088    0.043815    0.044318    0.044892    0.045478    0.045904    0.046532    0.047374    0.048106    0.049117    0.049834    0.049987    0.049877    0.049972    0.050379    0.051454    0.053178     0.05585    0.059918    0.066571    0.076513    0.088937     0.10235    0.11583     0.12827    0.14053     0.15202     0.16332     0.17363     0.18397      0.1938     0.20407     0.21372     0.22314     0.23184      0.2411     0.24957     0.25822     0.26622     0.27443     0.28235     0.28939     0.29711     0.30608     0.31234     0.31836     0.32429     0.33085    0.33588     0.34172     0.34805     0.35419     0.35922     0.36457     0.36903    0.37466     0.37947     0.38516     0.38983     0.39517     0.39994     0.40245     0.40631     0.40998     0.41228     0.41455     0.41706     0.41717     0.41822     0.41957     0.42104       0.423     0.42585     0.42863     0.43329     0.43819     0.44193     0.44261     0.44197     0.44177    0.44251     0.44323    0.44316     0.44384     0.44297     0.44344     0.44232     0.44275    0.44243      0.4418     0.44182     0.44225     0.44124     0.44175     0.44044    0.43925      0.4389     0.43588     0.43355     0.42942     0.42227     0.41512      0.4068     0.39819     0.38898     0.37921     0.36562    0.35016     0.33367     0.32147     0.31293     0.3078     0.30651     0.30602     0.30483     0.30894     0.30924     0.31456     0.31858     0.32623      0.3307     0.33833     0.34814    0.35358     0.32664 
     16     {'SYRAH'}          158.2          0.15493     0.12988    0.11542      0.10329    0.095183    0.088027    0.081363    0.076411    0.072261    0.068154    0.065145    0.062033    0.059432    0.057475    0.055949    0.054613    0.052989    0.052049    0.051316    0.050435     0.04926    0.048007    0.046952    0.045939    0.045292    0.044378    0.043339    0.042831    0.042016    0.041191    0.040811    0.040339    0.039769     0.03943    0.039017     0.03865    0.038381    0.038128    0.037785    0.037748    0.037801     0.03748    0.037434    0.037355    0.037063    0.036845    0.036774     0.03664    0.036505     0.03634      0.0364    0.036307    0.036153    0.035891    0.035845    0.035778    0.035881     0.03582    0.035967    0.035969    0.036132    0.036201    0.036502    0.036753    0.037142    0.037406    0.037837    0.038337    0.038887    0.039558    0.040283    0.041009      0.0419    0.042564    0.043218    0.043843    0.044563     0.04528    0.046193    0.047013    0.047902    0.048646     0.04942    0.050045    0.050709    0.051253    0.052199    0.053088    0.054316     0.05499    0.055056    0.054753    0.054628    0.055099    0.056496    0.058405    0.061487    0.066205    0.074182    0.085759      0.1005       0.117    0.13337     0.14846    0.16285     0.17669     0.18982     0.20217      0.2143     0.22565     0.23744     0.24849     0.25932     0.26948     0.27964     0.28953     0.29896     0.30817     0.31705     0.32571     0.33384      0.3426     0.35229     0.35933     0.36581     0.37251     0.37949    0.38554     0.39244      0.3997     0.40613     0.41176     0.41772     0.42368    0.42963     0.43472     0.44178     0.44701     0.45302     0.45844     0.46214     0.46603     0.47015     0.47278     0.47594     0.47837     0.47921        0.48     0.48138     0.48331     0.48636     0.48879     0.49363     0.49858      0.5049     0.50814     0.51032     0.50977     0.51097    0.50986     0.51072    0.51186     0.51282     0.51219     0.51304     0.51304     0.51235    0.51205     0.51257     0.51294     0.51236     0.51309      0.5111      0.5134    0.51059     0.51055      0.5069     0.50422     0.49864     0.49092     0.48221     0.47184     0.46333     0.45019     0.43905     0.42277    0.40495     0.38795     0.37151     0.36351    0.35863     0.35355     0.35563     0.35438     0.35517     0.36008     0.36585     0.36867     0.37547     0.38139     0.39158      0.3988    0.41004     0.37699 
      ⋮

Verify the number of samples in the table.

n = size(T,1)
n = 
274

Extract the average spectra of the samples from the table as a matrix of predictor variables, X.

X = table2array(T(:,4:end));

Extract the sugar content of the samples from the table as a vector of response variables, y.

y = table2array(T(:,3));

Create Training and Test Data Sets

Split the data into 70 percent training data and 30 percent test data using holdout validation.

rng("default")
p = 0.3;
datapartition = cvpartition(n,"Holdout",p);
idxTrain = training(datapartition);
nTrain = nnz(idxTrain);
idxTest = test(datapartition);
nTest = nnz(idxTest);

Extract the average spectra for the training and test data sets from the predictor variables into separate matrices.

XTrain = X(idxTrain,:);
XTest = X(idxTest,:);

Extract the sugar content for the training and test data sets from the response variables into separate vectors.

yTrain = y(idxTrain);
yTest = y(idxTest);

Perform PLS Regression on Training Data

Partial least squares (PLS) regression finds combinations of the predictors that have a large covariance with the response values. Perform PLS regression on the training data set, with 10 components, using the plsregress (Statistics and Machine Learning Toolbox) function and compute the coefficient matrix.

numComponents = 10;
[~,~,~,~,coeff,~,~,~] = plsregress(XTrain,yTrain,numComponents);

Predict the sugar content of the training data using the coefficient matrix.

yTrainPredicted = [ones(nTrain,1) XTrain]*coeff;

Evaluate the fit to the training data by computing the total sum of squares (TSS), and residual sum of squares (RSS), and then use them to find the R-square value, which indicates the variance in the sugar content explained by a small change in the average spectrum of the sample.

TSS_train = sum((yTrain - mean(yTrain)).^2);
RSS_train = sum((yTrain - yTrainPredicted).^2);
Rsquared_train = 1 - RSS_train/TSS_train
Rsquared_train = 
0.7897

Plot the predicted sugar content against the actual sugar content of the training data. Observe that the PLS regression model is a good fit to the training data.

figure
scatter(yTrain,yTrainPredicted)
axis equal
xlabel("Actual Sugar Content (g/L)")
ylabel("Predicted Sugar Content (g/L)")
title("PLS Regression for Training Data")

Figure contains an axes object. The axes object with title PLS Regression for Training Data, xlabel Actual Sugar Content (g/L), ylabel Predicted Sugar Content (g/L) contains an object of type scatter.

Perform PLS Regression on Test Data

Predict the sugar content of the test data using the coefficient matrix.

yTestPredicted = [ones(nTest,1) XTest] * coeff;

Evaluate the fit to the test data by computing the total sum of squares (TSS) and residual sum of squares (RSS), and then use them to find the R-square value, which indicates the variance in the sugar content explained by a small change in the average spectrum of the sample.

TSS_test = sum((yTest - mean(yTest)).^2);
RSS_test = sum((yTest - yTestPredicted).^2);
Rsquared_test = 1 - RSS_test/TSS_test
Rsquared_test = 
0.6670

Plot the predicted sugar content against the actual sugar content of the test data. Observe that the PLS regression model is a good fit to the test data.

figure
scatter(yTest,yTestPredicted)
axis equal
xlabel("Actual Sugar Content (g/L)")
ylabel("Predicted Sugar Content (g/L)")
title("PLS Regression for Test Data")

Figure contains an axes object. The axes object with title PLS Regression for Test Data, xlabel Actual Sugar Content (g/L), ylabel Predicted Sugar Content (g/L) contains an object of type scatter.

References

[1] Maxime Ryckewaert. “Spectral Dataset of Grape Berries from Hyperspectral Imaging for Maturity Monitoring,” January 26, 2022. https://doi.org/10.17632/GJWX64SGKP.1, licensed under CC-BY-4.0.

See Also

(Statistics and Machine Learning Toolbox)