{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Domain market Example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Packages to load"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import ratingslib.ratings as rl\n",
"import pandas as pd\n",
"from ratingslib.datasets.filenames import FILENAME_DOMAIN_NAMES, dataset_path\n",
"from ratingslib.utils import logmsg\n",
"from ratingslib.utils.logmsg import set_logger\n",
"from ratingslib.utils.methods import print_pandas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set precision to 4 digits"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"pd.set_option('float_format', \"{:.4f}\".format)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Set logger to show extra information during computations"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"set_logger(logmsg.EXAMPLE)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Get the filename and add columns dictionary"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"filename_dn = dataset_path(FILENAME_DOMAIN_NAMES)\n",
"COLUMNS_DOMAIN_DICT = {\n",
" 'item_i': 'DomainNameI',\n",
" 'item_j': 'DomainNameJ',\n",
" 'points_i': 'TrendsI',\n",
" 'points_j': 'TrendsJ',\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Winloss ratings"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"EXAMPLE: Winloss[normalization=False]\n",
"Rating method for filename: \n",
"c:\\ratingslib\\datasets\\examples\\domainMarketExample.csv\n",
"MATRIX: \n",
"W\n",
"[2. 0. 4. 1. 3.]\n"
]
},
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Item | \n",
" rating | \n",
" ranking | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" authorization.com | \n",
" 2.0000 | \n",
" 3 | \n",
"
\n",
" \n",
" 1 | \n",
" desirous.com | \n",
" 0.0000 | \n",
" 5 | \n",
"
\n",
" \n",
" 2 | \n",
" jean.com | \n",
" 4.0000 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" peaked.com | \n",
" 1.0000 | \n",
" 4 | \n",
"
\n",
" \n",
" 4 | \n",
" true.com | \n",
" 3.0000 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Item rating ranking\n",
"0 authorization.com 2.0000 3\n",
"1 desirous.com 0.0000 5\n",
"2 jean.com 4.0000 1\n",
"3 peaked.com 1.0000 4\n",
"4 true.com 3.0000 2"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rl.Winloss(normalization=False).rate_from_file(filename_dn,\n",
" columns_dict=COLUMNS_DOMAIN_DICT)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Colley ratings"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"EXAMPLE: Colley\n",
"Rating method for filename: \n",
"c:\\ratingslib\\datasets\\examples\\domainMarketExample.csv\n",
"MATRIX: \n",
"C\n",
"[[ 6. -1. -1. -1. -1.]\n",
" [-1. 6. -1. -1. -1.]\n",
" [-1. -1. 6. -1. -1.]\n",
" [-1. -1. -1. 6. -1.]\n",
" [-1. -1. -1. -1. 6.]]\n",
"MATRIX: \n",
"b\n",
"[ 1. -1. 3. 0. 2.]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Item | \n",
" rating | \n",
" ranking | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" authorization.com | \n",
" 0.5000 | \n",
" 3 | \n",
"
\n",
" \n",
" 1 | \n",
" desirous.com | \n",
" 0.2143 | \n",
" 5 | \n",
"
\n",
" \n",
" 2 | \n",
" jean.com | \n",
" 0.7857 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" peaked.com | \n",
" 0.3571 | \n",
" 4 | \n",
"
\n",
" \n",
" 4 | \n",
" true.com | \n",
" 0.6429 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Item rating ranking\n",
"0 authorization.com 0.5000 3\n",
"1 desirous.com 0.2143 5\n",
"2 jean.com 0.7857 1\n",
"3 peaked.com 0.3571 4\n",
"4 true.com 0.6429 2"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rl.Colley().rate_from_file(filename_dn,\n",
" columns_dict=COLUMNS_DOMAIN_DICT)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Massey ratings"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"EXAMPLE: Massey[data_limit=0]\n",
"Rating method for filename: \n",
"c:\\ratingslib\\datasets\\examples\\domainMarketExample.csv\n",
"MATRIX: \n",
"Massey adjusted\n",
"[[ 4. -1. -1. -1. -1.]\n",
" [-1. 4. -1. -1. -1.]\n",
" [-1. -1. 4. -1. -1.]\n",
" [-1. -1. -1. 4. -1.]\n",
" [ 1. 1. 1. 1. 1.]]\n",
"MATRIX: \n",
"d adjusted\n",
"[ 26. -313. 263. -189. 0.]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Item | \n",
" rating | \n",
" ranking | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" authorization.com | \n",
" 5.2000 | \n",
" 3 | \n",
"
\n",
" \n",
" 1 | \n",
" desirous.com | \n",
" -62.6000 | \n",
" 5 | \n",
"
\n",
" \n",
" 2 | \n",
" jean.com | \n",
" 52.6000 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" peaked.com | \n",
" -37.8000 | \n",
" 4 | \n",
"
\n",
" \n",
" 4 | \n",
" true.com | \n",
" 42.6000 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Item rating ranking\n",
"0 authorization.com 5.2000 3\n",
"1 desirous.com -62.6000 5\n",
"2 jean.com 52.6000 1\n",
"3 peaked.com -37.8000 4\n",
"4 true.com 42.6000 2"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rl.Massey().rate_from_file(filename_dn,\n",
" columns_dict=COLUMNS_DOMAIN_DICT)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Offesne Defense ratings"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"EXAMPLE: OffenseDefense[tol=0.0001]\n",
"Rating method for filename: \n",
"c:\\ratingslib\\datasets\\examples\\domainMarketExample.csv\n",
"MATRIX: \n",
"od A\n",
"[[ 0. 1. 88. 5. 73.]\n",
" [93. 0. 88. 80. 73.]\n",
" [ 4. 0. 0. 0. 73.]\n",
" [93. 20. 88. 0. 73.]\n",
" [ 3. 0. 76. 0. 0.]]\n",
"INFO: iterations: 16 error: 7.715371838667995e-05 tol: 0.0001000 \n",
"MATRIX: \n",
"Offensive vector\n",
"[105.48 7.23 900.54 32.97 703.57]\n",
"MATRIX: \n",
"Defensive vector\n",
"[0.49 3.51 0.14 3.85 0.11]\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Item | \n",
" rating | \n",
" ranking | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" authorization.com | \n",
" 214.6477 | \n",
" 3 | \n",
"
\n",
" \n",
" 1 | \n",
" desirous.com | \n",
" 2.0604 | \n",
" 5 | \n",
"
\n",
" \n",
" 2 | \n",
" jean.com | \n",
" 6356.2606 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" peaked.com | \n",
" 8.5660 | \n",
" 4 | \n",
"
\n",
" \n",
" 4 | \n",
" true.com | \n",
" 6235.3988 | \n",
" 2 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Item rating ranking\n",
"0 authorization.com 214.6477 3\n",
"1 desirous.com 2.0604 5\n",
"2 jean.com 6356.2606 1\n",
"3 peaked.com 8.5660 4\n",
"4 true.com 6235.3988 2"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rl.OffenseDefense().rate_from_file(filename_dn,\n",
" columns_dict=COLUMNS_DOMAIN_DICT)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.13 ('py38')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "23ceb7112fbf9d0e38ecbf60d6e6d5e2dcebcc82200eeb1e5a5d5f9ffb9e27ca"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}