binomial

Binomial Distribution

A binomial distribution class, derived from a Udacity exercise template.

final class boring_math.probability_distributions.distributions.binomial.Binomial

Bases: DiscreteDist

Class for visualizing Binomial distributed data.

A Binomial distribution represents the number of events with probability p happening in n numbers of trials.

Attributes (some inherited):

  • mean (float) representing the mean value of the distribution

  • stdev (float) representing the standard deviation of the distribution

  • data extracted from a data file (taken to be a population)

  • p (float) representing the probability of an event occurring

  • n (int) the total number of trials

__init__(p: float = 0.5, n: int = 20)
pdf(kf: float) float

Binomial probability distribution function.

cdf(kf: float) float

Binomial cumulative probability distribution function.

calculate_mean() float

Calculate the mean from p and n

calculate_stdev() float

Calculate the standard deviation using p and n

replace_stats_from_dataset(dset: DataSet) tuple[float, int]

Function to calculate p and n from a data set.

Where the read in data set is taken as the population.

plot_bar_data() None

Produce a bar-graph of the data using the matplotlib pyplot library.

plot_pdf_bar_graph(show: bool = True, lower_cap: int | None = None, upper_cap: int | None = None) tuple[list[int], list[float]]

Function to plot the pdf of the binomial distribution.

Parameters:
  • show – If False suppress printing the bar graph, useful in pytest test suite.

  • lower_cap – Put a lower cap on the values printed.

  • upper_cap – Put an upper cap on the values printed.

Returns:

A tuple[list[int], list[float]] where list[int] are the x values used for the bar graph and list[float] are the corresponding probabilities for each x.

__add__(other: Self) Self

Add together two Binomial distributions with equal p.

__repr__() str

Return repr(self).

__str__() str

Return str(self).