python笔记:7.2.1.4方差分析模型的参数估计和预测(影响数码相机销量)

 

# -*- coding: utf-8 -*-
"""
Created on Mon Jul  8 14:16:26 2019

@author: User
"""

# 《Python数据分析基础》中国统计出版社

#import numpy as np
from scipy import stats
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
from statsmodels.stats.multicomp import pairwise_tukeyhsd
from matplotlib.font_manager import FontProperties
myfont=FontProperties(fname='data\msyh.ttc')

dc_sales = pd.read_csv(u'data\\ch7\\dc_sales.csv',encoding = "gbk")

dc_sales['pixel'] = dc_sales['pixel'].astype('category')
dc_sales['pixel'].cat.categories=['500万像素及以下','500-600万像素',
        '600-800万像素','800-1000万像素',
        '1000万像素及以上']
print(dc_sales.head())

formula = 'sales ~ C(pixel)'
dc_sales_est = smf.ols(formula, dc_sales).fit()  # dc_sales_est 是一个模型对象

#print("\n dc_sales_est.summary():")
#print(dc_sales_est.summary())

print("\n dc_sales_est.summary2():")
print(dc_sales_est.summary2())

运行:

   market        pixel  sales
0       1    500万像素及以下     70
1       1   500-600万像素    101
2       1   600-800万像素    114
3       1  800-1000万像素    120
4       1   1000万像素及以上    132

 dc_sales_est.summary2():
                    Results: Ordinary least squares
=======================================================================
Model:                OLS                Adj. R-squared:       0.656   
Dependent Variable:   sales              AIC:                  314.0202
Date:                 2019-07-08 16:31   BIC:                  322.4646
No. Observations:     40                 Log-Likelihood:       -152.01 
Df Model:             4                  F-statistic:          19.57   
Df Residuals:         35                 Prob (F-statistic):   1.55e-08
R-squared:            0.691              Scale:                133.77  
-----------------------------------------------------------------------
                         Coef.  Std.Err.    t    P>|t|   [0.025  0.975]
-----------------------------------------------------------------------
Intercept               81.1250   4.0892 19.8387 0.0000 72.8234 89.4266
C(pixel)[T.500-600万像素]  14.6250   5.7831  2.5289 0.0161  2.8848 26.3652
C(pixel)[T.600-800万像素]  26.0000   5.7831  4.4959 0.0001 14.2598 37.7402
C(pixel)[T.800-1000万像素] 42.8750   5.7831  7.4139 0.0000 31.1348 54.6152
C(pixel)[T.1000万像素及以上]  41.0000   5.7831  7.0897 0.0000 29.2598 52.7402
-----------------------------------------------------------------------
Omnibus:                 0.757          Durbin-Watson:            1.535
Prob(Omnibus):           0.685          Jarque-Bera (JB):         0.172
Skew:                    -0.090         Prob(JB):                 0.917
Kurtosis:                3.266          Condition No.:            6    
=======================================================================

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值