# Prediction with Pandas OLS

I am using scikits.statsmodels OLS to predict data, but would now like to switch to using Pandas.

The documentation refers to OLS as well as a function called y_predict , but I can't find any documentation on how to use it correctly.

As an example:

```
exogenous = {
"1998": "4760","1999": "5904","2000": "4504","2001": "9808","2002": "4241","2003": "4086","2004": "4687","2005": "7686","2006": "3740","2007": "3075","2008": "3753","2009": "4679","2010": "5468","2011": "7154","2012": "4292","2013": "4283","2014": "4595","2015": "9194","2016": "4221","2017": "4520"}
endogenous = {
"1998": "691", "1999": "1580", "2000": "80", "2001": "1450", "2002": "555", "2003": "956", "2004": "877", "2005": "614", "2006": "468", "2007": "191"}
import numpy as np
from pandas import *
ols_test = ols(y=Series(endogenous), x=Series(exogenous))
```

However, while I can create a fit:

```
>>> ols_test.y_fitted
1998 675.268299
1999 841.176837
2000 638.141913
2001 1407.354228
2002 600.000352
2003 577.521485
2004 664.681478
2005 1099.611292
2006 527.342854
2007 430.901264
```

The forecast does not produce anything else:

```
>>> ols_test.y_predict
1998 675.268299
1999 841.176837
2000 638.141913
2001 1407.354228
2002 600.000352
2003 577.521485
2004 664.681478
2005 1099.611292
2006 527.342854
2007 430.901264
```

In scikits.statsmodels you can do the following:

`import scikits.statsmodels.api as sm ... ols_model = sm.OLS(endogenous, np.column_stack(exogenous)) ols_results = ols_mod.fit() ols_pred = ols_mod.predict(np.column_stack(exog_prediction_values))`

How do I do this in Pandas to predict endogenous data to the limits of exogenous?

UPDATE: Thanks to Chang, the newer version of Pandas (0.7.3) now has this functionality as standard.

source to share

is your problem how to get the predicted y values of your regression? Or how do you use regression coefficients to get predicted y values for a different set of samples for exogenous variables? pandas y_predict and y_fitted should give you the same value, and both should give you the same values as the predictive method in scikits.statsmodels.

If you are looking for regression coefficients do ols_test.beta p>

source to share