My perceptron was very slow until I read a Stack Overflow comment that led me to a post comparing the speeds of different ways of accessing a dataframe by rows.
If you are using df.loc[rownum]
, your code is slow. The fast way to
get rows is to zip the columns together and get the info from that
list/array. It’s not just a little fast, it’s like 100x faster.
Code snippet:
#outside of beta updating function
xyc = list(zip(df.x, df.y, df.c))
#inside beta updating function
for (x1,x2,c) in xyc:
...