<jupyter_start><jupyter_text>ЛР 1 (В8) Основные понятия математической статистики. Вариационный ряд. Эмпирическая функция распределения.<jupyter_code>from random import uniform
from tabulate import tabulate
from collections import Counter
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>1<jupyter_code>def Y(x):
    return 2 / (2 + x)

a = -1
b = 5
y0 = 1
n = 10
X = sorted(round(uniform(0, 1) * (b - a) + a, 3) for _ in range(n))
X
y_list = sorted([round(Y(X[i]), 3) for i in range(n)])<jupyter_output><empty_output><jupyter_text>2 Вариационный ряд<jupyter_code>y_list<jupyter_output><empty_output><jupyter_text>Эмпирическая функция распределения<jupyter_code>counts = dict(Counter(y_list))
freq = [round(i / n, 3) for i in counts.values()]
ys = [0]
for k, i in enumerate(counts.values()):
    ys.append(ys[k] + i)
star_f = [round(i / n, 3) for i in ys]
star_f<jupyter_output><empty_output><jupyter_text>Таблица и график<jupyter_code>x_list = sorted(list(set(y_list[:])))

table = [list(item) for item in zip(x_list, counts.values(), freq, ys[1:], star_f[1:])]
print(tabulate(table, headers=['Значение', 'Количество вариант', 'Частота',
                               'Накопленное количество вариант', 'Накопленная частота'], tablefmt='fancy_grid'))
x_list.insert(0, -float('inf'))
x_list.append(float('inf'))
x_interval = [(x_list[i], x_list[i+1]) for i in range(len(x_list) - 1)]
table = [list(item) for item in zip(x_interval, star_f)]
print(tabulate(table, headers=['Промежуток', 'Значение функции'], tablefmt='fancy_grid'))
x_plot = x_list[1:-1]
y_plot = star_f[:]
x_plot.insert(0, a)
x_plot.append(b)
y_plot.insert(0, 0)
plt.step(x_plot, y_plot)
plt.plot(x_plot[1:-1], y_plot[1:-1], '.')
plt.grid(True)
plt.show()<jupyter_output><empty_output><jupyter_text>3 Теоритическая функция распределения<jupyter_code>def G(y):
    if y < 2 / 7:
        return 0
    elif y > 2:
        return 1
    else:
        return 1 / 3 * (-(1 / y) + 3.5)<jupyter_output><empty_output><jupyter_text>График теоритической функции расределения<jupyter_code>x_lin = np.linspace(min(x_plot), max(x_plot), 50)
plt.plot(x_lin, list(map(G, x_lin)))
plt.grid(True)
plt.show()<jupyter_output><empty_output><jupyter_text>График эмпирической и теоретической функции<jupyter_code>plt.step(x_plot, y_plot)
plt.plot(x_plot[1:-1], y_plot[1:-1], '.')
plt.plot(x_lin, list(map(G, x_lin)))
plt.grid(True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15860105734038227, 'fraction_numerical': 0.020333468889792598, 'mean_word_length': 5.871508379888268, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '438599', 'license': 'MIT', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1111, 'n_words': 200, 'path': 'term4/TViMS/lab1.ipynb', 'repo_name': 'japanese-goblinn/labs', 'size': '2459'}