Introduction — statsmodels | Statsmodels

Skiptocontentstatisticalmodels,hypothesistests,anddataexplorationstatsmodelsv0.13.0.dev0(+600)statsmodelsInstallingstatsmodelsGettingstartedUserGuideExamplesAPIReferenceAboutstatsmodelsDeveloperPageReleaseNotesContentsIntroductionCitationIndexShowSourcestatsmodelsisaPythonmodulethatprovidesclassesandfunctionsfortheestimationofmanydifferentstatisticalmodels,aswellasforconductingstatisticaltests,andstatisticaldataexploration.Anextensivelistofresultstatisticsareavailableforeachestimator.Theresultsaretestedagainstexistingstatisticalpackagestoensurethattheyarecorrect.ThepackageisreleasedundertheopensourceModifiedBSD(3-clause)license.Theonlinedocumentationishostedatstatsmodels.org.Introduction¶statsmodelssupportsspecifyingmodelsusingR-styleformulasandpandasDataFrames.Hereisasimpleexampleusingordinaryleastsquares:In[1]:importnumpyasnpIn[2]:importstatsmodels.apiassmIn[3]:importstatsmodels.formula.apiassmf#LoaddataIn[4]:dat=sm.datasets.get_rdataset("Guerry","HistData").data#Fitregressionmodel(usingthenaturallogofoneoftheregressors)In[5]:results=smf.ols('Lottery~Literacy+np.log(Pop1831)',data=dat).fit()#InspecttheresultsIn[6]:print(results.summary())OLSRegressionResults==============================================================================Dep.Variable:LotteryR-squared:0.348Model:OLSAdj.R-squared:0.333Method:LeastSquaresF-statistic:22.20Date:Tue,03Aug2021Prob(F-statistic):1.90e-08Time:09:33:22Log-Likelihood:-379.82No.Observations:86AIC:765.6DfResiduals:83BIC:773.0DfModel:2CovarianceType:nonrobust===================================================================================coefstderrtP>|t|[0.0250.975]-----------------------------------------------------------------------------------Intercept246.434135.2336.9950.000176.358316.510Literacy-0.48890.128-3.8320.000-0.743-0.235np.log(Pop1831)-31.31145.977-5.2390.000-43.199-19.424==============================================================================Omnibus:3.713Durbin-Watson:2.019Prob(Omnibus):0.156Jarque-Bera(JB):3


常見投資理財問答


延伸文章資訊