How to get the value from a list based on highest probability?

how to find probability in matlab
machine learning predict probability
generate random number with probability - matlab
brier score
probability matlab examples
randsample
probability score logistic regression
numpy random choice

I have a list A = [1,2,3,4,5,6,7,8,9,10] and a list B which gives the probability of list A i.e. B = [0.1,0.2,0.3,0.4,0.15,0.6,0.22,0.4,0.3,0.32]

I need to choose a value from A based on the highest probability of B. Here it is obvious that the highest value in B is 0.6 so I need to choose the number 6 from list A. How an I write the code in python?

If you can use numpy:

import numpy as np
print(A[np.argmax(B)])

np.argmax returns the index of the max element. And we can simply use that index to access A's element.

Statistical Methods for Spoken Dialogue Management, 0 The marginal probability that the “method” node value is “byname”, denoted This represents the probability that the user wants a list of alternative venues. o have a high probability of not matching the user's constraints have the highest  If your value list is Text instead of numbers or is not numbered in sequence with the data, you can add the INDEX function to the formula to randomly lookup the text value based on its probability. Lookup Text Value Using Index Function. The INDEX function returns a value based on the ROW and COLUMN the user specifies – Example: “=Index(1,1

How about this:

print(max(zip(B,A))[1])

Actually @Dim78 suggested and measured that creating the tuples (zip() does that) is more costly than searching twice (once for the maximum and once for its position). I double-checked that and agree. The effect also doesn't go away for larger lists or when switching to another Python version.

Of course searching for the found maximum can be costly in case comparison of the values is very costly (for plain numbers it isn't), so in general this version is inferior.

But for the special case we have here, double searching actually is faster (in all cases I tried out):

python3 -c 'import timeit; print(timeit.timeit("a[b.index(max(b))]", setup="import numpy as np; a=list(np.random.rand(1000000)); b=list(np.random.rand(1000000))", number=100))'
4.586365897208452

python3 -c 'import timeit; print(timeit.timeit("max(zip(b,a))[1]", setup="import numpy as np; a=list(np.random.rand(1000000)); b=list(np.random.rand(1000000))", number=100))'
6.770604271441698

Web Information Systems and Technologies: 6th International , Our developed algorithm (called probability-based extended profile filtering) is generate a top-N recommendation list with a corresponding confidence value  A slow but simple way to do it is to have every member to pick a random number based on its probability and pick the one with highest value. Analogy: Imagine 1 of 3 people needs to be chosen but they have different probabilities. You give them die with different amount of faces. First person's dice has 4 face, 2nd person's 6, and the third person's 8.

A = [1,2,3,4,5,6,7,8,9,10]
B = [0.1,0.2,0.3,0.4,0.15,0.6,0.22,0.4,0.3,0.32]
>>> A[max(enumerate(B), key=lambda x:x[1])[0]]
6

As suggested by @bro-grammer, a zip version:

>>> max(zip(A,B), key=lambda x:x[1])
6

Security in Communication Networks: Third International , For each pair of fundamental differences (ΔA, ΔB), make the list {ΔC} of output differences such Calculate the differential probability for each triplet of differences and store the value. Based on the list made in the third prosess, examine inductively whether or not a Output the characteristic with the highest probability. 3. Question: 1.The Highest Possible Probability Is? A. None Of These. B. Can Be Any Positive Value. C. Is Equal To 1.0 D. Is Equal To 0.0 E. Any Value Between 0 To 1. 2. If An Experiment Can Be Described As A Sequence Of 4 Steps With 3 Possible Outcomes On The First Step, Possible Outcomes On The Second Step, 3 Possible Outcomes On The Third Step, And 4 Possible

An option with a dictionary (maybe you can use this dictionary later):

d = dict(zip(A, B)) # {1: 0.1, 2: 0.2, 3: 0.3, 4: 0.4, 5: 0.15, 6: 0.6, 7: 0.22, 8: 0.4, 9: 0.3}
m = max(d, key=lambda x: d[x]) # 6

Probability of choosing a random pair with maximum sum in an array , Given an array of N integers, You have to find the probability of choosing a i < j to get the maximum value possible and then again do a brute force to calculate  *Values in the lookup range must be sorted in ascending order. Random weighted text value. To return a random weighted text value (i.e. a non-numeric value), you can enter text values in the range B5:B10, then add INDEX to return a value in that range, based on the position returned by MATCH: =

Try this

maxA=A[B.index(max(B))]

Also you could try method argmax from NumPy lib.

How to pick a value according to its probability, where P(n) is the probability to select the X(n) element. I wish to make a function that select a "random" element of X according to its probability, like. f = myfun(P  Multiply each value times its respective probability. Each possible outcome represents a portion of the total expected value for the problem or experiment that you are calculating. To find the partial value due to each outcome, multiply the value of the outcome times its probability.

Python Weighted random choices from the list with Probability, Choose elements from the list randomly with a different probability. There are 2 ways to make weighted random choices in Python output, we got 555 three times because we specified the highest weight for it. Given a range of integers, we want to generate five random numbers based on the weight. Generate a number between 0 and 1. Walk the list substracting the probability of each item from your number. Pick the item that, after substraction, took your number down to 0 or below. That's simple, O (n) and should work :)

A Gentle Introduction to Probability Scoring Methods in Python, Discover bayes opimization, naive bayes, maximum likelihood, distributions, cross entropy, is calculated that penalizes the probability based on the distance from the expected value. We can make a single log loss score concrete with an example. loss for predicting different fixed probability values. The expected value can really be thought of as the mean of a random variable. This means that if you ran a probability experiment over and over, keeping track of the results, the expected value is the average of all the values obtained. The expected value is what you should anticipate happening in the long run of many trials of a game of chance.

Numerical & Scientific Computing with Python: Weighted Choice , Just like with the loaded die, we have again the need of a weighted choice. of times, for example 10,000 times, we get roughly the probability values of the weights: We will base our first exercise on the popularity of programming language as import numpy as np def cartesian_choice(*iterables): """ A list with random  This sums to 1.35, as a result the 11-15 selection will have a 0% odd (never get reached), and the 9-11 selection has a 20% odd despite being flagged as 30%. In a weights system. The probability is based on the relative weights of the entries included. This means adding new entries keeps the same relative odds to one another no matter what.

Comments
  • Welcome to StackOverflow! Here you can ① post your code (as a minimal reproducible example), ② describe what you observe it does (with which input), and ③ describe what you expect to observe instead. This results in a clear question which can be answered. Please take the tour and read the How-To-Ask to learn more about this.
  • How should ties (joint highest values) be handled?
  • It's a unique way to do it. But wouldn't it first iterate over the entire list, to create tuples out of them, and them iterate over the zip again to find max?
  • The zip() creates an iterator (in Python3; in Python2 consider using izip() or switching to Python3) creating tuples, and the max() will consume these tuples linearly. I'd be interested in a version which works without building tuples but I don't think it's possible without searching twice.
  • That would search for the max, then search for it again to find its index. That's not optimal.
  • See my post's edit: You are right, searching twice is faster than building the tuples. I did a non-edit to be able to revoke my downvote :)