{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Itemratingranking
0authorization.com2.00003
1desirous.com0.00005
2jean.com4.00001
3peaked.com1.00004
4true.com3.00002
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Itemratingranking
0authorization.com0.50003
1desirous.com0.21435
2jean.com0.78571
3peaked.com0.35714
4true.com0.64292
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Itemratingranking
0authorization.com5.20003
1desirous.com-62.60005
2jean.com52.60001
3peaked.com-37.80004
4true.com42.60002
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Itemratingranking
0authorization.com214.64773
1desirous.com2.06045
2jean.com6356.26061
3peaked.com8.56604
4true.com6235.39882
\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 }