Linear Regression — statsmodels | Statsmodels OLS

SkiptocontentUserGuidestatsmodelsv0.12.2statsmodelsInstallingstatsmodelsGettingstartedUserGuideBackgroundRegressionandLinearModelsLinearRegressionLinearRegressionContentsLinearRegressionExamplesTechnicalDocumentationReferencesAttributesModuleReferenceModelClassesResultsClassesShowSourceGeneralizedLinearModelsGeneralizedEstimatingEquationsGeneralizedAdditiveModels(GAM)RobustLinearModelsLinearMixedEffectsModelsRegressionwithDiscreteDependentVariableGeneralizedLinearMixedEffectsModelsANOVATimeSeriesAnalysisOtherModelsStatisticsandToolsDataSetsSandboxExamplesAPIReferenceAboutstatsmodelsDeveloperPageReleaseNotesContentsLinearRegressionExamplesTechnicalDocumentationReferencesAttributesModuleReferenceModelClassesResultsClassesShowSourceLinearRegression¶Linearmodelswithindependentlyandidenticallydistributederrors,andforerrorswithheteroscedasticityorautocorrelation.Thismoduleallowsestimationbyordinaryleastsquares(OLS),weightedleastsquares(WLS),generalizedleastsquares(GLS),andfeasiblegeneralizedleastsquareswithautocorrelatedAR(p)errors.SeeModuleReferenceforcommandsandarguments.Examples¶#LoadmodulesanddataIn[1]:importnumpyasnpIn[2]:importstatsmodels.apiassmIn[3]:spector_data=sm.datasets.spector.load(as_pandas=False)In[4]:spector_data.exog=sm.add_constant(spector_data.exog,prepend=False)#FitandsummarizeOLSmodelIn[5]:mod=sm.OLS(spector_data.endog,spector_data.exog)In[6]:res=mod.fit()In[7]:print(res.summary())OLSRegressionResults==============================================================================Dep.Variable:yR-squared:0.416Model:OLSAdj.R-squared:0.353Method:LeastSquaresF-statistic:6.646Date:Tue,02Feb2021Prob(F-statistic):0.00157Time:07:07:13Log-Likelihood:-12.978No.Observations:32AIC:33.96DfResiduals:28BIC:39.82DfModel:3CovarianceType:nonrobust==============================================================================coefstderrtP>|t|[0.0250.975]------------------------------------------------------------------------------x10.46390.1622.8640.0080.1320.796x20.01050.01


常見投資理財問答