Implementing ordinary least squares (OLS) using Statsmodels in Python ... | Statsmodels pandas

SigninMOBILE+MLLENSSTUDIOMACHINELEARNINGCOMMUNITYCONTRIBUTEALLABOUTFRITZAIImplementingordinaryleastsquares(OLS)usingStatsmodelsinPythonDhirajKFollowOct10,2019·4minreadPhotobyIlzeLuceroonUnsplashAreyoulookingforacomputationallycheap,easy-to-explainlinearestimatorthat’sbasedonsimplemathematics?LooknofurtherthanOLS!OLSstandsforordinaryleastsquares.OLSisheavilyusedineconometrics—abranchofeconomicswherestatisticalmethodsareusedtofindtheinsightsineconomicdata.Asweknow,thesimplestlinearregressionalgorithmassumesthattherelationshipbetweenanindependentvariable(x)anddependentvariable(y)isofthefollowingform:y=mx+c,whichistheequationofaline.Inlinewiththat,OLSisanestimatorinwhichthevaluesofmandc(fromtheaboveequation)arechoseninsuchawayastominimizethesumofthesquaresofthedifferencesbetweentheobserveddependentvariableandpredicteddependentvariable.That’swhyit’snamedordinaryleastsquares.Also,itshouldbenotedthatwhenthesumofthesquaresofthedifferencesisminimum,thelossisalsominimum—hencethepredictionisbetter.PleasefindbelowthevideoonMultipleLinearRegressioninPythonandsklearnJoinmorethan14,000ofyourfellowmachinelearnersanddatascientists.Subscribetothepremiernewsletterforallthingsdeeplearning.AdvantagesofOLSOLSiseasiertoimplementcomparedtoothersimilareconometrictechniques.Thisisbecausethetheoryofleastsquaresiseasiertounderstandforadeveloperthanothercommonapproaches.OLShasasimplemathematicalconceptsoitiseasiertoexplaintonon-technologistsorstakeholdersathighlevel.AssumptionsofOLSThereshouldbenomulticollinearitybetweenanytwoindependentvariables.Thevalueofthemeanoftheerrortermsshouldbezeroforgivenindependentvariables.ThesampletakenfortheOLSregressionmodelshouldbetakenrandomlyfromthepopulation.Alltheerrortermsintheregressionshouldhavethesamevariance,whichmeanshomoscedasticity.Photoby@chairulfajar_onUnsplashOLSusingStatsmodelsStatsmodelsispartofthescientificPythonlibrarythat’sinclinedtowardsdataanalysis,datascience,andstatistics.It’sbuiltontopofthenumericlibraryNumPyandthescientificlibrarySciPy.


常見投資理財問答


延伸文章資訊