logo

stdev()-Methode im Python-Statistikmodul

Das Statistikmodul in Python bietet eine Funktion namens stdev() , mit dem sich die Standardabweichung berechnen lässt. Die Funktion stdev() berechnet die Standardabweichung nur aus einer Datenstichprobe und nicht aus einer gesamten Population.

Um die Standardabweichung einer gesamten Grundgesamtheit zu berechnen, wird eine andere Funktion namens verwendet pstdev() wird eingesetzt.



Standardabweichung ist ein Maß für die Ausbreitung in der Statistik. Es wird verwendet, um das Maß der Ausbreitung und Variation einer Reihe von Datenwerten zu quantifizieren. Es ist der Varianz sehr ähnlich und gibt das Maß für die Abweichung an, während die Varianz den quadrierten Wert liefert.
Ein niedriges Maß für die Standardabweichung zeigt an, dass die Daten weniger weit auseinanderliegen, wohingegen ein hoher Wert für die Standardabweichung darauf hinweist, dass die Daten in einem Satz von ihren mittleren Durchschnittswerten weit auseinander liegen. Eine nützliche Eigenschaft der Standardabweichung besteht darin, dass sie im Gegensatz zur Varianz in denselben Einheiten wie die Daten ausgedrückt wird.

Standard Deviation is calculated by : where x1, x2, x3.....xn are observed values in sample data, is the mean value of observations andN is the number of sample observations.>

Syntax : stdev( [Datensatz], xbar )
Parameter:
[Daten] : Eine Iteration mit reellwertigen Zahlen.
xbar (Optional) : Nimmt den tatsächlichen Mittelwert des Datensatzes als Wert.
Rückgabetyp: Gibt die tatsächliche Standardabweichung der als Parameter übergebenen Werte zurück.
Ausnahmen:
Statistikfehler wird für einen Datensatz ausgelöst, der weniger als 2 Werte als Parameter übergeben hat.
Unmögliche/präzisionslose Werte wenn der Wert als bereitgestellt wird xbar stimmt nicht mit dem tatsächlichen Mittelwert des Datensatzes überein.

Code Nr. 1:



Python3

# Python code to demonstrate stdev() function> # importing Statistics module> import> statistics> # creating a simple data - set> sample>=> [>1>,>2>,>3>,>4>,>5>]> # Prints standard deviation> # xbar is set to default value of 1> print>(>'Standard Deviation of sample is % s '> >%> (statistics.stdev(sample)))>
>
>

Ausgabe :

Standard Deviation of the sample is 1.5811388300841898>

Code Nr. 2: Demonstrieren Sie stdev() für einen unterschiedlichen Satz von Datentypen

Python3

# Python code to demonstrate stdev()> # function on various range of datasets> # importing the statistics module> from> statistics>import> stdev> # importing fractions as parameter values> from> fractions>import> Fraction as fr> # creating a varying range of sample sets> # numbers are spread apart but not very much> sample1>=> (>1>,>2>,>5>,>4>,>8>,>9>,>12>)> # tuple of a set of negative integers> sample2>=> (>->2>,>->4>,>->3>,>->1>,>->5>,>->6>)> # tuple of a set of positive and negative numbers> # data-points are spread apart considerably> sample3>=> (>->9>,>->1>,>->0>,>2>,>1>,>3>,>4>,>19>)> # tuple of a set of floating point values> sample4>=> (>1.23>,>1.45>,>2.1>,>2.2>,>1.9>)> # Print the standard deviation of> # following sample sets of observations> print>(>'The Standard Deviation of Sample1 is % s'> >%>(stdev(sample1)))> > print>(>'The Standard Deviation of Sample2 is % s'> >%>(stdev(sample2)))> > print>(>'The Standard Deviation of Sample3 is % s'> >%>(stdev(sample3)))> > > print>(>'The Standard Deviation of Sample4 is % s'> >%>(stdev(sample4)))>
>
>

Ausgabe :



The Standard Deviation of Sample1 is 3.9761191895520196 The Standard Deviation of Sample2 is 1.8708286933869707 The Standard Deviation of Sample3 is 7.8182478855559445 The Standard Deviation of Sample4 is 0.41967844833872525>

Code Nr. 3: Demonstrieren Sie den Unterschied zwischen den Ergebnissen von variance() und stdev()

Python3

# Python code to demonstrate difference> # in results of stdev() and variance()> # importing Statistics module> import> statistics> # creating a simple data-set> sample>=> [>1>,>2>,>3>,>4>,>5>]> # Printing standard deviation> # xbar is set to default value of 1> print>(>'Standard Deviation of the sample is % s '> >%>(statistics.stdev(sample)))> # variance is approximately the> # squared result of what stdev is> print>(>'Variance of the sample is % s'> >%>(statistics.variance(sample)))>
>
>

Ausgabe :

Standard Deviation of the sample is 1.5811388300841898 Variance of the sample is 2.5>

Code Nr. 4: Demonstrieren Sie die Verwendung von xbar Parameter

Python3

# Python code to demonstrate use of xbar> # parameter while using stdev() function> # Importing statistics module> import> statistics> # creating a sample list> sample>=> (>1>,>1.3>,>1.2>,>1.9>,>2.5>,>2.2>)> # calculating the mean of sample set> m>=> statistics.mean(sample)> # xbar is nothing but stores> # the mean of the sample set> # calculating the variance of sample set> print>(>'Standard Deviation of Sample set is % s'> >%>(statistics.stdev(sample, xbar>=> m)))>
>
>

Ausgabe :

Standard Deviation of Sample set is 0.6047037842337906>

Code Nr. 5: Demonstriert StatisticsError

Python3

# Python code to demonstrate StatisticsError> # importing the statistics module> import> statistics> # creating a data-set with one element> sample>=> [>1>]> # will raise StatisticsError> print>(statistics.stdev(sample))>
>
>

Ausgabe :

Traceback (most recent call last): File '/home/f921f9269b061f1cc4e5fc74abf6ce10.py', line 12, in print(statistics.stdev(sample)) File '/usr/lib/python3.5/statistics.py', line 617, in stdev var = variance(data, xbar) File '/usr/lib/python3.5/statistics.py', line 555, in variance raise StatisticsError('variance requires at least two data points') statistics.StatisticsError: variance requires at least two data points>

Anwendungen:

  • Die Standardabweichung ist im Bereich der statistischen Mathematik und statistischen Studien äußerst wichtig. Es wird häufig verwendet, um die Zuverlässigkeit statistischer Berechnungen zu messen. Beispielsweise wird die Fehlerquote bei der Berechnung der Noten einer Prüfung durch die Berechnung der erwarteten Standardabweichung der Ergebnisse bestimmt, wenn dieselbe Prüfung mehrmals durchgeführt würde.
  • Es ist im Bereich der Finanzstudien sehr nützlich und hilft bei der Bestimmung der Gewinn- und Verlustspanne. Wichtig ist auch die Standardabweichung, wobei die Standardabweichung der Rendite einer Anlage ein Maß für die Volatilität der Anlage ist.