anfederico / clairvoyant

Software designed to identify and monitor social/historical cues for short term stock movement
MIT License
2.42k stars 772 forks source link

TypeError: a float is required: "self.svc.fit(self.scaler.transform(self.XX), self.yy)" #26

Closed tianwen2976 closed 6 years ago

tianwen2976 commented 6 years ago

I am trying to run the example from your instructions. data comes from example/data.csv

I am getting the error:

Traceback (most recent call last): File "test.py", line 22, in backtest.start(data, kernel='rbf', C=1, gamma=10) File "/home/machol/virtualenv/local/lib/python2.7/site-packages/clairvoyant/engine.py", line 197, in start Engine.start(self, data, **kwargs) File "/home/machol/virtualenv/local/lib/python2.7/site-packages/clairvoyant/engine.py", line 60, in start self.model.fit(X, y) File "/home/machol/virtualenv/local/lib/python2.7/site-packages/clairvoyant/engine.py", line 22, in fit self.svc.fit(self.scaler.transform(self.XX), self.yy) File "/home/machol/virtualenv/local/lib/python2.7/site-packages/sklearn/svm/base.py", line 187, in fit fit(X, y, sample_weight, solver_type, kernel, random_seed=seed) File "/home/machol/virtualenv/local/lib/python2.7/site-packages/sklearn/svm/base.py", line 254, in _dense_fit max_iter=self.max_iter, random_seed=random_seed) File "sklearn/svm/libsvm.pyx", line 59, in sklearn.svm.libsvm.fit TypeError: a float is required

My python version is 2.7.9。

anfederico commented 6 years ago

Seems like the package is starting to lose compatibility with Python 2.7, especially for those with newer versions of pandas, numpy, matplotlib installed. Can you try in Python 3?

tianwen2976 commented 6 years ago

Ok, I am trying with python 3.

tianwen2976 commented 6 years ago

I use Python 3.4 and I still get the same error.

Traceback (most recent call last):
  File "test.py", line 22, in <module>
    backtest.start(data, kernel='rbf', C=1, gamma=10)
  File "/home/machol/virtualenv3/lib/python3.4/site-packages/clairvoyant/engine.py", line 197, in start
    Engine.start(self, data, **kwargs)
  File "/home/machol/virtualenv3/lib/python3.4/site-packages/clairvoyant/engine.py", line 60, in start
    self.model.fit(X, y)
  File "/home/machol/virtualenv3/lib/python3.4/site-packages/clairvoyant/engine.py", line 22, in fit
    self.svc.fit(self.scaler.transform(self.XX), self.yy)
  File "/home/machol/virtualenv3/lib/python3.4/site-packages/sklearn/svm/base.py", line 187, in fit
    fit(X, y, sample_weight, solver_type, kernel, random_seed=seed)
  File "/home/machol/virtualenv3/lib/python3.4/site-packages/sklearn/svm/base.py", line 254, in _dense_fit
    max_iter=self.max_iter, random_seed=random_seed)
  File "sklearn/svm/libsvm.pyx", line 59, in sklearn.svm.libsvm.fit
TypeError: a float is required

Below is the installed library:

Package         Version
--------------- -------
backports-abc   0.5    
bokeh           0.13.0 
clairvoyant     1.0    
cycler          0.10.0 
Jinja2          2.10   
kiwisolver      1.0.1  
MarkupSafe      1.0    
matplotlib      2.2.3  
numpy           1.15.1 
packaging       17.1   
pandas          0.23.4 
pip             18.0   
pyparsing       2.2.0  
python-dateutil 2.7.3  
pytz            2018.5 
PyYAML          3.13   
scikit-learn    0.19.2 
scipy           1.1.0  
setuptools      5.5.1  
six             1.11.0 
tornado         5.1    
tianwen2976 commented 6 years ago

@anfederico I think the position of **kwargs should be put to the end.

self.svc = SVC(**kwargs, probability=True) =>
self.svc = SVC(probability=True, **kwargs) 

After modifying, the program runs successfully.

anfederico commented 6 years ago

Whoops, you're right, it should be at the end.