python多元线性回归_如何在Python中实现多元线性回归?

我试图从头开始写一个多元线性回归模型来预测影响Facebook上歌曲浏览量的关键因素。关于每首歌,我们收集这些信息,即我使用的变量:df.dtypes

clicked int64

listened_5s int64

listened_20s int64

views int64

percentage_listened float64

reactions_total int64

shared_songs int64

comments int64

avg_time_listened int64

song_length int64

likes int64

listened_later int64

我使用视图的数量作为因变量,而数据集中的所有其他变量作为独立变量。模型如下:

^{pr2}$

此处输出:regr.intercept_

array([-1173904.20950487])

MSE: 19722838329246.82

Variance Score: 0.99

好像出了什么大问题。在

尝试OLS模型:import statsmodels.api as sm

from statsmodels.sandbox.regression.predstd import wls_prediction_std

model=sm.OLS(y_train,x_train)

result = model.fit()

print(result.summary())

输出:R-squared: 0.992

F-statistic: 6121.

coef std err t P>|t| [95.0% Conf. Int.]

clicked 0.3333 0.012 28.257 0.000 0.310 0.356

listened_5s -0.4516 0.115 -3.944 0.000 -0.677 -0.227

listened_20s 1.9015 0.138 13.819 0.000 1.631 2.172

percentage_listened 7693.2520 1.44e+04 0.534 0.594 -2.06e+04 3.6e+04

reactions_total 8.6680 3.561 2.434 0.015 1.672 15.664

shared_songs -36.6376 3.688 -9.934 0.000 -43.884 -29.392

comments 34.9031 5.921 5.895 0.000 23.270 46.536

avg_time_listened 1.702e+05 4.22e+04 4.032 0.000 8.72e+04 2.53e+05

song_length -6309.8021 5425.543 -1.163 0.245 -1.7e+04 4349.413

likes 4.8448 4.194 1.155 0.249 -3.395 13.085

listened_later -2.3761 0.160 -14.831 0.000 -2.691 -2.061

Omnibus: 233.399 Durbin-Watson:

1.983

Prob(Omnibus): 0.000 Jarque-Bera (JB):

2859.005

Skew: 1.621 Prob(JB):

0.00

Kurtosis: 14.020 Cond. No.

2.73e+07

Warnings:

[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

[2] The condition number is large, 2.73e+07. This might indicate that there are strong multicollinearity or other numerical problems.

仅仅看一下这个输出,就好像有些事情出了严重的问题。在

我相信在训练/测试集和创建两个不同的数据帧x和y时出了问题,但不知道是什么问题。这个问题必须用多元回归来解决。它不是线性的吗?你能帮我找出哪里出了问题吗?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值