sciPy stats.scoreatpercentile() Funktion | Python
scipy.stats.scoreatpercentile(a, score, kind='rank')
Die Funktion hilft uns, die Punktzahl bei einem bestimmten Perzentil des Eingabearrays zu berechnen.
Die Punktzahl bei Perzentil = 50 ist der Median. Wenn das gewünschte Quantil zwischen zwei Datenpunkten liegt, interpolieren wir zwischen ihnen entsprechend dem Interpolationswert.
Parameter:
arr: [array_like] Eingabearray.
per: [array_like] Perzentil, bei dem wir die Punktzahl benötigen.
Grenze: [Tupel] die unteren und oberen Grenzen, innerhalb derer das Perzentil berechnet werden soll.
Achse: [int] Achse, entlang der wir die Punktzahl berechnen müssen.Ergebnisse: Punktzahl bei Perzentil relativ zum Array-Element.
Code # 1:
from
scipy
import
stats
import
numpy as np
arr
=
[
20
,
2
,
7
,
1
,
7
,
7
,
34
,
3
]
(
"arr : "
, arr)
(
"\nScore at 50th percentile : "
,
stats.scoreatpercentile(arr,
50
))
(
"\nScore at 90th percentile : "
,
stats.scoreatpercentile(arr,
90
))
(
"\nScore at 10th percentile : "
,
stats.scoreatpercentile(arr,
10
))
(
"\nScore at 100th percentile : "
,
stats.scoreatpercentile(arr,
100
))
(
"\nScore at 30th percentile : "
,
stats.scoreatpercentile(arr,
30
))
Ausgabe:
arr: [20, 2, 7, 1, 7, 7, 34, 3] Punktzahl beim 50. Perzentil: 7,0 Punktzahl beim 90. Perzentil: 24,2 Punktzahl beim 10. Perzentil: 1,7 Punktzahl beim 100. Perzentil: 34,0 Punktzahl beim 30. Perzentil: 3.4
Code # 2:
from
scipy
import
stats
import
numpy as np
arr
=
[[
14
,
17
,
12
,
33
,
44
],
[
15
,
6
,
27
,
8
,
19
],
[
23
,
2
,
54
,
1
,
4
, ]]
(
"arr : "
, arr)
(
"\nScore at 50th percentile : "
,
stats.scoreatpercentile(arr,
50
))
(
"\nScore at 50th percentile : "
,
stats.scoreatpercentile(arr,
50
, axis
=
1
))
(
"\nScore at 50th percentile : "
,
stats.scoreatpercentile(arr,
50
, axis
=
0
))
Ausgabe:
arr: [[14, 17, 12, 33, 44], [15, 6, 27, 8, 19], [23, 2, 54, 1, 4]] Punktzahl beim 50. Perzentil: 15,0 Punktzahl beim 50. Perzentil: [17. 15. 4.] Punktzahl beim 50. Perzentil: [15. 6. 27. 8. 19.]