statsmodels.regression.linear | Statsmodels OLS

SkiptocontentUserGuideLinearRegressionstatsmodelsv0.12.2statsmodelsInstallingstatsmodelsGettingstartedUserGuideBackgroundRegressionandLinearModelsLinearRegressionGeneralizedLinearModelsGeneralizedEstimatingEquationsGeneralizedAdditiveModels(GAM)RobustLinearModelsLinearMixedEffectsModelsRegressionwithDiscreteDependentVariableGeneralizedLinearMixedEffectsModelsANOVATimeSeriesAnalysisOtherModelsStatisticsandToolsDataSetsSandboxExamplesAPIReferenceAboutstatsmodelsDeveloperPageReleaseNotesShowSourcestatsmodels.regression.linear_model.OLS¶classstatsmodels.regression.linear_model.OLS(endog,exog=None,missing='none',hasconst=None,**kwargs)[source]¶OrdinaryLeastSquaresParametersendogarray_likeA1-dendogenousresponsevariable.Thedependentvariable.exogarray_likeAnobsxkarraywherenobsisthenumberofobservationsandkisthenumberofregressors.Aninterceptisnotincludedbydefaultandshouldbeaddedbytheuser.Seestatsmodels.tools.add_constant.missingstrAvailableoptionsare‘none’,‘drop’,and‘raise’.If‘none’,nonancheckingisdone.If‘drop’,anyobservationswithnansaredropped.If‘raise’,anerrorisraised.Defaultis‘none’.hasconstNoneorboolIndicateswhethertheRHSincludesauser-suppliedconstant.IfTrue,aconstantisnotcheckedforandk_constantissetto1andallresultstatisticsarecalculatedasifaconstantispresent.IfFalse,aconstantisnotcheckedforandk_constantissetto0.**kwargsExtraargumentsthatareusedtosetmodelpropertieswhenusingtheformulainterface.SeealsoWLSFitalinearmodelusingWeightedLeastSquares.GLSFitalinearmodelusingGeneralizedLeastSquares.NotesNoconstantisaddedbythemodelunlessyouareusingformulas.Examples>>>importstatsmodels.apiassm>>>importnumpyasnp>>>duncan_prestige=sm.datasets.get_rdataset("Duncan","carData")>>>Y=duncan_prestige.data['income']>>>X=duncan_prestige.data['education']>>>X=sm.add_constant(X)>>>model=sm.OLS(Y,X)>>>results=model.fit()>>>results.paramsconst10.603498education0.594859dtype:float64>>>results.tvaluesconst2.039813education6.892802dtype:float64>>>print(results.t_test([1,0]))TestforConstraints========


常見投資理財問答