EDA-Ebook

Page 1


ExploratoryDataAnalysis

IbonMartínez-Arranz

DataScienceWorkflowManagement

Introduction

Inrecentyears,theamountofdatageneratedbybusinesses,organizations,andindividualshas increasedexponentially.WiththeriseoftheInternet,mobiledevices,andsocialmedia,wearenow generatingmoredatathaneverbefore.Thisdatacanbeincrediblyvaluable,providinginsightsthat caninformdecision-making,improveprocesses,anddriveinnovation.However,thesheervolume andcomplexityofthisdataalsopresentsignificantchallenges.

Inthepastfewyears,therehasbeenasignificantsurgeinthevolumeofdataproducedbycompanies, institutions,andindividuals.TheproliferationoftheInternet,mobiledevices,andsocialmediahas ledtoasituationwherewearecurrentlygeneratingmoredatathanatanyothertimeinhistory.Image generatedwithDALL-E.

Datasciencehasemergedasadisciplinethathelpsusmakesenseofthisdata.Itinvolvesusing statisticalandcomputationaltechniquestoextractinsightsfromdataandcommunicatetheminaway thatisactionableandrelevant.Withtheincreasingavailabilityofpowerfulcomputersandso ware

tools,datasciencehasbecomeanessentialpartofmanyindustries,fromfinanceandhealthcareto marketingandmanufacturing.

However,datascienceisnotjustaboutapplyingalgorithmsandmodelstodata.Italsoinvolvesa complexando eniterativeprocessofdataacquisition,cleaning,exploration,modeling,andimplementation.Thisprocessiscommonlyknownasthedatascienceworkflow.

Managingthedatascienceworkflowcanbeachallengingtask.Itrequirescoordinatingthee ortsof multipleteammembers,integratingvarioustoolsandtechnologies,andensuringthattheworkflow iswell-documented,reproducible,andscalable.Thisiswheredatascienceworkflowmanagement comesin.

Datascienceworkflowmanagementisespeciallyimportantintheeraofbigdata.Aswecontinueto collectandanalyzeever-largeramountsofdata,itbecomesincreasinglyimportanttohaverobust mathematicalandstatisticalknowledgetoanalyzeite ectively.Furthermore,astheimportanceof data-drivendecisionmakingcontinuestogrow,itiscriticalthatdatascientistsandotherprofessionals involvedinthedatascienceworkflowhavethetoolsandtechniquesneededtomanagethisprocess e ectively.

Toachievethesegoals,datascienceworkflowmanagementreliesonacombinationofbestpractices, tools,andtechnologies.SomepopulartoolsfordatascienceworkflowmanagementincludeJupyter Notebooks,GitHub,Docker,andvariousprojectmanagementtools.

WhatisDataScienceWorkflowManagement?

Datascienceworkflowmanagementisthepracticeoforganizingandcoordinatingthevarioustasks andactivitiesinvolvedinthedatascienceworkflow.Itencompasseseverythingfromdatacollection andcleaningtoanalysis,modeling,andimplementation.E ectivedatascienceworkflowmanagement requiresadeepunderstandingofthedatascienceprocess,aswellasthetoolsandtechnologiesused tosupportit.

Atitscore,datascienceworkflowmanagementisaboutmakingthedatascienceworkflowmore e icient,e ective,andreproducible.Thiscaninvolvecreatingstandardizedprocessesandprotocols fordatacollection,cleaning,andanalysis;implementingqualitycontrolmeasurestoensuredata accuracyandconsistency;andutilizingtoolsandtechnologiesthatmakeiteasiertocollaborateand communicatewithotherteammembers.

Oneofthekeychallengesofdatascienceworkflowmanagementisensuringthattheworkflowis well-documentedandreproducible.Thisinvolveskeepingdetailedrecordsofallthestepstakeninthe datascienceprocess,fromthedatasourcesusedtothemodelsandalgorithmsapplied.Bydoingso,it becomeseasiertoreproducetheresultsoftheanalysisandverifytheaccuracyofthefindings.

Anotherimportantaspectofdatascienceworkflowmanagementisensuringthattheworkflowis scalable.Astheamountofdatabeinganalyzedgrows,itbecomesincreasinglyimportanttohavea workflowthatcanhandlelargevolumesofdatawithoutsacrificingperformance.Thismayinvolve usingdistributedcomputingframeworkslikeApacheHadooporApacheSpark,orutilizingcloud-based dataprocessingserviceslikeAmazonWebServices(AWS)orGoogleCloudPlatform(GCP).

E ectivedatascienceworkflowmanagementalsorequiresastrongunderstandingofthevarioustools andtechnologiesusedtosupportthedatascienceprocess.Thismayincludeprogramminglanguages likePythonandR,statisticalso warepackageslikeSASandSPSS,anddatavisualizationtoolslike TableauandPowerBI.Inaddition,datascienceworkflowmanagementmayinvolveusingproject managementtoolslikeJIRAorAsanatocoordinatethee ortsofmultipleteammembers.

Overall,datascienceworkflowmanagementisanessentialaspectofmoderndatascience.Byimplementingbestpracticesandutilizingtherighttoolsandtechnologies,datascientistsandother professionalsinvolvedinthedatascienceprocesscanensurethattheirworkflowsaree icient,e ective,andscalable.This,inturn,canleadtomoreaccurateandactionableinsightsthatdriveinnovation andimprovedecision-makingacrossawiderangeofindustriesanddomains.

WhyisDataScienceWorkflowManagementImportant?

E ectivedatascienceworkflowmanagementiscriticaltothesuccessofanydatascienceproject.By organizingandcoordinatingthevarioustasksandactivitiesinvolvedinthedatascienceprocess,data scienceworkflowmanagementhelpsensurethatprojectsarecompletedontime,withinbudget,and withhighlevelsofaccuracyandreproducibility.

Oneofthekeybenefitsofdatascienceworkflowmanagementisthatitpromotesamorestructured, methodologicalapproachtodatascience.Bybreakingdownthedatascienceprocessintodiscrete stepsandtasks,datascienceworkflowmanagementmakesiteasiertomanagecomplexprojects andidentifypotentialbottlenecksorareaswhereimprovementscanbemade.This,inturn,canhelp ensurethatdatascienceprojectsarecompletedmoree icientlyandwithgreaterlevelsofaccuracy.

Anotherimportantbenefitofdatascienceworkflowmanagementisthatitcanhelpensurethatthe resultsofdatascienceprojectsaremorereproducible.Bykeepingdetailedrecordsofallthesteps takeninthedatascienceprocess,datascienceworkflowmanagementmakesiteasiertoreplicatethe resultsofanalysesandverifytheiraccuracy.Thisisparticularlyimportantinfieldswhereaccuracyand reproducibilityareessential,suchasscientificresearchandfinancialmodeling.

Inadditiontothesebenefits,e ectivedatascienceworkflowmanagementcanalsoleadtomore e ectivecollaborationandcommunicationamongteammembers.Byutilizingprojectmanagement toolsandotherso waredesignedfordatascienceworkflowmanagement,teammemberscanwork

IbonMartínez-ArranzPage5

togethermoree icientlyande ectively,sharingdata,insights,andfeedbackinreal-time.Thiscan helpensurethatprojectsstayontrackandthateveryoneinvolvedisworkingtowardthesamegoals.

Thereareanumberofso waretoolsavailablefordatascienceworkflowmanagement,including popularplatformslikeJupyterNotebooks,ApacheAirflow,andApacheNiFi.Eachoftheseplatforms o ersauniquesetoffeaturesandcapabilitiesdesignedtosupportdi erentaspectsofthedatascience workflow,fromdatacleaningandpreparationtomodeltraininganddeployment.Byleveragingthese tools,datascientistsandotherprofessionalsinvolvedinthedatascienceprocesscanworkmore e icientlyande ectively,improvingthequalityandaccuracyoftheirwork.

Overall,datascienceworkflowmanagementisanessentialaspectofmoderndatascience.Bypromotingamorestructured,methodologicalapproachtodatascienceandleveragingtherighttools andtechnologies,datascientistsandotherprofessionalsinvolvedinthedatascienceprocesscan ensurethattheirprojectsarecompletedontime,withinbudget,andwithhighlevelsofaccuracyand reproducibility.

References

Books

• Peng,R.D.(2016).Rprogrammingfordatascience.Availableathttps://bookdown.org/rdpeng/ rprogdatascience/

• Wickham,H.,&Grolemund,G.(2017).Rfordatascience:import,tidy,transform,visualize,and modeldata.Availableathttps://r4ds.had.co.nz/

• Géron,A.(2019).Hands-onmachinelearningwithScikit-Learn,Keras,andTensorFlow:Concepts, tools,andtechniquestobuildintelligentsystems.Availableathttps://www.oreilly.com/library/ view/hands-on-machine-learning/9781492032632/

• Shrestha,S.(2020).DataScienceWorkflowManagement:FromBasicstoDeployment.Available athttps://www.springer.com/gp/book/9783030495362

• Grollman,D.,&Spencer,B.(2018).Datascienceprojectmanagement:fromconceptionto deployment.Apress.

• Kelleher,J.D.,Tierney,B.,&Tierney,B.(2018).DatascienceinR:acasestudiesapproachto computationalreasoningandproblemsolving.CRCPress.

• VanderPlas,J.(2016).Pythondatasciencehandbook:Essentialtoolsforworkingwithdata. O’ReillyMedia,Inc. Page6IbonMartínez-Arranz

ExploratoryDataAnalysis

• Kluyver,T.,Ragan-Kelley,B.,Pérez,F.,Granger,B.,Bussonnier,M.,Frederic,J.,...&Ivanov, P.(2016).JupyterNotebooks-apublishingformatforreproduciblecomputationalworkflows. PositioningandPowerinAcademicPublishing:Players,AgentsandAgendas,87.

• Pérez,F.,&Granger,B.E.(2007).IPython:asystemforinteractivescientificcomputing.ComputinginScience&Engineering,9(3),21-29.

• Rule,A.,Tabard-Cossa,V.,&Burke,D.T.(2018).Opensciencegoesmicroscopic:anapproachto knowledgesharinginneuroscience.ScientificData,5(1),180268.

• Shen,H.(2014).Interactivenotebooks:Sharingthecode.Nature,515(7525),151-152.

ExploratoryDataAnalysis

ExploratoryDataAnalysis(EDA) isacrucialstepinthedatascienceworkflowthatinvolvesanalyzingandvisualizingdatatogaininsights,identifypatterns,andunderstand theunderlyingstructureofthedataset.Itplaysavitalroleinuncoveringrelationships, detectinganomalies,andinformingsubsequentmodelinganddecision-makingprocesses.

ExploratoryDataAnalysis(EDA)standsasanimportantphasewithinthedatascienceworkflow, encompassingtheexaminationandvisualizationofdatatogleaninsights,detectpatterns,and comprehendtheinherentstructureofthedataset.ImagegeneratedwithDALL-E.

TheimportanceofEDAliesinitsabilitytoprovideacomprehensiveunderstandingofthedatasetbefore

divingintomorecomplexanalysisormodelingtechniques.Byexploringthedata,datascientistscan identifypotentialissuessuchasmissingvalues,outliers,orinconsistenciesthatneedtobeaddressed beforeproceedingfurther.EDAalsohelpsinformulatinghypotheses,generatingideas,andguiding thedirectionoftheanalysis.

Thereareseveraltypesofexploratorydataanalysistechniquesthatcanbeapplieddependingonthe natureofthedatasetandtheresearchquestionsathand.Thesetechniquesinclude:

• DescriptiveStatistics:Descriptivestatisticsprovidesummarymeasuressuchasmean,median, standarddeviation,andpercentilestodescribethecentraltendency,dispersion,andshapeof thedata.Theyo eraquickoverviewofthedataset’scharacteristics.

• DataVisualization:Datavisualizationtechniques,suchasscatterplots,histograms,boxplots, andheatmaps,helpinvisuallyrepresentingthedatatoidentifypatterns,trends,andpotential outliers.Visualizationsmakeiteasiertointerpretcomplexdataanduncoverinsightsthatmay notbeevidentfromrawnumbersalone.

• CorrelationAnalysis:Correlationanalysisexplorestherelationshipsbetweenvariablestounderstandtheirinterdependence.Correlationcoe icients,scatterplots,andcorrelationmatrices areusedtoassessthestrengthanddirectionofassociationsbetweenvariables.

• DataTransformation:Datatransformationtechniques,suchasnormalization,standardization, orlogarithmictransformations,areappliedtomodifythedatadistribution,handleskewness,or improvethemodel’sassumptions.Thesetransformationscanhelprevealhiddenpatternsand makethedatamoresuitableforfurtheranalysis.

Byapplyingtheseexploratorydataanalysistechniques,datascientistscangainvaluableinsights intothedataset,identifypotentialissues,validateassumptions,andmakeinformeddecisionsabout subsequentdatamodelingoranalysisapproaches.

Exploratorydataanalysissetsthefoundationforacomprehensiveunderstandingofthedataset, allowingdatascientiststomakeinformeddecisionsanduncovervaluableinsightsthatdrivefurther analysisanddecision-makingindatascienceprojects.

DescriptiveStatistics

Descriptivestatisticsisabranchofstatisticsthatinvolvestheanalysisandsummaryofdatatogain insightsintoitsmaincharacteristics.Itprovidesasetofquantitativemeasuresthatdescribethe centraltendency,dispersion,andshapeofadataset.Thesestatisticshelpinunderstandingthedata distribution,identifyingpatterns,andmakingdata-drivendecisions.

Thereareseveralkeydescriptivestatisticscommonlyusedtosummarizedata:

• Mean:Themean,oraverage,iscalculatedbysummingallvaluesinadatasetanddividingby thetotalnumberofobservations.Itrepresentsthecentraltendencyofthedata.

• Median:Themedianisthemiddlevalueinadatasetwhenitisarrangedinascendingordescendingorder.Itislessa ectedbyoutliersandprovidesarobustmeasureofcentraltendency.

• Mode:Themodeisthemostfrequentlyoccurringvalueinadataset.Itrepresentsthevalueor valueswiththehighestfrequency.

• Variance:Variancemeasuresthespreadordispersionofdatapointsaroundthemean.Itquantifiestheaveragesquareddi erencebetweeneachdatapointandthemean.

• StandardDeviation:Standarddeviationisthesquarerootofthevariance.Itprovidesameasure oftheaveragedistancebetweeneachdatapointandthemean,indicatingtheamountofvariation inthedataset.

• Range:Therangeisthedi erencebetweenthemaximumandminimumvaluesinadataset.It providesanindicationofthedata’sspread.

• Percentiles:Percentilesdivideadatasetintohundredths,representingtherelativepositionofa valueincomparisontotheentiredataset.Forexample,the25thpercentile(alsoknownasthe firstquartile)representsthevaluebelowwhich25%ofthedatafalls.

Now,let’sseesomeexamplesofhowtocalculatethesedescriptivestatisticsusingPython:

1 import numpyasnpy

2

3 data =[10,12,14,16,18,20]

4

5 mean = npy.mean(data)

6 median = npy.median(data)

7 mode = npy.mode(data)

8 variance = npy.var(data)

9 std_deviation = npy.std(data)

10 data_range = npy.ptp(data)

11 percentile_25 = npy.percentile(data,25)

12 percentile_75 = npy.percentile(data,75)

13

14 print("Mean:", mean)

15 print("Median:", median)

16 print("Mode:", mode)

17 print("Variance:", variance)

18 print("StandardDeviation:", std_deviation)

19 print("Range:", data_range)

20 print("25thPercentile:", percentile_25)

21 print("75thPercentile:", percentile_75)

Intheaboveexample,weusetheNumPylibraryinPythontocalculatethedescriptivestatistics. The mean, median, mode, variance, std_deviation, data_range, percentile_25,and

percentile_75 variablesrepresenttherespectivedescriptivestatisticsforthegivendataset.

Descriptivestatisticsprovideaconcisesummaryofdata,allowingdatascientiststounderstandits centraltendencies,variability,anddistributioncharacteristics.Thesestatisticsserveasafoundation forfurtherdataanalysisanddecision-makinginvariousfields,includingdatascience,finance,social sciences,andmore.

Withpandaslibrary,it’seveneasier.

1 import pandasaspd

2

3 #Createadictionarywithsampledata

4 data ={

5 'Name':['John' , 'Maria' , 'Carlos' , 'Anna' , 'Luis'],

6 'Age':[28,24,32,22,30],

7 'Height(cm)':[175,162,180,158,172],

8 'Weight(kg)':[75,60,85,55,70]

9 }

10

11 #CreateaDataFramefromthedictionary

12 df = pd.DataFrame(data) 13

14 #DisplaytheDataFrame

15 print("DataFrame:")

16 print(df)

18 #Getbasicdescriptivestatistics

19 descriptive_stats = df.describe()

20

21 #Displaythedescriptivestatistics

22 print("\nDescriptiveStatistics:")

23 print(descriptive_stats)

ExploratoryDataAnalysis

ThecodecreatesaDataFramewithsampledataaboutnames,ages,heights,andweightsandthen uses describe() toobtainbasicdescriptivestatisticssuchascount,mean,standarddeviation, minimum,maximum,andquartilesforthenumericcolumnsintheDataFrame.

DataVisualization

Datavisualizationisacriticalcomponentofexploratorydataanalysis(EDA)thatallowsustovisually representdatainameaningfulandintuitiveway.Itinvolvescreatinggraphicalrepresentationsofdata touncoverpatterns,relationships,andinsightsthatmaynotbeapparentfromrawdataalone.Byleveragingvariousvisualtechniques,datavisualizationenablesustocommunicatecomplexinformation e ectivelyandmakedata-drivendecisions.

E ectivedatavisualizationreliesonselectingappropriatecharttypesbasedonthetypeofvariables beinganalyzed.Wecanbroadlycategorizevariablesintothreetypes:

QuantitativeVariables

Thesevariablesrepresentnumericaldataandcanbefurtherclassifiedintocontinuousordiscrete variables.Commoncharttypesforvisualizingquantitativevariablesinclude:

Variable Type Chart Type

Continuous LinePlot

Continuous Histogram

Discrete BarChart

Discrete Scatter Plot

Showsthetrendandpatternsover time plt.plot(x,y)

Displaysthedistributionofvalues plt.hist(data)

Comparesvaluesacrossdi erent categories plt.bar(x,y)

Examinestherelationshipbetween variables plt.scatter(x,y)

Table1: TypesofchartsandtheirdescriptionsinPython.

CategoricalVariables

Thesevariablesrepresentqualitativedatathatfallintodistinctcategories.Commoncharttypesfor visualizingcategoricalvariablesinclude:

Variable

Categorical BarChart

Categorical PieChart

Categorical Heatmap

Displaysthefrequencyorcountof categories plt.bar(x,y)

Representstheproportionofeach category plt.pie(data,labels=labels)

Showstherelationshipbetweentwo categoricalvariables sns.heatmap(data)

Table2: TypesofchartsforcategoricaldatavisualizationinPython.

ExploratoryDataAnalysis

OrdinalVariables

Thesevariableshaveanaturalorderorhierarchy.Charttypessuitableforvisualizingordinalvariables include:

Variable

Ordinal BarChart Comparesvaluesacrossdi erent categories plt.bar(x,y)

Ordinal BoxPlot Displaysthedistributionandoutliers sns.boxplot(x,y)

Table3: TypesofchartsforordinaldatavisualizationinPython.

DatavisualizationlibrarieslikeMatplotlib,Seaborn,andPlotlyinPythonprovideawiderangeof functionsandtoolstocreatethesevisualizations.Byutilizingtheselibrariesandtheircorresponding commands,wecangeneratevisuallyappealingandinformativeplotsforEDA.

ExploratoryDataAnalysis

Library Description

Matplotlib Matplotlibisaversatileplottinglibraryforcreatingstatic,animated, andinteractivevisualizationsinPython.Ito ersawiderangeofchart typesandcustomizationoptions.

Seaborn SeabornisastatisticaldatavisualizationlibrarybuiltontopofMatplotlib.Itprovidesahigh-levelinterfaceforcreatingattractiveand informativestatisticalgraphics.

Altair AltairisadeclarativestatisticalvisualizationlibraryinPython.It allowsuserstocreateinteractivevisualizationswithconciseand expressivesyntax,basedontheVega-Litegrammar.

Plotly Plotlyisanopen-source,web-basedlibraryforcreatinginteractive visualizations.Ito ersawiderangeofcharttypes,including2Dand 3Dplots,andsupportsinteractivityandsharingcapabilities.

Website

Plotly ggplot ggplotisaplottingsystemforPythonbasedontheGrammarof Graphics.Itprovidesapowerfulandflexiblewaytocreateaestheticallypleasingandpublication-qualityvisualizations.

Bokeh BokehisaPythonlibraryforcreatinginteractivevisualizationsfor theweb.ItfocusesonprovidingelegantandconciseAPIsforcreating dynamicplotswithinteractivityandstreamingcapabilities.

Plotnine PlotnineisaPythonimplementationoftheGrammarofGraphics. Itallowsuserstocreatevisuallyappealingandhighlycustomizable plotsusingasimpleandintuitivesyntax.

Table4: Pythondatavisualizationlibraries.

ggplot

Pleasenotethatthedescriptionsprovidedabovearesimplifiedsummaries,andformoredetailed information,itisrecommendedtovisittherespectivewebsitesofeachlibrary.Pleasenotethatthe Pythoncodeprovidedaboveisasimplifiedrepresentationandmayrequireadditionalcustomization basedonthespecificdataandplotrequirements.

CorrelationAnalysis

Correlationanalysisisastatisticaltechniqueusedtomeasurethestrengthanddirectionoftherelationshipbetweentwoormorevariables.Ithelpsinunderstandingtheassociationbetweenvariables andprovidesinsightsintohowchangesinonevariablearerelatedtochangesinanother.

Thereareseveraltypesofcorrelationanalysiscommonlyused:

Matplotlib
Seaborn
Altair
Bokeh
Plotnine

ExploratoryDataAnalysis

• PearsonCorrelation:Pearsoncorrelationcoe icientmeasuresthelinearrelationshipbetween twocontinuousvariables.Itcalculatesthedegreetowhichthevariablesarelinearlyrelated, rangingfrom-1to1.Avalueof1indicatesaperfectpositivecorrelation,-1indicatesaperfect negativecorrelation,and0indicatesnolinearcorrelation.

• SpearmanCorrelation:Spearmancorrelationcoe icientassessesthemonotonicrelationship betweenvariables.Itranksthevaluesofthevariablesandcalculatesthecorrelationbasedon therankorder.Spearmancorrelationisusedwhenthevariablesarenotnecessarilylinearly relatedbutshowaconsistenttrend.

Calculationofcorrelationcoe icientscanbeperformedusingPython:

1 import pandasaspd

2

3 #Generatesampledata

4 data = pd.DataFrame({

5 'X':[1,2,3,4,5],

6 'Y':[2,4,6,8,10],

7 'Z':[3,6,9,12,15]

8 })

9

10 #CalculatePearsoncorrelationcoefficient

11 pearson_corr = data['X'].corr(data['Y'])

12

13 #CalculateSpearmancorrelationcoefficient

14 spearman_corr = data['X'].corr(data['Y'], method='spearman')

15

16 print("PearsonCorrelationCoefficient:", pearson_corr)

17 print("SpearmanCorrelationCoefficient:", spearman_corr)

Intheaboveexample,weusethePandaslibraryinPythontocalculatethecorrelationcoe icients. The corr functionisappliedtothecolumns 'X' and 'Y' ofthe data DataFrametocomputethe PearsonandSpearmancorrelationcoe icients.

Pearsoncorrelationissuitableforvariableswithalinearrelationship,whileSpearmancorrelation ismoreappropriatewhentherelationshipismonotonicbutnotnecessarilylinear.Bothcorrelation coe icientsrangebetween-1and1,withhigherabsolutevaluesindicatingstrongercorrelations.

Correlationanalysisiswidelyusedindatasciencetoidentifyrelationshipsbetweenvariables,uncover patterns,andmakeinformeddecisions.Ithasapplicationsinfieldssuchasfinance,socialsciences, healthcare,andmanyothers.

IbonMartínez-ArranzPage17

DataTransformation

Datatransformationisacrucialstepintheexploratorydataanalysisprocess.Itinvolvesmodifying theoriginaldatasettoimproveitsquality,addressdataissues,andprepareitforfurtheranalysis.By applyingvarioustransformations,wecanuncoverhiddenpatterns,reducenoise,andmakethedata moresuitableformodelingandvisualization.

ImportanceofDataTransformation

Datatransformationplaysavitalroleinpreparingthedataforanalysis.Ithelpsinachievingthe followingobjectives:

• DataCleaning: Transformationtechniqueshelpinhandlingmissingvalues,outliers,andinconsistentdataentries.Byaddressingtheseissues,weensuretheaccuracyandreliabilityofour analysis.

• Normalization: Di erentvariablesinadatasetmayhavedi erentscales,units,orranges. Normalizationtechniquessuchasmin-maxscalingorz-scorenormalizationbringallvariables toacommonscale,enablingfaircomparisonsandavoidingbiasinsubsequentanalyses.

• FeatureEngineering: Transformationallowsustocreatenewfeaturesorderivemeaningful informationfromexistingvariables.Thisprocessinvolvesextractingrelevantinformation,creatinginteractionterms,orencodingcategoricalvariablesforbetterrepresentationandpredictive power.

• Non-linearityHandling: Insomecases,relationshipsbetweenvariablesmaynotbelinear. Transformingvariablesusingfunctionslikelogarithm,exponential,orpowertransformations canhelpcapturenon-linearpatternsandimprovemodelperformance.

• OutlierTreatment: Outlierscansignificantlyimpacttheanalysisandmodelperformance.Transformationssuchaswinsorizationorlogarithmictransformationcanhelpreducetheinfluenceof outlierswithoutlosingvaluableinformation.

ExploratoryDataAnalysis

Purpose LibraryName Description

DataCleaning

Pandas (Python)

Website

Apowerfuldatamanipulationlibraryfor cleaningandpreprocessingdata. Pandas

dplyr(R) Providesasetoffunctionsfordatawrangling anddatamanipulationtasks. dplyr

Normalization

scikit-learn (Python) O ersvariousnormalizationtechniquessuchas Min-MaxscalingandZ-scorenormalization.

scikit-learn

caret(R) Providespre-processingfunctions,including normalization,forbuildingmachinelearning models. caret

FeatureEngineering

Featuretools (Python)

Alibraryforautomatedfeatureengineeringthat cangeneratenewfeaturesfromexistingones.

Featuretools

recipes(R) O ersaframeworkforfeatureengineering, allowing userstocreatecustomfeature transformationpipelines. recipes

Non-LinearityHandling

TensorFlow (Python)

Adeeplearninglibrarythatsupportsbuilding andtrainingnon-linearmodelsusingneural networks.

keras(R) Provideshigh-levelinterfacesforbuilding andtrainingneuralnetworkswithnon-linear activationfunctions.

OutlierTreatment

PyOD(Python) Acomprehensivelibraryforoutlierdetection andremovalusingvariousalgorithmsand models.

outliers(R) Implementsvariousmethodsfordetectingand handlingoutliersindatasets.

Table5: Datapreprocessingandmachinelearninglibraries.

TensorFlow

keras

PyOD

outliers

TypesofDataTransformation

Thereareseveralcommontypesofdatatransformationtechniquesusedinexploratorydataanalysis:

• ScalingandStandardization: Thesetechniquesadjustthescaleanddistributionofvariables, makingthemcomparableandsuitableforanalysis.Examplesincludemin-maxscaling,z-score normalization,androbustscaling.

• LogarithmicTransformation: Thistransformationisusefulforhandlingvariableswithskewed distributionsorexponentialgrowth.Ithelpsinstabilizingvarianceandbringingextremevalues closertothemean.

• PowerTransformation: Powertransformations,suchassquareroot,cuberoot,orBox-Cox transformation,canbeappliedtohandlevariableswithnon-linearrelationshipsorheteroscedasticity.

• BinningandDiscretization: Binninginvolvesdividingacontinuousvariableintocategoriesor intervals,simplifyingtheanalysisandreducingtheimpactofoutliers.Discretizationtransforms continuousvariablesintodiscreteonesbyassigningthemtospecificrangesorbins.

• EncodingCategoricalVariables: Categoricalvariableso enneedtobeconvertedintonumerical representationsforanalysis.Techniqueslikeone-hotencoding,labelencoding,orordinal encodingareusedtotransformcategoricalvariablesintonumericequivalents.

• FeatureScaling: Featurescalingtechniques,suchasmeannormalizationorunitvectorscaling, ensurethatdi erentfeatureshavesimilarscales,avoidingdominancebyvariableswithlarger magnitudes.

Byemployingthesetransformationtechniques,datascientistscanenhancethequalityofthedataset, uncoverhiddenpatterns,andenablemoreaccurateandmeaningfulanalyses.

Keepinmindthattheselectionandapplicationofspecificdatatransformationtechniquesdependon thecharacteristicsofthedatasetandtheobjectivesoftheanalysis.Itisessentialtounderstandthe dataandchoosetheappropriatetransformationstoderivevaluableinsights.

ExploratoryDataAnalysis

Transformation Mathematical Equation

Advantages

Disadvantages

Logarithmic y =log(x) -Reducestheimpactof extremevalues -Doesnotworkwithzeroor negativevalues

SquareRoot y = √x -Reducestheimpactof extremevalues -Doesnotworkwithnegativevalues

Exponential y =expx -Increasesseparation betweensmallvalues -Amplifiesthedi erences betweenlargevalues

Box-Cox y = xλ 1 λ -Adaptstodi erenttypes ofdata -Requiresestimationofthe λ parameter

Power y = xp -Allowscustomizationof thetransformation -Sensitivitytothechoiceof powervalue

Square y = x2 -Preservestheorderof values -Amplifiesthedi erences betweenlargevalues

Inverse y = 1 x -Reducestheimpactof largevalues -Doesnotworkwithzeroor negativevalues

Min-Max Scaling y = x minx maxx minx -Scalesthedatatoa specificrange -Sensitivetooutliers

Z-ScoreScaling y = x x σx -Centersthedataaround zeroandscaleswith standarddeviation -Sensitivetooutliers

Rank Transformation Assignsrankvalues tothedatapoints -Preservestheorderof valuesandhandlesties gracefully -Lossofinformationabout theoriginalvalues

Table6: Datatransformationmethodsinstatistics.

PracticalExample:HowtoUseaDataVisualizationLibrarytoExploreand AnalyzeaDataset

Inthispracticalexample,wewilldemonstratehowtousetheMatplotliblibraryinPythontoexploreand analyzeadataset.Matplotlibisawidely-useddatavisualizationlibrarythatprovidesacomprehensive setoftoolsforcreatingvarioustypesofplotsandcharts.

DatasetDescription

Forthisexample,let’sconsideradatasetcontaininginformationaboutthesalesperformanceof di erentproductsacrossvariousregions.Thedatasetincludesthefollowingcolumns:

• Product:Thenameoftheproduct.

• Region:Thegeographicalregionwheretheproductissold.

• Sales:Thesalesvalueforeachproductinaspecificregion.

1 Product,Region,Sales

2 ProductA,Region 1,1000

3 ProductB,Region 2,1500

4 ProductC,Region 1,800

5 ProductA,Region 3,1200

6 ProductB,Region 1,900

7 ProductC,Region 2,1800

8 ProductA,Region 2,1100

9 ProductB,Region 3,1600

10 ProductC,Region 3,750

ImportingtheRequiredLibraries

Tobegin,weneedtoimportthenecessarylibraries.WewillimportMatplotlibfordatavisualization andPandasfordatamanipulationandanalysis.

1 import matplotlib.pyplotasplt

2 import pandasaspd

LoadingtheDataset

Next,weloadthedatasetintoaPandasDataFrameforfurtheranalysis.Assumingthedatasetisstored inaCSVfilenamed“sales_data.csv,”wecanusethefollowingcode:

ExploratoryDataAnalysis

1 df = pd.read_csv("sales_data.csv")

ExploratoryDataAnalysis

Oncethedatasetisloaded,wecanstartexploringandanalyzingthedatausingdatavisualization techniques.

VisualizingSalesDistribution

Tounderstandthedistributionofsalesacrossdi erentregions,wecancreateabarplotshowingthe totalsalesforeachregion:

1 sales_by_region = df.groupby("Region")["Sales"].sum()

2 plt.bar(sales_by_region.index, sales_by_region.values)

3 plt.xlabel("Region")

4 plt.ylabel("TotalSales")

5 plt.title("SalesDistributionbyRegion")

6 plt.show()

Thisbarplotprovidesavisualrepresentationofthesalesdistribution,allowingustoidentifyregions withthehighestandlowestsales.

VisualizingProductPerformance

Wecanalsovisualizetheperformanceofdi erentproductsbycreatingahorizontalbarplotshowing thesalesforeachproduct:

1 sales_by_product = df.groupby("Product")["Sales"].sum()

2 plt.bar(sales_by_product.index, sales_by_product.values)

3 plt.xlabel("Product")

4 plt.ylabel("TotalSales")

5 plt.title("SalesDistributionbyProduct")

6 plt.show()

Thisbarplotprovidesavisualrepresentationofthesalesdistribution,allowingustoidentifyproducts withthehighestandlowestsales.

IbonMartínez-ArranzPage23

References

Books

• Aggarwal,C.C.(2015).DataMining:TheTextbook.Springer.

• Tukey,J.W.(1977).ExploratoryDataAnalysis.Addison-Wesley.

• Wickham,H.,&Grolemund,G.(2017).RforDataScience.O’ReillyMedia.

• McKinney,W.(2018).PythonforDataAnalysis.O’ReillyMedia.

• Wickham,H.(2010).ALayeredGrammarofGraphics.JournalofComputationalandGraphical Statistics.

• VanderPlas,J.(2016).PythonDataScienceHandbook.O’ReillyMedia.

• Bruce,P.andBruce,A.(2017).PracticalStatisticsforDataScientists.O’ReillyMedia.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
EDA-Ebook by labortoriosrubio - Issuu