Questions tagged [probability]

Consider if your question would be better at stats.stackexchange.com. Probability touches upon uncertainty, random phenomena, random numbers, random variables, probability distributions, sampling, combinatorics.

See also https://statistics.stackexchange.com

Probability theory is a branch of mathematics that studies uncertainty and random phenomena. It operates by introducing a sample space (a set), and associating probabilities (numbers between 0 and 1, inclusive) to certain subsets of this set, in a manner that satisfies some sensible axioms. If the sample space can be thought of as the real line, we obtain random variables; if it is a Euclidean space, we obtain random vectors. Random variables and random vectors have associated probability distributions, which can be characterized by probability density functions, cumulative density functions, moments, characteristic or moment generating functions.

Typically, questions with this tag will deal with computing (exactly or approximately) probabilities of certain events (from winning a lottery to server outages), drawing random samples, approximating distributions, etc. There might be an overlap with statistics and/or statistical packages (R, SAS, Stata).

Synonym: probability-theory

4021 questions
67
votes
12 answers

Random number with Probabilities

I am wondering what would be the best way (e.g. in Java) to generate random numbers within a particular range where each number has a certain probability to occur or not? e.g. Generate random integers from within [1;3] with the following…
marc wellman
  • 5,808
  • 5
  • 32
  • 59
62
votes
11 answers

Normalizing a list of numbers in Python

I need to normalize a list of values to fit in a probability distribution, i.e. between 0.0 and 1.0. I understand how to normalize, but was curious if Python had a function to automate this. I'd like to go from: raw = [0.07, 0.14, 0.07] to …
Adam_G
  • 7,337
  • 20
  • 86
  • 148
57
votes
2 answers

Probability of collision when using a 32-bit hash

I have a 10-character string key field in a database. I've used CRC32 to hash this field, but I'm worrying about duplicates. Could somebody show me the probability of collision in this situation? P.S.: My string field is unique in the database. If…
nguyenngoc101
  • 1,211
  • 4
  • 16
  • 28
54
votes
7 answers

How to calculate mean, median, mode and range from a set of numbers

Are there any functions (as part of a math library) which will calculate mean, median, mode and range from a set of numbers.
user339108
  • 12,613
  • 33
  • 81
  • 112
44
votes
7 answers

Generate Random Boolean Probability

I only know how I can generate a random boolean value (true/false). The default probability is 50:50 But how can I generate a true false value with my own probability? Let's say it returns true with a probability of 40:60 or 20:80 etc...
Dark Side
  • 695
  • 2
  • 8
  • 18
43
votes
5 answers

Probability in Java

I was curious to know, how do I implement probability in Java? For example, if the chances of a variable showing is 1/25, then how would I implement that? Or any other probability? Please point me in the general direction.
Jeel Shah
  • 3,274
  • 17
  • 47
  • 68
41
votes
2 answers

scikit-learn return value of LogisticRegression.predict_proba

What exactly does the LogisticRegression.predict_proba function return? In my example I get a result like this: array([ [4.65761066e-03, 9.95342389e-01], [9.75851270e-01, 2.41487300e-02], [9.99983374e-01, 1.66258341e-05] ]) From other…
38
votes
10 answers

An interview question: About Probability

An interview question: Given a function f(x) that 1/4 times returns 0, 3/4 times returns 1. Write a function g(x) using f(x) that 1/2 times returns 0, 1/2 times returns 1. My implementation is: function g(x) = { if (f(x) == 0){ // 1/4 …
Sawyer
  • 15,581
  • 27
  • 88
  • 124
38
votes
6 answers

How can I make a random choice according to probabilities stored in a list (weighted random distribution)?

Given a list of probabilities like: P = [0.10, 0.25, 0.60, 0.05] (I can ensure that the sum of all the variables in P is always 1) How can I write a function that randomly returns a valid index, according to the values in the list? In other words,…
Roughmar
  • 305
  • 1
  • 5
  • 9
36
votes
7 answers

How do I simulate flip of biased coin?

In unbiased coin flip H or T occurs 50% of times. But I want to simulate coin which gives H with probability 'p' and T with probability '(1-p)'. something like this: def flip(p): '''this function return H with probability p''' # do something …
Pratik Deoghare
  • 35,497
  • 30
  • 100
  • 146
36
votes
4 answers

R: Calculate and interpret odds ratio in logistic regression

I am having trouble interpreting the results of a logistic regression. My outcome variable is Decision and is binary (0 or 1, not take or take a product, respectively). My predictor variable is Thoughts and is continuous, can be positive or…
Sudy Majd
  • 365
  • 1
  • 4
  • 7
34
votes
3 answers

How to get a classifier's confidence score for a prediction in sklearn?

I would like to get a confidence score of each of the predictions that it makes, showing on how sure the classifier is on its prediction that it is correct. I want something like this: How sure is the classifier on its prediction? Class 1: 81%…
user3377126
  • 2,091
  • 4
  • 32
  • 39
33
votes
7 answers

How do I programmatically calculate Poker Odds?

I'm trying to write a simple game/utility to calculate poker odds. I know there's plenty of resources that talk about the formulas to do so, but I guess I'm having trouble translating that to code. Particularly, I'm interested in Texas Hold-em…
Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
32
votes
6 answers

How do I assess the hash collision probability?

I'm developing a back-end application for a search system. The search system copies files to a temporary directory and gives them random names. Then it passes the temporary files' names to my application. My application must process each file within…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
32
votes
13 answers

How to incrementally sample without replacement?

Python has my_sample = random.sample(range(100), 10) to randomly sample without replacement from [0, 100). Suppose I have sampled n such numbers and now I want to sample one more without replacement (without including any of the previously sampled…
necromancer
  • 23,916
  • 22
  • 68
  • 115