python - how can i predict my variables -


i made code works patsy , formula, wanted make 'predict' verify results found summary. how can predict variables?

import numpy np scipy import stats import scipy import matplotlib.pyplot plt import statsmodels.api sm  statsmodels.formula.api import logit, probit, poisson, ols  fname ="c:/users/lenovo/desktop/table.csv"  my_data = np.genfromtxt (fname, delimiter = ',')   x = my_data [:,1] d = my_data [:,4] f=my_data[:,6] c= my_data[:,3] #crée un masque pour les valeurs nans masque = ~ (np.isnan (x) | np.isnan (d) | np.isnan (f) | np.isnan (c))  x = my_data[masque, 1] - 1 d = my_data[masque, 4] f = my_data[masque, 6] c = my_data[masque, 3]  my_data_dict = dict ( x = x, d = d, f = f, c=c  )  form = 'x ~ c(c)+c(d)+c(f)'   affair_model = logit (form, my_data_dict, manquant = 'drop')  affair_result = affair_model.fit ()  print affair_result.summary ()  

in line:

data = df[cols_to_keep].join(dummy_ranks1.ix[:, 'c_2':]).join(dummy_ranks3.ix[:, 'd_2':]).join(dummy_ranks2.ix[:, 'f_2':]) 

you're selecting columns ['a', 'b'], joining other dataframes don't have x in them.

simply change

cols_to_keep = ['a', 'b'] 

to

cols_to_keep = ['a', 'b', 'x'] 

for one-off scripts this, it's not bad idea use sanity checks assert make sure it's doing expect, e.g.,

assert 'x' in data, 'x not column in data' 

since x has been added data you'll need change train_cols to

cols = data.columns train_cols = cols[cols != 'x'][1:] 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -