I want to store the coefficients of a statsmodels.api model for future use (so I don't have to run the model every time). When I get a new dataframe for which I want to make a prediction on, I want to be able to multiply each row of the dataframe by the coefficients( i.e. model.params). I would then sum the results of each row*coefficients to get the prediction for that row. However, it does not seem to be working for me when I try:
preds = []
for row in df.iterrows():
preds.append((model.params*row).sum())
Edit: example
df:
Height Weight Color
6 5 3
6 2 4
9 1 9
10 3 3
coefficients:
Height: -1.6403
Weight: 2.0435
Color: 300.4532
I would consider doing something like:
df.dot(model.params)
This computes the dot product on each of the rows of the DataFrame.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With