Add pretty prints
This commit is contained in:
parent
fdb95361cb
commit
39c9a260e1
@ -25,7 +25,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 313,
|
||||
"execution_count": 61,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
@ -47,7 +47,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 314,
|
||||
"execution_count": 62,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -56,7 +56,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 315,
|
||||
"execution_count": 63,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -67,7 +67,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 316,
|
||||
"execution_count": 64,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -88,7 +88,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 317,
|
||||
"execution_count": 65,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
@ -110,7 +110,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 318,
|
||||
"execution_count": 66,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -128,7 +128,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 319,
|
||||
"execution_count": 67,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -146,7 +146,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 320,
|
||||
"execution_count": 68,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -171,6 +171,36 @@
|
||||
" return t_stat_list"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 69,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def pretty_print_test(p, t_stat_from_sample, t_stat_list, thesis, alternative, max_print=5):\n",
|
||||
" print('Wyniki bootstrapowej wersji testu T-studenta')\n",
|
||||
" print()\n",
|
||||
" print(f'Hipoteza: {thesis}')\n",
|
||||
" if alternative is Alternatives.LESS:\n",
|
||||
" print(f'Hipoteza alternatywna: średnia jest mniejsza')\n",
|
||||
" else:\n",
|
||||
" print(f'Hipoteza alternatywna: średnia jest większa')\n",
|
||||
" print()\n",
|
||||
" print(f'p: {p}')\n",
|
||||
" print(f'Wartość statystyki testowej z próby: {t_stat_from_sample}')\n",
|
||||
" print(f'Wartości statystyk z prób boostrapowych:')\n",
|
||||
"\n",
|
||||
" t_stat_list_len = len(t_stat_list)\n",
|
||||
" for i in range(min(max_print, t_stat_list_len)):\n",
|
||||
" print(f'{t_stat_list[i]}, ', end='')\n",
|
||||
" if max_print < t_stat_list_len:\n",
|
||||
" remaining = t_stat_list_len - max_print\n",
|
||||
" print(f'... (i {remaining} pozostałych)')\n",
|
||||
"\n",
|
||||
" print()\n",
|
||||
" print()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@ -193,7 +223,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 321,
|
||||
"execution_count": 70,
|
||||
"metadata": {
|
||||
"pycharm": {
|
||||
"name": "#%%\n"
|
||||
@ -221,7 +251,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 322,
|
||||
"execution_count": 71,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"pycharm": {
|
||||
@ -231,11 +261,15 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def bootstrap_one_sample(sample, population_mean, alternative=Alternatives.LESS):\n",
|
||||
" return t_test_1_samp(\n",
|
||||
" p, t, ts = t_test_1_samp(\n",
|
||||
" sample_1=sample,\n",
|
||||
" population_mean=population_mean,\n",
|
||||
" alternative=alternative,\n",
|
||||
" )"
|
||||
" )\n",
|
||||
" \n",
|
||||
" pretty_print_test(p, t, ts, f'średnia jest równa {population_mean}', alternative)\n",
|
||||
" print()\n",
|
||||
" return p, t, ts"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -247,7 +281,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 323,
|
||||
"execution_count": 72,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -258,7 +292,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 324,
|
||||
"execution_count": 73,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"pycharm": {
|
||||
@ -270,15 +304,22 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"p: 0.73\n"
|
||||
"Wyniki bootstrapowej wersji testu T-studenta\n",
|
||||
"\n",
|
||||
"Hipoteza: średnia jest równa 165\n",
|
||||
"Hipoteza alternatywna: średnia jest mniejsza\n",
|
||||
"\n",
|
||||
"p: 0.58\n",
|
||||
"Wartość statystyki testowej z próby: [-229.1025971]\n",
|
||||
"Wartości statystyk z prób boostrapowych:\n",
|
||||
"[-316.92367438], [-406.5], [-201.5], [-243.92267776], [-330.27286699], ... (i 95 pozostałych)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"#TODO: poprawić kod aby można było podawać kolumny\n",
|
||||
"\n",
|
||||
"p, _ = bootstrap_one_sample(dummy, 165)\n",
|
||||
"print(f'p: {p}')"
|
||||
"p, t, ts = bootstrap_one_sample(dummy, 165)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -302,7 +343,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 325,
|
||||
"execution_count": 74,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"pycharm": {
|
||||
@ -312,11 +353,14 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def bootstrap_independent(sample_1, sample_2, alternative=Alternatives.LESS):\n",
|
||||
" return t_test_ind(\n",
|
||||
" p, t, ts = t_test_ind(\n",
|
||||
" sample_1=sample_1,\n",
|
||||
" sample_2=sample_2,\n",
|
||||
" alternative=alternative,\n",
|
||||
" )"
|
||||
" )\n",
|
||||
" \n",
|
||||
" pretty_print_test(p, t, ts, 'średnie są takie same', alternative)\n",
|
||||
" return p, t, ts"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -348,7 +392,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 326,
|
||||
"execution_count": 75,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"pycharm": {
|
||||
@ -358,11 +402,14 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def bootstrap_dependent(sample_1, sample_2, alternative=Alternatives.LESS):\n",
|
||||
" return t_test_dep(\n",
|
||||
" p, t, ts = t_test_dep(\n",
|
||||
" sample_1=sample_1,\n",
|
||||
" sample_2=sample_2,\n",
|
||||
" alternative=alternative,\n",
|
||||
" )"
|
||||
" )\n",
|
||||
" \n",
|
||||
" pretty_print_test(p, t, ts, 'średnie są takie same', alternative)\n",
|
||||
" return p, t, ts"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -390,7 +437,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 327,
|
||||
"execution_count": 76,
|
||||
"metadata": {
|
||||
"collapsed": false,
|
||||
"pycharm": {
|
||||
@ -419,7 +466,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 328,
|
||||
"execution_count": 77,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
@ -427,11 +474,35 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Statystyki dla jednej próby:\n",
|
||||
"0.44\n",
|
||||
"Wyniki bootstrapowej wersji testu T-studenta\n",
|
||||
"\n",
|
||||
"Hipoteza: średnia jest równa 2\n",
|
||||
"Hipoteza alternatywna: średnia jest mniejsza\n",
|
||||
"\n",
|
||||
"p: 0.52\n",
|
||||
"Wartość statystyki testowej z próby: [1.41421356]\n",
|
||||
"Wartości statystyk z prób boostrapowych:\n",
|
||||
"[-0.53452248], [0.], [-1.63299316], [1.5], [2.3590713], ... (i 95 pozostałych)\n",
|
||||
"Statystyki dla dwóch prób zależnych:\n",
|
||||
"0.0\n",
|
||||
"Wyniki bootstrapowej wersji testu T-studenta\n",
|
||||
"\n",
|
||||
"Hipoteza: średnie są takie same\n",
|
||||
"Hipoteza alternatywna: średnia jest mniejsza\n",
|
||||
"\n",
|
||||
"p: 0.0\n",
|
||||
"Wartość statystyki testowej z próby: [10.61445555]\n",
|
||||
"Wartości statystyk z prób boostrapowych:\n",
|
||||
"[nan], [nan], [nan], [nan], [nan], ... (i 95 pozostałych)\n",
|
||||
"Statystyki dla dwóch prób niezależnych:\n",
|
||||
"1.0\n"
|
||||
"Wyniki bootstrapowej wersji testu T-studenta\n",
|
||||
"\n",
|
||||
"Hipoteza: średnie są takie same\n",
|
||||
"Hipoteza alternatywna: średnia jest mniejsza\n",
|
||||
"\n",
|
||||
"p: 1.0\n",
|
||||
"Wartość statystyki testowej z próby: [2.4140394]\n",
|
||||
"Wartości statystyk z prób boostrapowych:\n",
|
||||
"[0.], [0.], [0.], [0.], [0.], ... (i 95 pozostałych)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -440,16 +511,13 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"print('Statystyki dla jednej próby:')\n",
|
||||
"p, _ = bootstrap_one_sample(dummy, 2)\n",
|
||||
"print(f'p {p}')\n",
|
||||
"p, t, ts = bootstrap_one_sample(dummy, 2)\n",
|
||||
"\n",
|
||||
"print('Statystyki dla dwóch prób zależnych:')\n",
|
||||
"p, _ = bootstrap_dependent(dummy2, dummy3)\n",
|
||||
"print(f'p {p}')\n",
|
||||
"p, t, ts = bootstrap_dependent(dummy2, dummy3)\n",
|
||||
"\n",
|
||||
"print('Statystyki dla dwóch prób niezależnych:')\n",
|
||||
"p, _ = bootstrap_independent(dummy2, dummy3)\n",
|
||||
"print(f'p {p}')"
|
||||
"p, t, ts = bootstrap_independent(dummy2, dummy3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -483,7 +551,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10-final"
|
||||
"version": "3.9.1"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user