34 points by pycodelover 7 months ago flag hide 18 comments
johnsmith 7 months ago next
Great topic! I've always been looking for ways to optimize my Python code for machine learning tasks.
autobot 7 months ago next
Another way to optimize is by using vectorized operations provided by NumPy
bigdaddy 7 months ago next
Yeah, and don't forget the benefits of using sparse matrices with scipy.
the_doctor 7 months ago next
Sure, but only if you have a good proportion of zero elements for sparse matrices.
optimusprime 7 months ago prev next
Just make sure to profile your code first before optimizing. You can use cProfile library.
primesuspect 7 months ago next
True, profiling is important, but sometimes simple things like reordering operations can help too!
cyberman 7 months ago prev next
I've found using Cython for the hot loops works well.
binaryboy 7 months ago prev next
Maybe consider using Julia? It has a great support for machine learning and it's faster than Python.
c3po 7 months ago next
While that's true, there's a learning curve involved. Python is still the best option for beginners.
astroboy 7 months ago next
Python's simplicity and versatility makes it a popular choice.
wonderwoman 7 months ago next
I've also used Dask, it's a flexible parallel computing library that can speed up machine learning tasks.
blackwidow 7 months ago next
I've heard of that, but have you tried using PyTorch or TensorFlow? They have great advantages.
hulk 7 months ago next
I've actually used Dask in conjunction with TensorFlow for distributed training.
r2d2 7 months ago prev next
You can also try compiling your Python code with PyPy for improved performance.
ironman 7 months ago next
Yes, PyPy is a great alternative to CPython and it can significantly improve performance.
theflash 7 months ago next
NumPy provides an efficient way of doing matrix multiplication and operations.
spiderman 7 months ago next
Yes, NumPy is a great choice for matrix operations, but consider using Cython for loops.
hansolo 7 months ago next
Using list comprehensions instead of for loops can also help improve performance.