### Install kickscore via pip Source: https://github.com/lucasmaystre/kickscore/blob/master/README.rst This command installs the latest release of the kickscore library directly from the Python Package Index (PyPI). It is the standard way to get started with the library. ```Shell pip install kickscore ``` -------------------------------- ### Installing kickscore library (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Installs the kickscore library using pip, typically required when running in environments like Google Colaboratory. ```Python !pip install kickscore ``` -------------------------------- ### Install kickscore Library (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Installs the kickscore library using pip. This is typically needed when running in environments like Google Colaboratory. ```python !pip install kickscore ``` -------------------------------- ### Initializing a BinaryModel (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Creates an instance of the BinaryModel from the kickscore library, suitable for modeling outcomes where one item wins over another. ```Python model = ks.BinaryModel() ``` -------------------------------- ### Importing kickscore and setting up plotting (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Imports the kickscore library under the alias 'ks' and enables inline plotting for visualization in a notebook environment. ```Python import kickscore as ks %matplotlib inline ``` -------------------------------- ### Fitting the kickscore model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Trains the kickscore model using the added observations to infer the latent skill parameters over time. ```Python model.fit(verbose=True) ``` -------------------------------- ### Define kickscore Model and Kernel (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Initializes a kickscore.BinaryModel suitable for pairwise comparisons and defines a composite kernel using Constant and Matern32 components. The kernel parameters are set based on prior optimization results, with lengthscale converted to seconds. ```python # It is a bit more convenient to specify lengthscales in yearly units. seconds_in_year = 365.25 * 24 * 60 * 60 model = ks.BinaryModel() kernel = (ks.kernel.Constant(var=0.03) + ks.kernel.Matern32(var=0.138, lscale=1.753*seconds_in_year)) ``` -------------------------------- ### Defining item kernels and adding items to the model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Defines kernel functions to describe the temporal dynamics of item skills and adds items (contestants) to the model with their respective kernels. ```Python # Spike's skill does not change over time. k_spike = ks.kernel.Constant(var=0.5) # Tom's skill changes over time, with "jagged" (non-smooth) dynamics. k_tom = ks.kernel.Exponential(var=1.0, lscale=1.0) # Jerry's skill has a constant offset and smooth dynamics. k_jerry = ks.kernel.Constant(var=1.0) + ks.kernel.Matern52(var=0.5, lscale=1.0) # Now we are ready to add the items in the model. model.add_item("Spike", kernel=k_spike) model.add_item("Tom", kernel=k_tom) model.add_item("Jerry", kernel=k_jerry) ``` -------------------------------- ### Fit the kickscore Model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Executes the model fitting process using the model.fit() method. This command is timed using %%time in the notebook environment. It prints a message indicating if the model fitting converged successfully. ```python %%time converged = model.fit() if converged: print("Model has converged.") ``` -------------------------------- ### Download NBA Data (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Downloads the NBA Elo dataset from FiveThirtyEight's website using the curl command executed from the Python environment and saves it as nba_elo.csv. ```python !curl https://projects.fivethirtyeight.com/nba-model/nba_elo.csv -o nba_elo.csv ``` -------------------------------- ### Import Required Libraries (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Imports necessary Python libraries: csv for data parsing, kickscore as ks for the modeling, datetime for time handling, and enables inline matplotlib plotting. ```python import csv import kickscore as ks from datetime import datetime %matplotlib inline ``` -------------------------------- ### Plotting item skills over time (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Visualizes the inferred skill trajectories for specified items over time, showing the mean skill and one standard deviation confidence interval. ```Python model.plot_scores(["Tom", "Jerry", "Spike"], figsize=(14, 5)); ``` -------------------------------- ### Calculate Future Probability with Model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Calculates the probability of one entity beating another at a future time point (t=2.0) using the model's `probabilities` method and prints the result. ```python p_win, p_los = model.probabilities(["Jerry"], ["Tom"], t=2.0) print("Chances that Jerry beats Tom at t = 2.0: {:.1f}%".format(100*p_win)) ``` -------------------------------- ### Calculate Past Probability with Model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Calculates the probability of one entity beating another at a past time point (t=-1.0) using the model's `probabilities` method and prints the result. ```python p_win, p_los = model.probabilities(["Jerry"], ["Tom"], t=-1.0) print("Chances that Jerry beats Tom at t = -1.0: {:.1f}%".format(100*p_win)) ``` -------------------------------- ### Parse NBA Data and Create Observations (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Reads the downloaded nba_elo.csv file, extracts team names, and creates a list of game observations up to a specified cutoff date (June 1, 2019). Each observation records the winner(s), loser(s), and timestamp of a game. ```python teams = set() observations = list() cutoff = datetime(2019, 6, 1).timestamp() with open("nba_elo.csv") as f: for row in csv.DictReader(f): t = datetime.strptime(row["date"], "%Y-%m-%d").timestamp() if t > cutoff: break teams.add(row["team1"]) teams.add(row["team2"]) if int(row["score1"]) > int(row["score2"]): observations.append({ "winners": [row["team1"]], "losers": [row["team2"]], "t": t, }) else: observations.append({ "winners": [row["team2"]], "losers": [row["team1"]], "t": t, }) ``` -------------------------------- ### Adding observations to the model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Adds chronological observations of outcomes (winners and losers) at specific time points to the kickscore model for training. ```Python # At first, Jerry beats Tom a couple of times. model.observe(winners=["Jerry"], losers=["Tom"], t=0.0) model.observe(winners=["Jerry"], losers=["Tom"], t=0.9) # Then, Tom beats Spike, and then Jerry. model.observe(winners=["Tom"], losers=["Spike"], t=1.7) model.observe(winners=["Tom"], losers=["Jerry"], t=2.1) # Finally, Jerry beats Tom, and then Tom + Spike. model.observe(winners=["Jerry"], losers=["Tom"], t=3.0) model.observe(winners=["Jerry"], losers=["Tom", "Spike"], t=3.5) ``` -------------------------------- ### Access Model Log-Likelihood (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Accesses the log-marginal likelihood of the data given the model. This value can be used to compare different models; a higher value indicates a better fit. ```python model.log_likelihood ``` -------------------------------- ### Predicting outcome probabilities (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/kickscore-basics.ipynb Uses the fitted model to predict the probability of a specific outcome (one item winning over another) at a given future time point. ```Python # We can predict a future outcome... p_win, p_los = model.probabilities(["Jerry"], ["Tom"], t=4.0) print("Chances that Jerry beats Tom at t = 4.0: {:.1f}%".format(100*p_win)) ``` -------------------------------- ### Add Teams and Observations to Model (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Iterates through the collected set of unique team names and adds each team to the kickscore model with the defined kernel. Then, it iterates through the list of game observations and adds each game result to the model. ```python for team in teams: model.add_item(team, kernel=kernel) for obs in observations: model.observe(**obs) ``` -------------------------------- ### Plot Team Skill Evolution (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Generates a plot showing the estimated skill evolution over time for specific NBA teams (Lakers, Bulls, Celtics) using the fitted model. The plot resolution and size are configured, and timestamps are used on the x-axis. A title is added to the plot. ```python fig, ax = model.plot_scores( items=["LAL", "CHI", "BOS"], resolution=10/seconds_in_year, figsize=(14.0, 3.0), timestamps=True) ax.set_title("Evolution of skill of NBA teams (1946–2019)"); ``` -------------------------------- ### Compute Outcome Probabilities (Python) Source: https://github.com/lucasmaystre/kickscore/blob/master/examples/nba-history.ipynb Uses the fitted model to calculate and print the probability of the Chicago Bulls beating the Boston Celtics at three different points in time (1996, 2001, and 2020). ```python print("Probability that CHI beats BOS...") p_win, _ = model.probabilities(["CHI"], ["BOS"], t=datetime(1996, 1, 1).timestamp()) print(" ... in 1996: {:.2f}%".format(100 * p_win)) p_win, _ = model.probabilities(["CHI"], ["BOS"], t=datetime(2001, 1, 1).timestamp()) print(" ... in 2001: {:.2f}%".format(100 * p_win)) p_win, _ = model.probabilities(["CHI"], ["BOS"], t=datetime(2020, 1, 1).timestamp()) print(" ... in 2020: {:.2f}%".format(100 * p_win)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.