Sono in esecuzione regressione OLS usando pandas.stats.api.ols
utilizzando un groupby
con il seguente codice:OLS Stampa riepilogo di regressione per file di testo
from pandas.stats.api import ols
df=pd.read_csv(r'F:\file.csv')
result=df.groupby(['FID']).apply(lambda d: ols(y=d.loc[:, 'MEAN'], x=d.loc[:, ['Accum_Prcp', 'Accum_HDD']]))
for i in result:
x=pd.DataFrame({'FID':i.index, 'delete':i.values})
frame = pd.concat([x,DataFrame(x['delete'].tolist())], axis=1, join='outer')
del frame['delete']
print frame
ma questo restituisce l'errore:
AttributeError: 'OLS' object has no attribute 'index'
Ho circa 2.000 articoli nel mio gruppo da e quando stampo ognuno di essi assomigliano a qualcosa del genere:
-
------------------------Summary of Regression Analysis-------------------------
Formula: Y ~ <Accum_Prcp> + <Accum_HDD> + <intercept>
Number of Observations: 79
Number of Degrees of Freedom: 3
R-squared: 0.1242
Adj R-squared: 0.1012
Rmse: 0.1929
F-stat (2, 76): 5.3890, p-value: 0.0065
Degrees of Freedom: model 2, resid 76
-----------------------Summary of Estimated Coefficients------------------------
Variable Coef Std Err t-stat p-value CI 2.5% CI 97.5%
--------------------------------------------------------------------------------
Accum_Prcp 0.0009 0.0003 3.28 0.0016 0.0004 0.0015
Accum_HDD 0.0000 0.0000 1.98 0.0516 0.0000 0.0000
intercept 0.4750 0.0811 5.86 0.0000 0.3161 0.6340
---------------------------------End of Summary---------------------------------
Desidero essere in grado di esportare ciascuno in un CSV in modo che sia possibile visualizzarli singolarmente.
Credo che il 'ols.summary()' in realtà è uscita come testo, non come 'DataFrame'. In genere ho fatto ricorso alla stampa su uno o più file di testo per l'archiviazione. – Stefan
quando provo qualcosa come: 'for i in result: i.to_csv (os.path.join (outpath, i + '. Csv')' restituisce 'AttributeError: 'OLS' l'oggetto non ha attributo 'to_csv'' –
Quale routine 'OLS' stai usando?' Statsmodels'? – Stefan