'Python java.lang.OutOfMemoryError: Java heap space

I am getting an java.lang.OutOfMemoryError: Java heap space when I am trying to perform UnderSampling of Binary Imbalanced Classes data.

pandas_df = dataset.toPandas()
---------------------------------------------------------------------------
Py4JJavaError                             Traceback (most recent call last)
<ipython-input-16-49508101123e> in <module>()
----> 1 pandas_df = dataset.toPandas()

4 frames
/usr/local/lib/python3.7/dist-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    326                 raise Py4JJavaError(
    327                     "An error occurred while calling {0}{1}{2}.\n".
--> 328                     format(target_id, ".", name), value)
    329             else:
    330                 raise Py4JError(

Py4JJavaError: An error occurred while calling o41.collectToPython.
: java.lang.OutOfMemoryError: Java heap space


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source