0

Still beginning my journey using Python so this is a simple question that I don't understand.

Trying to use Ziggy's definition statement of Cramer's V statistic from here: Using pandas, calculate Cramér's coefficient matrix

but when I put it into Python the definition doesn't end at the return:

>>> import pandas as pd
>>> def cramers_corrected_stat(confusion_matrix):
...     # calculate Cramers V statistic for categorial-categorial association.
...     # uses correction from Bergsma and Wicher,
...     # Journal of the Korean Statistical Society 42 (2013): 323-328
...
...     chi2 = ss.chi2_contingency(confusion_matrix)[0]
...     n = confusion_matrix.sum()
...     phi2 = chi2/n
...     r,k = confusion_matrix.shape
...     phi2corr = max(0, phi2 - ((k-1)*(r-1))/(n-1))
...     rcorr = r - ((r-1)**2)/(n-1)
...     kcorr = k - ((k-1)**2)/(n-1)
...     return np.sqrt(phi2corr / min( (kcorr-1), (rcorr-1)))
...

What am I not seeing?

DrPaulVella
  • 391
  • 8
  • 22
  • 4
    Hit Enter again. – user2357112 Sep 15 '20 at 01:35
  • If you're writing large functions it's probably easier to just write a script. – ggorlen Sep 15 '20 at 01:36
  • 2
    (In a normal interactive environment, Python would have stopped after the first blank line and thrown a SyntaxError. Either you've inadvertently altered the transcript you're showing us, or you're using some other weird environment.) – user2357112 Sep 15 '20 at 01:39

1 Answers1

0

When you're in REPL, you need two consecutive blank lines to finish the statement. However writing code in REPL is quite cumbersome, as you can't easily edit/fix previously written code, so I'd suggest you to save anything you do into .py file, where you can edit the code more easily and then run the code via python ./myfile.py.

yedpodtrzitko
  • 9,035
  • 2
  • 40
  • 42