# Design choices of implementing an ensemble classifier

**URL:** <https://discuss.ray.io/t/design-choices-of-implementing-an-ensemble-classifier/4127>\
**Category:** Ray Core\
**Created:** [November 13, 2021, 5:15am UTC](https://discuss.ray.io/t/design-choices-of-implementing-an-ensemble-classifier/4127 "2021-11-13T05:15:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![xiaohan2012](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/xiaohan2012/32/1754_2.png) [@xiaohan2012](https://discuss.ray.io/u/xiaohan2012)\
**Post date:** [November 18, 2021, 7:58am UTC](https://discuss.ray.io/t/design-choices-of-implementing-an-ensemble-classifier/4127/2 "2021-11-18T07:58:48Z")

</div>

My final solution is this:

- instead of using actors, use normal Python classes and Ray functions
- each call of the Ray function creates a component classifier, fits it, and returns it
- subsequent use of the classifiers (e.g., making predictions) depend on using the returned component classifiers.

A working MWE is below:

```python
import ray
import time

class MyClass:
    def fit(self, value):
        time.sleep(1)
        print('done with fitting value {}'.format(value))
        return value

    def predict(self, value):
        time.sleep(1)
        print('done with prediction value {}'.format(value))
        return value

@ray.remote(num_cpus=2)
def _fit(value):
    obj = MyClass()
    obj.fit(value)
    return obj

ray.init(num_cpus=4) # we request 4 cpus

obj_ids = [_fit.remote(v) for v in range(4)]

@ray.remote
def _predict(obj, value):
    return obj.predict(value)

res_ids = [_predict.remote(obj, value) for obj, value in zip(obj_ids, range(len(obj_ids)))]

ray.get(res_ids)

ray.shutdown()

```

---

_[View the full topic](https://discuss.ray.io/t/design-choices-of-implementing-an-ensemble-classifier/4127)._
