Hi Timothy,
Thank you so much for sharing this wonderful package! I'm a freshman about this mixed logit model. I've run this Heating dataset in R successfully. When I run the above-mentioned example with Pylogit an error arose at In[14].
I downloaded the 'mlogit_Benchmark--Heating-checkpoint.ipynb' and run it in the Jupyter notebook of Anaconda3 for Python 3.5. And I just installed Pylogit two days ago by 'conda install -c timothyb0912 pylogit'. Here is the error information from Jupyter:
TypeError Traceback (most recent call last)
in ()
6 specification=model_1_spec,
7 model_type="MNL",
----> 8 names=model_1_names)
9
10 # Estimate the given model, starting from a point of all zeros
D:\Program Files\Anaconda3\lib\site-packages\pylogit\pylogit.py in create_choice_model(data, alt_id_col, obs_id_col, choice_col, specification, model_type, intercept_ref_pos, shape_ref_pos, names, intercept_names, shape_names, nest_spec, mixing_id_col, mixing_vars)
223 choice_col,
224 specification,
--> 225 **model_kwargs)
D:\Program Files\Anaconda3\lib\site-packages\pylogit\conditional_logit.py in init(self, data, alt_id_col, obs_id_col, choice_col, specification, names, *args, **kwargs)
296 specification,
297 names=names,
--> 298 model_type=model_type_to_display_name["MNL"])
299
300 # Store the utility transform function
D:\Program Files\Anaconda3\lib\site-packages\pylogit\base_multinomial_cm_v2.py in init(self, data, alt_id_col, obs_id_col, choice_col, specification, intercept_ref_pos, shape_ref_pos, names, intercept_names, shape_names, nest_spec, mixing_vars, mixing_id_col, model_type)
877 specification,
878 alt_id_col,
--> 879 names=names)
880
881 ##########
D:\Program Files\Anaconda3\lib\site-packages\pylogit\choice_tools.py in create_design_matrix(long_form, specification_dict, alt_id_col, names)
694 else: # the group is an integer
695 # Create the variable column
--> 696 new_col_vals = ((long_form[alt_id_col] == group).values *
697 long_form[variable].values)
698 independent_vars.append(new_col_vals)
D:\Program Files\Anaconda3\lib\site-packages\pandas\core\ops.py in wrapper(self, other, axis)
1281
1282 with np.errstate(all='ignore'):
-> 1283 res = na_op(values, other)
1284 if is_scalar(res):
1285 raise TypeError('Could not compare {typ} type with Series'
D:\Program Files\Anaconda3\lib\site-packages\pandas\core\ops.py in na_op(x, y)
1167 result = method(y)
1168 if result is NotImplemented:
-> 1169 raise TypeError("invalid type comparison")
1170 else:
1171 result = op(x, y)
TypeError: invalid type comparison
I also copied and pasted the code to Spyder in Anaconda3. It generated the same error.
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/Larry/Google Drive/CS/Programming_languages/Python/Python programs/exer_19_03_ML_mixlogit_Pylogit.py', wdir='C:/Users/Larry/Google Drive/CS/Programming_languages/Python/Python programs')
File "D:\Program Files\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 678, in runfile
execfile(filename, namespace)
File "D:\Program Files\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 106, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Larry/Google Drive/CS/Programming_languages/Python/Python programs/exer_19_03_ML_mixlogit_Pylogit.py", line 147, in
names=model_1_names)
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\pylogit.py", line 225, in create_choice_model
**model_kwargs)
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\conditional_logit.py", line 298, in init
model_type=model_type_to_display_name["MNL"])
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\base_multinomial_cm_v2.py", line 879, in init
names=names)
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\choice_tools.py", line 696, in create_design_matrix
new_col_vals = ((long_form[alt_id_col] == group).values *
File "D:\Program Files\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1283, in wrapper
res = na_op(values, other)
File "D:\Program Files\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1169, in na_op
raise TypeError("invalid type comparison")
TypeError: invalid type comparison
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/Larry/Google Drive/CS/Programming_languages/Python/Python programs/exer_19_03_ML_mixlogit_Pylogit.py', wdir='C:/Users/Larry/Google Drive/CS/Programming_languages/Python/Python programs')
File "D:\Program Files\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 678, in runfile
execfile(filename, namespace)
File "D:\Program Files\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 106, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/Larry/Google Drive/CS/Programming_languages/Python/Python programs/exer_19_03_ML_mixlogit_Pylogit.py", line 147, in
names=model_1_names)
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\pylogit.py", line 225, in create_choice_model
**model_kwargs)
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\conditional_logit.py", line 298, in init
model_type=model_type_to_display_name["MNL"])
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\base_multinomial_cm_v2.py", line 879, in init
names=names)
File "D:\Program Files\Anaconda3\lib\site-packages\pylogit\choice_tools.py", line 696, in create_design_matrix
new_col_vals = ((long_form[alt_id_col] == group).values *
File "D:\Program Files\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1283, in wrapper
res = na_op(values, other)
File "D:\Program Files\Anaconda3\lib\site-packages\pandas\core\ops.py", line 1169, in na_op
raise TypeError("invalid type comparison")
TypeError: invalid type comparison
Could you give me some ideas about how to fix it?
Thanks,
Larry