Battery energy storage systems (BESS) arenowadaysessen tialparts ofmicrogrids. Athermal managemen tsystem (TMS) belongs tosubstan tialcontrolcomp onentsensuring optimal operation andlonglifespan ofbatteries. Advanced controlstrategies implemen tedinTMS require accurate thermal modelstokeepbattery temp erature within prede ned bounds while minimizing operating costs. This paperproposes machinelearning-based models topredict temperature inside realindustrial BESS. Challenges represe ntpartially continuous andpartially discrete input signals. Furthermore, innerfanslocatedinside modules a ect thetemp erature inthisparticular BESS. Unfortunately ,theinformation onfans' operations isnotavailable. This study alsoprovides anaccuracy analysis ofbagged classi cation andregression trees (CAR T),multi-la yerperceptron (MLP), and averaged neural network(avNNet). Theresults reporthigh prediction accuracy ,over95%, forallmodels, eventheones with amore straig htforw ardstructure. Keywords:Thermal managemen tsystem, Battery energy storage, Modeling, Machine learning. 1Introduction Renew ableenergy sources (RESs), especially solar pan- elsandwind turbines, havebecome integral todaily life.They arenotonly operated asacomplemen ttothe global gridorinlarge structures intheindustry butalso assmall-rate systems inhouseholds, smart build ings, or public infrastructure. RESs havegainedmuchpopular- ityduetotheir potentialtoreduce greenhouse gasemis- sions, asmentioned in[17]. Since theEurop eanUnion is committed todecarb onizing itspowersector, thestudy [30]prepared fortheEurop eanParliame nt'sCommittee onEconomic andIndustry ,Researc handEnergy (ITRE) suggested thatRES, incombination with nuclear plants, should become theprimary powersources. Despite the positiv eimpact ofRES onthedecarb onizing grid, the authors of[6]havepointedoutthat RESs areaccompa- nied bytheproblemofthe uctuating amoun tofpro- duced energy .Itresults inaninsucien teconomicop- eration with anegligible impact onimpro ving theenvi- ronmen talsituation. Toovercome these negativ easpectsandstabilize theop- eration ofthewhole grid, energy storage hastobein- stalled inthesystem. Energy storage isessen tialtothe smooth,economical, andoptimal operation ofgrids and microgrids, asstated in[6].There aredi eren ttypes ofenergy storage: thermal, mechanical,electromagnetic, electro chemical (describ edinmore detail in[21]), hydroorcompressed airenergy storage, andmanymore sum- marized bytheauthors in[6].The most practical and commonly used energy storage system isabattery en- ergy storage system (BES S).Lithium-based BESS has beenprovedtobethemost e ectiveduetoitshigh e- ciency ,high energy densit y,andlong lifetime,asstated andgraphically illustrated intheworkof[23]. Toensure thesafeandsmoothoperation ofBESS,the energy managemen tsystem (EMS) andthermal man- agemen tsystem (TMS) mustbeproperly con gured. EMS hasbeenstudied with meticulou scareoverthepast decade, andalotofapproac hescanbefound intheliter- ature from di eren tperspectiveslike[10], [20], [11], [22] justtoname afew.TheTMS developmen tlagsbehind thatofEMS duetothelowimportance ingridoperation (compared toEMS). However,TMS isclosely related to theeconomic view ofgrid/microgrid operation. Ithas beenprovenin[19]that ifthebattery temp erature in- creases by1Cintherange 3040C,thebattery lifes- panisreduced bytwomonths.Furthermore, high bat- terytemp erature canlead toaccelerated capacit yfade, aging, anddamni cation following environmen talprob- lems asstudied bytheauthors in[26]. Ontheother hand, theworkof[12]showsthat lowbattery temp era- turereduces powercapabilit yorperformance failure. It implies that unsuitable thermal managemen tofBESS a ects theoperation ofEMS. Theoptimal range forbat- terytemp erature deviates from onestudy toanother. In [8],theacceptable range isbetween-2060C,in[18] theoptimal temperature range forlithium-based batter- iesis1535C.Generally ,inindustry ,theacceptable A. Mosavi, F. Kristina Modeling Thermal Management of Battery Energy Storage System with Machine Learning TU-Dresden, Dresden, Germany Slovak University of Technology, Bratislava, Slovakia range isde ned bythemanufacturer. Although TMS isinconspicuous, itiscrucial foropti- malBESS performance. Di eren tcontrolstrategies have beenemplo yedtoensure anadequate temp erature in BESS. ThePIDcontroller forregulating thethermal bal- ance ofthestackinhybridvehicles wasproposed in[29]. Itwasshownthat thePID controller could stabilize the stack'stemp erature evenwith lowcooling water owat thecostofahigher fanandpumping power.Theauthors of[16]introduced anovelfuzzycontrolstrategy tomain- tainasuitable battery temp erature range inelectric ve- hicles. Ithasbeenveri ed that thisstrategy canextend thebattery lifetime. However,thespeci c in uence on thebattery packhasnotbeeninvestigated further. PID andfuzzy controllers arepractical duetostraigh tfor- warddesign, implemen tation, andtuning. Nevertheless, itisn't easy toachieveBESS's economic operation, con- sidering theenvironmen talimpact ofthese twotypesof controlstrategies. Therefore, themodelpredictiv econtrol(MPC) strategy playsacrucial roleintheenergy sector, including bat- terythermal managemen t.Theauthors of[13]proposed anonlinear modelpredictiv econtroller (NMPC) metho d tooptimize thecooling processofbatteries inelectric vehicles. Thestudy reportsperformance comparisons of NMPC andPID controllers, concluding that NMPC is preferable duetoreduced coolantconsumption, reduced inconsistency ofthebatterymodule temp erature, and precise reference tracking. Ontheother hand, thecom- putational time ofNMPC is50-times higher than for PID. However,itisstillsucien t.Another implemen ta- tionofMPC canbefound in[15], [25], [28], andmany more. Eventhough these strategies weremostly applied inelectric vehicle researc h,they canbemodi ed andim- plemen tedinBESS thermal controlmanagemen t. Asthename suggests, themodelofthecontrolled pro- cessisessentialfortheMPC strategy .Thecontrolper- formance ofMPC depends ontheprecision ofthemodel. Intheprocesscontrolperspective,thestate-space mod- elsarepreferred overnonlinear orcomplicated models. Identi cation ofthestate-space battery thermal model canbefound in[5],where theauthors constructed the state-space modelusing stepresponse obtained from the computational uiddynamics (CFD) model.Astate- space-based multi-no desthermal modelcanbefound in[27], where themodelisderiv edfrom battery heat transfer process equations. Both metho dsrequire de- tailed knowledge aboutthethermalbehaviorofpartic- ular BESS.Furthermore, CDF analysis canbecostly . Theheat transfer processequations modelsrequire per- fectknowledge aboutthesystem andthermo dynamic laws.Therefore, theidenti cation from real-time data canrepresen tanappropriate alternativ e.However,the drawbac kisthedemand foraconsiderable amoun tof data.The studies mentioned aboveoperate with analytical mathematical modelsofbattery thermal behavior. An- other approac histoestimate battery temp erature using recurren tneural networks aspresentedin[9].However, thismodelwasidenti ed formonitori ngpurp oses and wastrained andvalidated onadataset acqui redfrom NASA's Prognostics CenterofExcellence (PCoE). The authors illustrated asimilar idea in[7]using arti cial neural networks. Thedata used fortraining andvalida- tionwereextractedfrom [14], where they wereobtained from anexperimen tallaboratory device. This paperpresen tsseveralmachine learning modeling techniques used toappro ximate thethermal behavior ofindustrial battery energy storage based onreal-time data. Compared with previous work, weanalyze tem- perature evolution inarackcontaining multiple battery modules, where eachperforms di eren tly.Moreover,the modelspresen tedinthispaperhandle combination of continuous anddiscrete input variables. Additionall y, theBESS hasbeendesigned withfeatures suchasinner fansin uencing thebattery temperatures, buttheinfor- mation aboutthefans' operation isunavailable. Never- theless, despite thementioned obstacles, wecanobtain aBESSthermal modelthat precisely predicts temp era- tureevolution inside therack. 2Materials This section introduces ourstudied system, itscurren t implemen tation, andparticular features in uencing out- putvariables. 2.1 Studie dSystem Theindustrial BESS studied inthispaperislocated in Lipto vskyHradok, Slovakia,andinstalled asapartof themicrogrid. Itisadapted tostore thespare energy from solarpanels orthegrid during low-price periods. Inaddition, theBESS energy isused forpeak-s having ortopreventdeviation sfrom thereported day-ahead di- agram. Themicrogrid structureisillustrated inFig.1. TheBESS iscomp osed of3parts: thebattery part, heat- ing,ventilation, andcooling (HVAC)part, andinverter part. The rstsection contains tenlithium-ion battery modules with NMC (nickel-mangan-cobalt) catho de.Al- together, they create BESS with abattery capacit yof around 150kWh. During thecharging ordischarging process, themodules emit acertain amoun tofheat, whichcanvarybetweenmodules. Thebattery part also disposes ofaventilation fansituated atthetopofthe rack.Thefanprovides airexchange betweenBESS and itssurroundings andoperates inacontinuousregime. Theairisdrawninfrom belowtheBESS andisvented outatthetop.TheHVACmodule contains anaircon- ditioning (AC)unit, whichcanoperate intwomodes: cooling orheating. Adjusted airentersthebottom of Fig. 1.The illustration ofmicrogrid structure. The BESS canbecharged bypowerfrom solar panels oragrid. On theother hand, battery powerisused toful ll consumer requiremen tswhile minimizing deviations andcosts. thebattery part andreturns totheHVACpartthrough thecirculation fanatthetop. AllHVACfeatures can beonly inactiv eorinactiv emodeintroducing discrete variables tooursystem. Theinverter partisessen tialfor theenergy managemen tsystem. However,itisisolated from therestofBESS. Therefore itsthermal impact on thebattery temp erature isnegligibl e.TheBESS struc- tureandair owsareillustrated inFig.2.Note thatbat- terymodules havebuild-in fanswhose operation cannot bemonitored. Furthermore, nothermal modelhasbeen found yet. 2.2 Curr entImplementation Since theBESS iscurren tlyoperational, itisalready ac- companied bythethermal managementsyste m.Itrepre- sentsarule-based controller, whichcollects ambientand BESS temp erature measuremen tstoproduce commands forHVACandfansbased onasetofrulesasportra yed inFig.6.Itisane ortless butacceptable control. Gen- erally ,therule-based andPID controllers areprimarily used intheTMS ofindustrial batteries. Theproblem is nottheimplemen tation ofadvanced controlstrategies butthecomplexit yofobtaining theappropr iatethermal model.However,HVACoperation isnotoptimized to achieveeconomic goals. Moreo ver,iftheBESS isinthe processofcharging ordischargi ng,itisdetected byTMS when temp erature measuremen tsarecollected. There- fore, itresults indelayedcooling, whichleads toavi- olation oftheoptimal temp erature range. Thethermal range forthisparticular BESS isshowninFig.3with temp erature impact onmaximal battery powerrate. The grayarea represen tsthesuitable range de ned bythe manufacturer when thebattery poweroutput ismaxi- mized. However,theintervalisshrunk en(green area) for safetyandstable operation. Last butnotleast,using a rule-based controller generates amaxim umdi erence of Fig.2.Thestructure ofBESS: theleftdotted partrepresen ts HVAC,themiddle part isthebattery part comp osed of battery modules, and therightdashed part contains the inverter. The blue arrowillustrates air owthrough BESS generated bythebattery ventilation fan.Thepurple arrows represen taircirculation betweenbatteries andHVAC. Fig.3.Thedependence ofmaximumpowerrateontemper- ature. The optimal operation conditions arebetweenTmin andTmax (grayarea), because that iswhen weworkwith maxim umbattery power.Thegreen area represen tsthein- tervalconsidered bythecontroller forsafetyandstabilit y. 9.8Cbetweenaminim umandmaximumtemp eratures inBESS, whichisundesirable. Fig.4.Evolution oftemp eratures inbattery part ofBESS. The enormous temp erature changes arecaused byinten- tional steptests,where theimpact ofHVACfeatures wasin- vestigated indetail. Theambienttemperature increased its valueonMarc h4that16:00 duetoacolossal heat exchange betweenBESS anditssurroundings. 2.3 Dataset Ourdataset foridenti cation andvalidation iscreated from datameasured inthebattery energy storage sys- tem, whicharecollected inreal-time. Measurementsare stored inthedatabase with 1minutesampling time. Since ourindustrial partner doesnotwish toshare exact values ofvariables, weapplied so-called min-max nor- malization toovercome thisissue. Thegeneral formula isde ned as x=xorgxmin xmax xmin; (1) where xorgisoriginal measured value ofvariable, xmin andxmax arenormalization limits andx2[0;1]isnor- malized value. Aswealready know,thetemp erature ofBESS modules isin uenced bytheoperation ofHVAC,ambienttem- perature, andtheamoun tofcharged/disc hargedenergy to/from themodule since charging anddischarging the battery emitsheat. Thetemp eratu resconsidered asour system's outputs aretheaverage TBAT avg,minimal TBAT min, and maximal TBAT maxtemp eratures ofmodules inbat- terypart. These signals describ ethethermal behaviorof BESS because they directly in uence thelength ofbat- tery lifespan andvalue ofmaximal charged/disc harged power,therefore theeconomic aspectofBESS operation. Furthermore, these signals areessen tialforcontroller de- sign. The rstfourBESS inputs represen tthecooling uC andheatinguHofmodules using theHVACsystem, cir- culation fanuCFused fordistribution ofcooled/heated airfrom HVACpart tobattery part, andventilation fan uFused forpassiv ecooling. Thesesignals arecontrolled byathermal managemen tsystem (TMS). Other input signals arecharging anddischarging battery poweral- Fig.5.Evolution ofcontrolinputs inbattery part ofBESS. When thecontroller status isequal to1,theTMS isrunning, meaning that therule-based controller produces appropriate controlactions. Ifcontroller status is0,theactuators are manually controlled, represen tingstep tests. together PSandambienttemp erature Tamb.TMS can- notcontrolthem, considering theambienttemp eratu re depends onthelocation ofBESSasmuchasthecon- ditions near BESS, andtheamoun tofcharged ordis- charged powerisde ned bytheenergy managemen tsys- tem(EMS). The EMS isprioritized overTMS since it ensures thesafeandsmoothoperation ofthewhole mi- crogrid. Therefore PSandTambareconsidered asdistur- bances. However,wecanmodeltheir impact onthemod- ules' temp eratures. Fig. 4illustrates measured output andambienttemp eratures over1.5daysperiod.Thebe- longing controlactions areportra yedinFig.5toclarify theimpact ofHVACandfansoperation onBESS tem- peratures. Since theBESS isalready operational with activ eTMS, thedataset ispartially comp osed oftem- perature data, measured when thecontroller wasactiv e, anddata without anytemp eratu recontrolrepresen ting ourstep tests. Paramete rCautinFig.5represen tsthe information aboutstatus ofcontroller. IfCaut=1,the controller wasactiv e(on), ifCaut=0,thermal control waso . Fig. 6.The closed-lo opsystem: rule-based controller pro- duces controlactions (command forHVACandfans)based onambienttemp erature and temp erature measuremen ts from BESS. The thermal conditions inBESS arenotonly in uenced bymentioned controlled actions butalsobythe demand onbattery power,whichthecontroller hasnoknowl- edge about. 3Metho ds This section describ esthree machine learning strategies that havereportedthebestresults inmodeling BESS temp erature. 3.1 Bagge dClassi c ation andRegression Trees Theclassi cation andregression trees(CAR T),histor- ically called decision trees, areastatistical andpredic- tivemodeling metho dintroduced byBreiman etal.in [3].Theclassi cation treealgorithm decides whichofthe prede ned classes thetarget value most likelybelongs. Theregression treerefers toanalgorithm that predicts thevalue ofacontinuous target variable. Thedata set intheCAR Tmetho dispartitioned intomultipl esub- sets, eachrepresen tingonebranc h.Then, themodelis obtained byapplying therecursiv esegmen tation tech- nology within eachpartition. Gained setofrules isused topredict thetarget variable. The advantages ofthis modeling approac harethemodel's simplicit yandnegat- ingtheneed forlinearit yassumptions. Furthermore, the CAR Tmodelcanoperate with bothdiscrete andcontin- uous variables. Ontheother hand, using CAR Tmodels cancreate aproblem suchasover tting, high variance, andlowbias. Fig.7.Visualization ofalgorithm generating bagged CAR T model.Eachcircle represen tstheinput instance. After nd- ingthebagged CAR Tmodel,thetesting data areinserted ineachdecision treeinside themodelandobtained outputs areaveraged, creating atarget value. Fig.8.Visual ization ofavNNet model.Likebagged CAR T, severalrandomized subsets oftheoriginal dataset areused totrain multiple ANN s.Thevalue ofthetarget variable is obtained asanaverage ofallANNs outputs. Since theCAR Tisconsidered sensitiv etothetrain ed data, itreportshigh prediction variance forother input data. Bootstrap Aggregation (Bagging) isanensem ble metho dused toincrease theprediction accuracy ofthe CAR Tmodel.Thebagged CAR Tmetho distheproce- dure where multiple CAR Tmodelsaretrained using ran- dom subsets ofouroriginal dataset. Thetarget valueis calculated asanaverage ofthemodels' outputs. Bagged Cart hasbeenprovedtobeanecien tstrategy toim- proveaccuracy asstated in[2]. 3.2 Multi-L ayer Perceptron The multi-la yerperceptron (MLP) isaclassic fully connected feed-forw ardarti cial neural network(ANN) consisting ofoneinput, multiple hidden, andoneoutput layer.The layerscontain severalnodescalled neurons. The numberofneurons intheinput andoutput layer equals thenumberofinputs andoutputs inthedataset. The numberofhidden layersandnodeswithin itcan bechosen. Allneurons areconnectedinafeed-forw ard fashion, andtheir inputs areweighted.These inputsare summed upinside eachneuron, andsubsequen tly,abias parameter speci c foreachneuron isadded tothere- sult. Theoutcome isconverted tonodeoutput usingthe selected activ ation function. The MLP uses theback- propagation algorithm toadjust theweightsandbiases tominimize thedi erence betweenoutputs from the dataset andpredicted values from theMLP model.The Fig.9.Visualization ofMLP model.Theinputvariables are modi ed multiple times asthey aretransp orted through the networkinafeed-forw ardfashion. They areweighted,added up,andtransformed using theactiv ation function inneurons toproduce the nal output. The results arecompared to theexpected value, and based onthedeviation size, the backpropagation algorith mtakescharge. authors of[1]declare that thepresen tedmetho dapplies tocomplex nonlinear systems evenwith extensiv einput data andgains high accuracy ratio ifadequately set. 3.3 AveragedNeur alNetwork Theaveraged neural network(avNNet) modelreprese nts acombination ofbagged CAR TandMLP features. It iscreated bytraining multiple arti cial neural networks with thesame structure onrandom seeds ofdata from theoriginal datase t.Thetarget values areobtai nedby averaging theoutputs from allneuralnetworks inthe avNNet. Since theANNs aretrained using di eren tsub- sets, they candi er invalues ofparameters. Thebene ts ofusing theavNNet arethat thenetworkensem blecan befarlessfallible than onenetwork,asdiscussed and experimen tally shownin[4].Furtherm ore,avNNet re- portsahigh possibilit yofover- tting andover-training avoidance asstate din[24]. 3.4 ModelQuality Tocompare thepresen tedmodels, wehavechosen four qualit yparameters. The rstoneisRootMean Squared Error (RMSE). This criterion aggregates thesquared magnitudes oferrors betweenmeasured outputyandpredicted value ^y.Themathematical formulaofRMSE isde ned as RMSE =sPN k=1(^ykyk)2 N: (2) The second criterion isMean Absolute Error (MAE), whichoperates with anabsolutedi erence betweeny and^y.Itisformulated asfollows MAE =PN k=1j^ykykj N: (3) Both RMSE andMAE areparameters describingtheac- curacy ofmodeling. However,theRMSE parameter is more helpful inconsidering undesirable large errorsbe- cause itsquared theerrors before averaging. Thecoe- cientofdetermination, denoted asR2,isthethird qual- ityparameter represen tingtheclosenessofdata tothe tted regression line. Itisevaluated as R2=1PN k=1(^ykyk)2 PN k=1(yky)2; (4) whereyisthemean ofmeasured outputs y.From the de nition R22[0;1],where R2=0represen tsnorela- tionship betweenyand^y,while R2=1corres pondto ideal situation where y=^y.Therefore, higher R2sym- bolizes high prediction accuracy . 4Results Forthispaper,wefocusedonmodeling average BESS temp erature. Dynamical models produced bybagged CAR T,MLP ,and avNNet metho dsconsider cooling, heating, circulation fan,ventilation fan,battery power, andambienttemp erature asinput signals. Thedataset inthetraining phase wasconstructed from 49,705 sam- ples corresp onding toappro ximately 35daysofdata. The models werevalidated andtested on21,295 data samples, whichisalmost 15daysofmeasuremen ts.The testing phase results aresummarized inTab.1.Aswecan see,eachmodelreportshigh accuracy .However,avNNet declares thelowestRMSE andMAE combined with the highest dandR2.Fig.10illustrates temp erature pro les generated from original data andfrom eachmodelover 600minutesshowing thatMLP andtheavNNet arevery precise inpredictions. The operation ofinner fanscan a ect theaccuracy oftrained models. The ventilators workindependen tlyoftheTMS, they a ect thetemper- ature, butwedonotdisposeofinformation abouttheir activit y. Table 1 Summary ofqualit yparameters forbagged CAR T,MLP , andavNNet models. Metho dRMSE MAE d R2 Bagged CAR T0.011 0.008 0.989 0.958 MLP0.008 0.007 0.995 0.979 avNNet0.007 0.006 0.996 0.985 Eventhough bagged CAR Treportsworse results than therest, itstillprovides amodelwith anaccuracy of over95%. Moreo ver,thebaggedCAR Tmodelpossesses asimple structur e,whichisexceptionally bene cial in thecontroldesign eld. The results portra yedinFig. 11reportsthat eventhough theMLP modelproduces thelowestvalueofmaxim umabsolute error, theaverage di erence isthehighest compared toother metho ds. 5Conclusions The proposed paperanalyzes three machine learning- based models' accuracy ,name lybagged CAR T,MLP , andavNNet, topredict temp erature inside BESS. The results showthatavNNet declares higher qualit yperfor- mance, eventhough theaccuracy ofeverymodelisover 95%. However,under some particular operational con- ditions, theworstmodel(bagged CAR T)hasdeviated from theoriginal dataset byanimmense 3C.Therea- sonistheBESS containin gfans, theoperation ofwhich cannot bemonitored. They a ect thetemp eratur e,but wedonotdisposeoftheassociated signal. The solu- tioncould betheimplemen tation ofnon-in trusiv eload monitoring. Another issue represen tsundetected mea- suremen tfailures whenHVACfeatures andfansarerun- ning, butinformation abouttemp erature isnotlogged inthedatabase. After comm unication isrestored,data betweenthese twoinstances areappro ximated using in- terpolation. This problem could besolvedbyincluding ananomaly detection algorithm inoursystem. However, thethermal pro les ofprese ntedmodelsreporthigh ac- curacy .They canbeused inadvanced controlstrategies orasabase forderivin glinear models. The machine learning modelswith declared precision arefrequen tly used formonitoring purp osesorasdigital twins forsim- ulations.