OLS estimation | Statsmodels OLS

SkiptocontentExamplesstatsmodelsv0.12.2statsmodelsInstallingstatsmodelsGettingstartedUserGuideExamplesLinearRegressionModelsOrdinaryLeastSquaresOrdinaryLeastSquaresContentsOrdinaryLeastSquaresOLSestimationOLSnon-linearcurvebutlinearinparametersOLSwithdummyvariablesJointhypothesistestFtestSmallgroupeffectsMulticollinearityConditionnumberDroppinganobservationShowSourceGeneralizedLeastSquaresQuantileregressionRecursiveleastsquaresExample2:QuantitytheoryofmoneyExample3:LinearrestrictionsandformulasRollingRegressionRegressiondiagnosticsWeightedLeastSquaresLinearMixedEffectsModelsComparingRlmertostatsmodelsMixedLMVarianceComponentAnalysisPlottingDiscreteChoiceModelsNonparametricStatisticsGeneralizedLinearModelsRobustRegressionGeneralizedEstimatingEquationsStatisticsTimeSeriesAnalysisStatespacemodelsStatespacemodels-TechnicalnotesForecastingMultivariateMethodsUserNotesAPIReferenceAboutstatsmodelsDeveloperPageReleaseNotesContentsOrdinaryLeastSquaresOLSestimationOLSnon-linearcurvebutlinearinparametersOLSwithdummyvariablesJointhypothesistestFtestSmallgroupeffectsMulticollinearityConditionnumberDroppinganobservationShowSourceOrdinaryLeastSquares¶[1]:%matplotlibinline[2]:importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportstatsmodels.apiassmfromstatsmodels.sandbox.regression.predstdimportwls_prediction_stdnp.random.seed(9876789)OLSestimation¶Artificialdata:[3]:nsample=100x=np.linspace(0,10,100)X=np.column_stack((x,x**2))beta=np.array([1,0.1,10])e=np.random.normal(size=nsample)Ourmodelneedsaninterceptsoweaddacolumnof1s:[4]:X=sm.add_constant(X)y=np.dot(X,beta)+eFitandsummary:[5]:model=sm.OLS(y,X)results=model.fit()print(results.summary())OLSRegressionResults==============================================================================Dep.Variable:yR-squared:1.000Model:OLSAdj.R-squared:1.000Method:LeastSquaresF-statistic:4.020e+06Date:Tue,02Feb2021Prob(F-statistic):2.83e-239Time:06:52:01Log-Likelihood:-146.51No.Observations:100AIC:299.0DfResiduals:97BIC:306.8DfModel:2


常見投資理財問答