SVC gamma value of 'auto' crashes when export_data=True
lichard49 opened this issue · comments
For SVC's, the default value of gamma is 'auto' which causes porter to crash when using exporting data is true.
>>> output = porter.export(export_data=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/sklearn_porter/Porter.py", line 189, in export method_name=method_name, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/sklearn_porter/estimator/classifier/SVC/__init__.py", line 192, in export
export_append_checksum)
File "/usr/local/lib/python2.7/dist-packages/sklearn_porter/estimator/classifier/SVC/__init__.py", line 239, in export_data
'gamma': float(self.gamma),
ValueError: could not convert string to float: auto
The solution is to check if it's equal to 'auto'; if so, then set gamma equal to 1/n_features, such as:
>>> clf.gamma
'auto'
>>> clf.gamma = 1/float(clf.support_vectors_.shape[1])
>>> output = porter.export(export_data=True) # success
Hello @lichard49 ,
thanks for the hint. It's fixed with the last commit (972d498) on the master branch and added to the next release branch 0.7.0
. For now you can use the following commands to install the fixed version:
$ pip uninstall -y sklearn-porter
$ pip install --no-cache-dir https://github.com/nok/sklearn-porter/zipball/master