Implementatie van Kansverdelingen in Python
Binomiale verdeling
De binomiale verdeling modelleert de kans op precies k successen in n onafhankelijke pogingen, waarbij elke poging een kans p op succes heeft.
123456789101112131415161718from scipy.stats import binom import matplotlib.pyplot as plt # number of trials n = 100 # probability of success p = 0.02 # number of successes k = 3 binom_prob = binom.pmf(k, n, p) # Vizualization x_vals = range(0, 15) y_vals = binom.pmf(x_vals, n, p) plt.bar(x_vals, y_vals, color='skyblue') plt.title(f'Binomial probability: {binom_prob:.4f}') plt.show()
n = 100
- er worden 100 staven getest;p = 0.02
- 2% kans dat een staaf defect is;k = 3
- kans op precies 3 defecte staven;binom.pmf()
berekent de probability mass function.
Uniforme verdeling
De uniforme verdeling modelleert een continue variabele waarbij alle waarden tussen $a$ en $b$ even waarschijnlijk zijn.
1234567891011121314151617from scipy.stats import uniform import matplotlib.pyplot as plt import numpy as np a = 49.5 b = 50.5 low, high = 49.8, 50.2 uniform_prob = uniform.cdf(high, a, b - a) - uniform.cdf(low, a, b - a) # Vizualization x = np.linspace(a, b, 100) pdf = uniform.pdf(x, a, b - a) plt.plot(x, pdf, color='black') plt.fill_between(x, pdf, where=(x >= low) & (x <= high), color='lightgreen', alpha=0.5) plt.title(f'Uniform probability: {uniform_prob:.1f}') plt.show()
a, b
- totale bereik van staaflengtes;low, high
- interval van interesse;- Het aftrekken van CDF-waarden geeft de kans binnen het interval.
Normale verdeling
De normale verdeling beschrijft waarden die zich groeperen rond een gemiddelde $\mu$ met spreiding gemeten door de standaardafwijking $\sigma$.
1234567891011121314151617181920import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm mu = 200 sigma = 5 lower, upper = 195, 205 norm_prob = norm.cdf(upper, mu, sigma) - norm.cdf(lower, mu, sigma) z1 = (lower - mu) / sigma z2 = (upper - mu) / sigma # Vizualization x = np.linspace(mu - 4*sigma, mu + 4*sigma, 200) pdf = norm.pdf(x, mu, sigma) plt.plot(x, pdf, color='black') plt.fill_between(x, pdf, where=(x >= lower) & (x <= upper), color='plum', alpha=0.5) plt.title(f'Normal probability: {norm_prob:.4f}\nZ-scores: {z1}, {z2}') plt.show()
mu
- gemiddelde staafgewicht;sigma
- standaardafwijking;- Kans - verschil in CDF;
- Z-scores tonen de afstand van de grenzen tot het gemiddelde.
Toepassing in de praktijk
- Binomiaal - hoe waarschijnlijk is een bepaald aantal defecte staven?
- Uniform - vallen de staaflengtes binnen de toleranties?
- Normaal - vallen de staafgewichten binnen de verwachte variabiliteit?
Door deze te combineren, richt kwaliteitscontrole zich op defecten, waarborgt precisie en behoudt productconsistentie.
Bedankt voor je feedback!
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Can you explain the main differences between the three distributions?
How do I choose which distribution to use for a specific problem?
Can you give more real-world examples for each distribution?
Awesome!
Completion rate improved to 1.96
Implementatie van Kansverdelingen in Python
Veeg om het menu te tonen
Binomiale verdeling
De binomiale verdeling modelleert de kans op precies k successen in n onafhankelijke pogingen, waarbij elke poging een kans p op succes heeft.
123456789101112131415161718from scipy.stats import binom import matplotlib.pyplot as plt # number of trials n = 100 # probability of success p = 0.02 # number of successes k = 3 binom_prob = binom.pmf(k, n, p) # Vizualization x_vals = range(0, 15) y_vals = binom.pmf(x_vals, n, p) plt.bar(x_vals, y_vals, color='skyblue') plt.title(f'Binomial probability: {binom_prob:.4f}') plt.show()
n = 100
- er worden 100 staven getest;p = 0.02
- 2% kans dat een staaf defect is;k = 3
- kans op precies 3 defecte staven;binom.pmf()
berekent de probability mass function.
Uniforme verdeling
De uniforme verdeling modelleert een continue variabele waarbij alle waarden tussen $a$ en $b$ even waarschijnlijk zijn.
1234567891011121314151617from scipy.stats import uniform import matplotlib.pyplot as plt import numpy as np a = 49.5 b = 50.5 low, high = 49.8, 50.2 uniform_prob = uniform.cdf(high, a, b - a) - uniform.cdf(low, a, b - a) # Vizualization x = np.linspace(a, b, 100) pdf = uniform.pdf(x, a, b - a) plt.plot(x, pdf, color='black') plt.fill_between(x, pdf, where=(x >= low) & (x <= high), color='lightgreen', alpha=0.5) plt.title(f'Uniform probability: {uniform_prob:.1f}') plt.show()
a, b
- totale bereik van staaflengtes;low, high
- interval van interesse;- Het aftrekken van CDF-waarden geeft de kans binnen het interval.
Normale verdeling
De normale verdeling beschrijft waarden die zich groeperen rond een gemiddelde $\mu$ met spreiding gemeten door de standaardafwijking $\sigma$.
1234567891011121314151617181920import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm mu = 200 sigma = 5 lower, upper = 195, 205 norm_prob = norm.cdf(upper, mu, sigma) - norm.cdf(lower, mu, sigma) z1 = (lower - mu) / sigma z2 = (upper - mu) / sigma # Vizualization x = np.linspace(mu - 4*sigma, mu + 4*sigma, 200) pdf = norm.pdf(x, mu, sigma) plt.plot(x, pdf, color='black') plt.fill_between(x, pdf, where=(x >= lower) & (x <= upper), color='plum', alpha=0.5) plt.title(f'Normal probability: {norm_prob:.4f}\nZ-scores: {z1}, {z2}') plt.show()
mu
- gemiddelde staafgewicht;sigma
- standaardafwijking;- Kans - verschil in CDF;
- Z-scores tonen de afstand van de grenzen tot het gemiddelde.
Toepassing in de praktijk
- Binomiaal - hoe waarschijnlijk is een bepaald aantal defecte staven?
- Uniform - vallen de staaflengtes binnen de toleranties?
- Normaal - vallen de staafgewichten binnen de verwachte variabiliteit?
Door deze te combineren, richt kwaliteitscontrole zich op defecten, waarborgt precisie en behoudt productconsistentie.
Bedankt voor je feedback!