Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| from scipy.stats import binom | |
| # Streamlit App Title | |
| st.title("Binomial Distribution Visualizer 📊") | |
| # Sidebar controls | |
| N = st.slider("Number of trials (N)", min_value=1, max_value=100, value=10) | |
| p = st.slider("Probability of success (p)", min_value=0.01, max_value=1.0, value=0.5, step=0.01) | |
| # Compute binomial probabilities | |
| x = np.arange(0, N + 1) | |
| y = binom.pmf(x, N, p) | |
| # Plot | |
| fig, ax = plt.subplots() | |
| ax.bar(x, y, color="skyblue", edgecolor="black") | |
| ax.set_xlabel("Number of Successes") | |
| ax.set_ylabel("Probability Mass Function") | |
| ax.set_title(f"Binomial Distribution (N={N}, p={p})") | |
| # Show plot | |
| st.pyplot(fig) | |
| # Display Summary | |
| st.write(f"**Expected value (Mean)** = {N*p:.2f}") | |
| st.write(f"**Variance** = {N*p*(1-p):.2f}") | |