1

I'm trying to understand simple regression and how the model predict work. The result of predict is an array of fitted values. But what if I only want one value for example.

If I want X=11 ( expected predict to only give me 110 ) why do I still get array of output and how can I reduce to only one value ? to get 110 ?

import statsmodels.api as sm
X = [1,2,3,4,5,6,7,8,9,10]
Y = [10,20,30,40,50,60,70,80,90,100]
X = sm.add_constant(X)                          
model = sm.OLS(Y,X)
results = model.fit()
ypred = model.predict(11)
print(ypred)

Output :

[[  11.   11.]
 [  11.   22.]
 [  11.   33.]
 [  11.   44.]
 [  11.   55.]
 [  11.   66.]
 [  11.   77.]
 [  11.   88.]
 [  11.   99.]
 [  11.  110.]]
Erba Aitbayev
  • 4,167
  • 12
  • 46
  • 81
JPC
  • 5,063
  • 20
  • 71
  • 100
  • 1
    You need to use `results.predict([1, 11])` not model.predict. See http://stackoverflow.com/questions/39714057/what-is-first-value-that-is-passed-into-statsmodels-predict-function for why you need the extra `1` – Josef Oct 02 '16 at 01:29

0 Answers0