如何打印阵列的完整信息?

How can I print the ndarray compelete information?

我一直在尝试匹配输出,但我没有得到我从 df 得到的列名,我将其放入 statmodels。

import pandas
import statsmodels.api as statmodel
df = pandas.read_csv('fastfood.csv')

df = df[['total_fat', 'sat_fat', 'cholesterol', 'sodium','calories']]
X = df[['total_fat', 'sat_fat', 'cholesterol', 'sodium']].values
Y = df[['calories']].values
X = statmodel.add_constant(X)
model = statmodel.OLS(Y, X).fit()

print(model.mse_total.round(2))
print(model.rsquared.round(2))
print(model.params.round(2))
print(model.pvalues.round(2))

我得到的输出:

79770.18
0.9
[71.73  9.1   0.6   0.21  0.16]
[0.   0.   0.64 0.07 0.  ]

我需要的输出:

79770.18
0.9 
-{0,}71.73 
total_fat 9.10 
sat_fat . ..0.60 
cholesterol 0.21 
sodium... ...0.16 
dtype: float64 
{0,}0.00 
total_fat 0.00 
sat_fat. ..0.64 
cholesterol...0.07 
sodium .. ..0.00 
dtype: float64

我试图删除 X 和 Y 定义中的 .values:

import pandas
import statsmodels.api as statmodel
df = pandas.DataFrame({'total_fat': np.random.rand(100), 
                       'sat_fat': np.random.rand(100), 
                       'cholesterol': np.random.rand(100), 
                       'sodium': np.random.rand(100),
                       'calories': np.random.rand(100)})

df = df[['total_fat', 'sat_fat', 'cholesterol', 'sodium','calories']]
X = df[['total_fat', 'sat_fat', 'cholesterol', 'sodium']]
Y = df[['calories']]
X = statmodel.add_constant(X)
model = statmodel.OLS(Y, X).fit()

print(model.mse_total.round(2))
print(model.rsquared.round(2))
print(model.params.round(2))
print(model.pvalues.round(2))

它给了我以下输出:

0.09
0.02
const          0.49
total_fat     -0.07
sat_fat        0.14
cholesterol    0.02
sodium        -0.01
dtype: float64
const          0.00
total_fat      0.54
sat_fat        0.21
cholesterol    0.83
sodium         0.89
dtype: float64