garydoranjr / misvm

Multiple-Instance Support Vector Machines
BSD 3-Clause "New" or "Revised" License
238 stars 81 forks source link

Example Code not Working #10

Closed aditsanghvi94 closed 5 years ago

aditsanghvi94 commented 7 years ago

I get this error when i try to run your example code for algorithm, classifier in classifiers.items(): classifier.fit(train_bags, train_labels)

`ValueError Traceback (most recent call last)

in () 26 accuracies = {} 27 for algorithm, classifier in classifiers.items(): ---> 28 classifier.fit(train_bags, train_labels) 29 predictions = classifier.predict(test_bags) 30 accuracies[algorithm] = np.average(test_labels == np.sign(predictions)) ~/misvm/src/misvm/misvm/misssvm.py in fit(self, bags, y) 55 bs.pos_instances, 56 bs.pos_instances, ---> 57 bs.neg_instances]) 58 self._y = np.vstack([np.matrix(np.ones((bs.X_p + bs.L_p, 1))), 59 -np.matrix(np.ones((bs.L_p + bs.L_n, 1)))]) ~/misvm/src/misvm/misvm/util.py in __getattr__(self, name) 59 return self.neg_bags 60 elif name == 'neg_instances': ---> 61 self.neg_instances = np.vstack(self.neg_bags) 62 return self.neg_instances 63 elif name == 'pos_instances': /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/numpy/core/shape_base.py in vstack(tup) 235 236 """ --> 237 return _nx.concatenate([atleast_2d(_m) for _m in tup], 0) 238 239 def hstack(tup): ValueError: need at least one array to concatenate ` This is problem with MissSVM on example code! When i try other classifiers , I get different errors, for example sbMIL 3 clf = misvm.sbMIL(kernel='linear', eta=0.1, C=1.0) ----> 4 clf.fit(train_bags, train_labels) 5 predictions = clf.predict(test_bags) 6 print (np.average(test_labels == np.sign(predictions))) ~/misvm/src/misvm/misvm/sbmil.py in fit(self, bags, y) 54 scale_C=self.scale_C, verbose=self.verbose, 55 sv_cutoff=self.sv_cutoff) ---> 56 initial_classifier.fit(bags, y) 57 if self.verbose: 58 print('Computing initial instance labels for sbMIL...') ~/misvm/src/misvm/misvm/smil.py in fit(self, bags, y) 49 if self.scale_C: 50 iC = float(self.C) / bs.L_n ---> 51 bC = float(self.C) / bs.X_p 52 else: 53 iC = self.C ZeroDivisionError: float division by zero SIL works as expected. However, for MISVM: `clf = misvm.MISVM(kernel='linear', C=1.0, max_iters=50) clf.fit(train_bags, [-1,1])` Gives me fitting and output. How does this work? There are 82 train bags and only 2 labels, why is there no "dimension mismatch" error as when i try this with SIL?
garydoranjr commented 7 years ago

Hi @aditsanghvi94, I think the problem is that the code still does not support Python 3. Some folks have begun implementing support for Python 3, but it's not fully finished yet.

I did just push a fix for an unrelated bug, so I suggest pulling the latest version of the repository and try using Python 2.6 or 2.7 if you can.