Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hsy_rvalue = pd.Series([-7.40,
- -6.20,
- -5.00,
- -3.80,
- -2.60,
- -1.40,
- -0.20,
- 1.00,
- 2.20,
- 3.90,
- ])
- hsy_prob = pd.Series([0.20,
- 0.00,
- 0.00,
- 0.40,
- 2.39,
- 13.72,
- 46.52,
- 30.42,
- 5.37,
- 0.99,
- ])
- def expected_value(data_rvalue, data_prob):
- '''Данная функция находит математическое ожидание'''
- E = 0
- for x in range(len(data_rvalue)):
- E += data_rvalue[x] * data_prob[x]
- return E
- expected_value(hsy_rvalue, hsy_prob)
- # OUTPUT: 8.369000000000003
- def variance(data_rvalue, data_prob):
- '''Данная функция находит дисперсию'''
- rvalue_probs = dict(zip(data_rvalue, data_prob))
- expectation = expected_value(data_rvalue, data_prob) # E(X)
- square_of_expectation = expectation ** 2 # (E(X))^2
- expectation_of_squares = expected_value(data_rvalue**2, data_prob) # E(X^2)
- variance = expectation_of_squares - square_of_expectation # E(X^2) - (E(X))^2
- return variance
- variance(hsy_rvalue, hsy_prob)
- # OUTPUT: 63.06493899999994
- def standard_dev(data_rvalue, data_prob):
- v = variance(data_rvalue, data_prob)
- standard_dev = math.sqrt(v)
- return standard_dev
- standard_dev(hsy_rvalue, hsy_prob)
- # OUTPUT: 7.94134365205284
- lisn_rvalue = [-3.53,
- -2.59,
- -1.66,
- -0.72,
- 0.22,
- 1.16,
- 2.10,
- 3.04,
- 3.97,
- 5.22
- ]
- lisn_prob = [1.19,
- 3.75,
- 10.87,
- 23.12,
- 32.61,
- 18.58,
- 6.92,
- 1.98,
- 0.59,
- 0.40
- ]
- expected_value(lisn_rvalue, lisn_prob)
- # OUTPUT: 5.104700000000004
- variance(lisn_rvalue, lisn_prob)
- # ---------------------------------------------------------------------------
- # TypeError Traceback (most recent call last)
- # /tmp/ipykernel_27/1282851349.py in <module>
- # ----> 1 variance(lisn_rvalue, lisn_prob)
- # /tmp/ipykernel_27/325116310.py in variance(data_rvalue, data_prob)
- # 6 expectation = expected_value(data_rvalue, data_prob) # E(X)
- # 7 square_of_expectation = expectation ** 2 # (E(X))^2
- # ----> 8 expectation_of_squares = expected_value(data_rvalue**2, data_prob) # E(X^2)
- # 9 variance = expectation_of_squares - square_of_expectation # E(X^2) - (E(X))^2
- # 10
- #
- # TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement