我有系数和常数。我想像这个例子一样将这些值相乘并相加。
预测 = 222 + (555-07 * 第 1 列) + (-555-07 * 列2) + (-66* 列3) + (55* 第 4 列) + (777* 第 5 列)
我有一个一行数据帧,其中包含这样的系数和常数
col1 | col2 | col3 | col4 | 第5栏 | 常数 | |
---|---|---|---|---|---|---|
2.447697e-07 | -5.214072e-07 | -0.000003 | 0.000006 | 555 | 222 |
以及另一个名称完全相同但具有每月值的数据框。
col1 | col2 | col3 | col4 | 第5栏 |
---|---|---|---|---|
16711 | 17961 | 0 | 20 | 55 |
我已经尝试对列进行排序,然后我取它们的乘积
df.dot
。
selected_columns = selected_columns.sort_index(axis=1)
#mean_coefficients dataframe 21th (starting from 0) is constant so i use the other columns
selected_columns['predicted_Mcap']=selected_columns.dot(mean_coefficients.iloc[:,0:20])+mean_coefficients['const']
所以我计算了预测值,但是当我在 Excel 中检查时,该值并不相同。
我计算得对吗?
这是矩阵乘法:
monthly_df.assign(constant=1) @ constant_df.T