Statistics and Linear Algebra 6

本文介绍了几种使用Python进行概率计算和数据分析的方法,包括获取数据集中特定最大或最小值的记录,计算某数值出现的概率,利用阶乘计算组合数,以及使用Scipy库简化概率计算过程。此外还讲解了如何计算概率分布的期望值及累积密度函数。

1. Two ways to get a column of another column with max/min values:

  a. most_bars_country = flags["name"][flags["bars"].idxmax()]

  b. bars_sorted = flags.sort_values("bars", ascending=[0])

    most_bars_country = bars_sorted["name"].iloc[0]

2. The way to get the probability of a certain value in a column:

  orange_probability = flags[flags["orange"]==1].shape[0]/flags.shape[0]

3. The way to calculate combination by using factorial: 

  import math
  def find_outcome_combinations(N, k): # Calculate the numerator of our formula.
    numerator = math.factorial(N) # Calculate the denominator.
    denominator = math.factorial(k) * math.factorial(N - k) # Divide them to get the final value.
    return numerator / denominator

4. The easier way to calculate the prabability of a number in a combination by using a library of scipy:

  import scipy
  from scipy import linspace
  from scipy.stats import binom

  outcome_counts = linspace(0,30,31) # Create a range of numbers from 0 to 30, with 31 elements (each number has one entry).
  dist = binom.pmf(outcome_counts,30,0.39) # The list of probability of the combination. 
  plt.bar(outcome_counts,dist)
  plt.show()

 

5. Sometimes we'll want to be able to tell people the expected value of a probability distribution -- the most likely result of a single sample that we look at.? To compute this, we just multiply N by p.

6. If we would like to calculate the probability of value k or less will occur, we can use cummulate density function:

  outcome_counts = linspace(0,30,31)

  dist = binom.cdf(outcome_counts,30,0.39) #To get cummulate density 

  plt.plot(outcome_counts,dist)

7.

转载于:https://www.cnblogs.com/kingoscar/p/6143510.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值