-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
129 lines (100 loc) 路 4.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "40%",
eval = TRUE
)
# The `nflpredictr` R package provides a lightweight R package that provides predictions for upcoming (and past) NFL games.
# `nflpredictr` provides four main things:
#
# 1. Retrieves new data to use an inputs into a [ML model trained to predict the outcomes of NFL games](https://anguswg-ucsb.github.io/nfl_wins/)
# 2. Generate predictions using the new data
# 3. Visualize results.
# 4. Retrieve Las Vegas Odds and lines to compare with the predictions generated from `nflpredictr`
# ggplot2::ggsave(plot = fav_plot,
# filename = "man/figures/plot_fav.png",
# width = 12,
# height = 8)
```
# **nflpredictr** <img src="man/figures/logo.png" align="right" width="25%" />
<!-- badges: start -->
[![Dependencies](https://img.shields.io/badge/dependencies-7/26-orange?style=flat)](#)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://choosealicense.com/licenses/mit/)
[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
<div align="left">
<p align="left">
<a href="http://68.183.25.9:8000/__docs__/"><strong>芦 API 禄</strong></a>
<br />
<a href="https://anguswg-ucsb.github.io/nfl_wins/">Model Details</a>
</p>
</div>
<hr>
The **`nflpredictr`** R package provides a lightweight R client for retrieving predictions for upcoming (and past) NFL games via the [NFL Win Predictor API](http://68.183.25.9:8000/__docs__/). Details on the model used to make the predictions can be found [here](https://anguswg-ucsb.github.io/nfl_wins/)
**`nflpredictr`** provides four main functionalities:
1. Retrieves new data to use as the inputs into a [ML model trained to predict the outcomes of NFL games](https://anguswg-ucsb.github.io/nfl_wins/)
2. Provide the new data to the [API](http://68.183.25.9:8000/__docs__/) and return predictions
3. Visualize results.
4. Retrieve Las Vegas Odds and lines to compare with the predictions generated from **`nflpredictr`**
<hr>
## Installation
You can install the development version of **`nflpredictr`** from [GitHub](https://github.com/) with:
```{r, eval=FALSE, echo=TRUE}
# install.packages("devtools")
devtools::install_github("anguswg-ucsb/nflpredictr")
```
## Example
**`nflpredictr`** provides utility functions for accessing game predictions from a Logistic Regression ML model that was trained on ~20 years of historic NFL data and [correctly predicts the outcomes of games ~69% of the time](https://anguswg-ucsb.github.io/nfl_wins/#Model_Performance_on_Test_Data).
If no inputs are given to **`predict_games()`**, the default behavior is to make a prediction for week 2 of the 2021 NFL season.
```{r example}
# Load package
library(nflpredictr)
# Make an API request using predict_games(), default week is the upcoming week of the season
nflpredictr::predict_games(
year = 2021,
week = 2
)
```
<br>
## Make predictions on past games
Predictions can also be requested for weeks of past NFL seasons, going as far back as the 2016 season.
```{r past_predictions}
# Make an API request using predict_games() for a specific year and week
nflpredictr::predict_games(
year = 2018,
week = 8
)
```
## Make a tile plot of win probabilities
`nflpredictr` contains a few functions for quick plotting the outputs from **`predict_games()`**. The **`plot_tile()`** function will plot each match up side by side on a tile plot and color code teams by their predicted win probability from the NFL Win Prediction API.
```{r plot_tile, eval=FALSE}
# Plot the outputs from predict_games()
tile_plot <- nflpredictr::plot_tile(
predictions = nflpredictr::predict_games(
year = 2021,
week = 5
)
)
```
<img src="man/figures/tile_plot.png" align="center" height = "100%" width="100%" />
<br>
## Plot the teams favored to win that week
The `plot_favored()` function will plot the teams favored by the NFL Win Prediction API model in order of win probability.
```{r plot_fav, eval=FALSE}
# Plot the outputs from predict_games()
fav_plot <- nflpredictr::plot_favored(
predictions = nflpredictr::predict_games(
year = 2021,
week = 5
),
prob_alpha = FALSE
)
```
<img src="man/figures/plot_fav.png" align="center" height = "100%" width="100%" />
<br>