-1

I am learning data mining and have difficulty understanding below code. Could anyone explain it to me? Thank you very much.

  1. What are the uses of the three % signs? How to understand % (stat, p)?

  2. How to understand the syntax stat, p = mannwhitneyu(data1, data2)? This is the first time I ask a question here. If I am not following the conventions or rules, please let me know. Thanks.

    from scipy.stats import mannwhitneyu

    data1 = [23, 45, 78, 56, 48] data2 = [90, 43, 28, 79, 69] data3 = [87, 56, 29, 52, 39]

    compare samples

    stat, p = mannwhitneyu(data1, data2) print('Statistics = %.3f, p = %.3f' % (stat, p))

    interpret

    alpha = 0.05 if p > alpha: print('Same distribution (fail to reject H0)') else: print('Different distribution (reject H0)')

sagum
  • 21
  • 2
  • 1
    This isn't related to statistics or data mining, it is one of Python's string formatting: https://stackoverflow.com/a/3395177/2745495 – Gino Mempin Aug 30 '22 at 22:55
  • Does this answer your question? [Using multiple arguments for string formatting in Python (e.g., '%s ... %s')](https://stackoverflow.com/questions/3395138/using-multiple-arguments-for-string-formatting-in-python-e-g-s-s) – Gino Mempin Aug 30 '22 at 22:56
  • "*This is the first time I ask a question here. If I am not following the conventions or rules, please let me know.*" Welcome. Please have only 1 question per post, otherwise your question can be closed as "needs more focused". You currently have 2 here, 1 about string formatting and 1 about unpacking iterables. You should be asking separate, unrelated questions in separate posts. – Gino Mempin Aug 30 '22 at 23:00
  • Thank you for reminding me, Gino. I created another post for the second question. – sagum Aug 31 '22 at 06:35
  • Hi, Gino. I read the references you provided But I don't quite understand them. It's complicated for me as I don't know much about Python. Could you please explain to me briefly the usage of the % signs in my question? Thank you very much. – sagum Aug 31 '22 at 06:43
  • *"It's complicated for me as I don't know much about Python."* That's why you should learn programming with Python properly before doing any course/subject with Python. – dinhanhx Aug 31 '22 at 09:22

1 Answers1

0

Let simplify your question a bit.

s = 0.12345
p = 0.6789

Now to print them with %

print('s = %.3f; q = %.3f' % (s, p))

This prints out

s = 0.123; q = 0.679

As you can see, %.3f limits the number of decimal places of float variables (which are s and q) to 3.

I suggest you use f-string in the future.

dinhanhx
  • 198
  • 2
  • 13