How do I make z score algorithms work? Where am I going wrong?

Question:

I have been having some trouble with my code, about how to use the Kaggle database to find the popularity of data, and analyze it using Z-score algorithms. I have tried a lot, but can never seem to get my code to work. Here is the link to the data: https://docs.google.com/spreadsheets/d/1HIAzQta-dSfoovkdPeqKcBxANhaO9VR_TiNFwnUKFcU/edit?usp=sharing

And here is my code

for header in data.columns:

  # average
  sum = 0
  n = 0
  crab = 0
  for i in data[header]:
    sum += ele
    n += 1
    average = sum / n
    # standard Deviation


  for j in data[header]:
      crab = np.std(crab)

  for k in data[header]:
    k = (k - average) / crab
    print("k = ",k)
    break


print(data.shape) 
data.info()
data.hist(figsize=(14, 14))
%config InlineBackend.print_figure_kwargs={'facecolor' : "w"} 

k is apparently = to – inf? and im really confused

Asked By: Mark Jacobs

||

Answers:

You have written:

crab = 0
# ...
# ...
crab = np.std(crab)
# ...
# ...
k = (k - average) / crab # You are dividing by zero

Hence the infinty in the output

Answered By: Mouse
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.