<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nba Archives - AI Betting Edge</title>
	<atom:link href="https://aibettingedge.com/tag/nba/feed/" rel="self" type="application/rss+xml" />
	<link>https://aibettingedge.com/tag/nba/</link>
	<description>MLB and NBA Prop Bets</description>
	<lastBuildDate>Sun, 21 Aug 2022 10:58:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>Scraping Potential Assists</title>
		<link>https://aibettingedge.com/scraping-potential-assists/</link>
					<comments>https://aibettingedge.com/scraping-potential-assists/#respond</comments>
		
		<dc:creator><![CDATA[Shon Butani]]></dc:creator>
		<pubDate>Fri, 15 May 2020 14:06:43 +0000</pubDate>
				<category><![CDATA[Apps]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[nba]]></category>
		<category><![CDATA[pandas]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://demo.creativethemes.com/blocksy/app/?p=273</guid>

					<description><![CDATA[<p>In this post, we&#8217;re going to discuss how to scrape one of the most important features for building a successful NBA prop bets model. That feature is potential assists. And it&#8217;s specifically helpful for building an over/under assists model.&#160; First, let&#8217;s discuss what a potential assist actually is. A potential assist is a pass that [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://aibettingedge.com/scraping-potential-assists/">Scraping Potential Assists</a> appeared first on <a rel="nofollow" href="https://aibettingedge.com">AI Betting Edge</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this post, we&#8217;re going to discuss how to scrape one of the most important features for building a successful NBA prop bets model. That feature is potential assists. And it&#8217;s specifically helpful for building an over/under assists model.&nbsp;</p>



<p class="wp-block-paragraph">First, let&#8217;s discuss what a potential assist actually is. A potential assist is a pass that leads directly to a shot, foul or turnover. If you watch basketball, you&#8217;ve probably noticed that the number of assists a player gets is&nbsp;<em>largely</em>&nbsp;dependent on how good his teammates are shooting that night. Let&#8217;s put it this way, consider two scenarios: In scenario one, player 1 makes three passes to player 2, and all three times player 2 shoots and makes a three pointer. That goes for both three potential assists and three assists for player 1. Each potential assist was actually realized as an actual assist, because player 2 made all his three 3-point attempts on passes from player 1. Now let&#8217;s consider scenario 2 &#8211; player 1 passes ten times to player 2, and player 2 shoots ten threes, making only two. This counts for TEN potential assists for player 1, while only two actual assists.</p>



<p class="wp-block-paragraph">Now comes the important question, which scenario do you prefer? The answer is, it&#8217;s complicated, but in the long run, scenario 2 is definitely preferable to scenario 1. No one in the history of basketball is a 100% three point shooter, so we can&#8217;t expect 3 potential assists to translate to 3 assists too often. On the contrary, most NBA players don&#8217;t shoot 20% from the field, so we can&#8217;t expect 10 potential assists to translate to 2 assists often &#8211; usually more like 3 or 4 assists. This is why just knowing the number of assists a player had in a game is a misleading statistic. By using potential assists as a feature, you can take into account how repeatable his previous assist totals are going forward.</p>



<p class="wp-block-paragraph">With that being said, let&#8217;s dig into the code. You&#8217;ll need the NBA API for this, and if you don&#8217;t have in installed yet, you can check out our previous blog post on working with the NBA API.</p>



<pre class="wp-block-code"><code>import pandas as pd
from nba_api.stats.endpoints import leaguedashptstats</code></pre>



<p class="wp-block-paragraph">Below we&#8217;ve created an easy to use function for you to scrape potential assists in addition to two other useful columns, passes made and passes received. The function itself takes in season, season_type, and game_date as arguments, and returns the three aformentioned features for all the players that played on that game date.</p>



<p class="wp-block-paragraph">The parameters that the leaguedashptstats endpoint takes in as arguments are predefined, so just copy and paste the function exactly as is below.</p>



<pre class="wp-block-code"><code>def get_passing_stats(season, season_type, game_date):

    player_dash_info = leaguedashptstats.LeagueDashPtStats(
        last_n_games = 0,
        pt_measure_type = "Passing",
        player_or_team = "Player",
        per_mode_simple = "PerGame",
        season = season,
        season_type_all_star = season_type,
        team_id_nullable = 0,
        opponent_team_id = 0,
        date_from_nullable = game_date,
        date_to_nullable = game_date
    )

    player_logs = player_dash_info.get_data_frames()&#91;0]
    player_logs&#91;"GAME_DATE"] = game_date
    
    player_logs&#91;"GAME_DATE"] = pd.to_datetime(player_logs&#91;"GAME_DATE"])
    
    return player_logs</code></pre>



<p class="wp-block-paragraph">And there you have it! Below is a dataframe the tells you how many passes made, passes received, and potential assists a player had for any particular game date. </p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="621" height="325" src="https://aibettingedge.com/wp-content/uploads/2022/05/Scraping-Potential-Assists.png" alt="Scraping Potential Assists" class="wp-image-434" srcset="https://aibettingedge.com/wp-content/uploads/2022/05/Scraping-Potential-Assists.png 621w, https://aibettingedge.com/wp-content/uploads/2022/05/Scraping-Potential-Assists-300x157.png 300w" sizes="(max-width: 621px) 100vw, 621px" /></figure>
<p>The post <a rel="nofollow" href="https://aibettingedge.com/scraping-potential-assists/">Scraping Potential Assists</a> appeared first on <a rel="nofollow" href="https://aibettingedge.com">AI Betting Edge</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://aibettingedge.com/scraping-potential-assists/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Calculating Season Averages for NBA Betting Features</title>
		<link>https://aibettingedge.com/calculating-season-averages-for-nba-betting-features/</link>
					<comments>https://aibettingedge.com/calculating-season-averages-for-nba-betting-features/#respond</comments>
		
		<dc:creator><![CDATA[Shon Butani]]></dc:creator>
		<pubDate>Fri, 15 May 2020 14:04:47 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Trends]]></category>
		<category><![CDATA[betting]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[nba]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://demo.creativethemes.com/blocksy/app/?p=270</guid>

					<description><![CDATA[<p>In this post, we&#8217;re going to dig into some feature engineering. At it&#8217;s core, any NBA betting model is a time series analysis problem. You&#8217;re trying to predict what a player will do tonight, given what he&#8217;s done in the past. The &#8220;given what he&#8217;s done in the past&#8221; is what we call feature engineering. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://aibettingedge.com/calculating-season-averages-for-nba-betting-features/">Calculating Season Averages for NBA Betting Features</a> appeared first on <a rel="nofollow" href="https://aibettingedge.com">AI Betting Edge</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this post, we&#8217;re going to dig into some feature engineering. At it&#8217;s core, any NBA betting model is a time series analysis problem. You&#8217;re trying to predict what a player will do tonight, given what he&#8217;s done in the past. The &#8220;given what he&#8217;s done in the past&#8221; is what we call feature engineering. In this post, we&#8217;re going to walk you through how to take some basic stats and turn them into season average features, while preventing the dreaded data leakage problem.</p>



<p class="wp-block-paragraph">First, as always (most of the time), we import pandas. That&#8217;s surprisingly the only package we&#8217;ll need for this blog post.</p>



<pre class="wp-block-code language-python"><code>import pandas as pd</code></pre>



<p class="wp-block-paragraph">Next, let&#8217;s define the features we want to compute season averages for. For simplicity, we chose the basic box score stats.</p>



<pre class="wp-block-code"><code>stats = &#91;'PTS','REB','AST','TOV','3PM','STL','BLK']</code></pre>



<p class="wp-block-paragraph">Now let&#8217;s dig into the logic. There are a few relatively straightforward preprocessing steps that need to be performed before computing the season average. But before digging into the code, let&#8217;s talk a little about what we DON&#8217;T want to do. Imagine the NBA season is 5 games long. Monday, Tuesday, Wednesday, Thursday and Friday. LeBron James scored 20, 25, 30, 35 and 40 points on those 5 days. We pass in all 5 games as part of our training data (the data the algorithm learns from), and the only feature we use is his season average for points.&nbsp;<em>What is</em>&nbsp;his season average? You may quickly think, oh it&#8217;s just (20+25+30+35+40)/5 = 30 points. But is his season average really 30 points for all of those 5 game dates? To the algorithm, when it&#8217;s predicting Wednesday, the games on Thursday and Friday have not happened yet. So really for Monday, there is no average, because there&#8217;s no &#8220;yesterday&#8221;. For Tuesday, his average is 20 (Monday&#8217;s total). For Wednesday, it&#8217;s 22.5 (taken by averaging Monday and Tuesday&#8217;s outcomes) and so on and so forth.</p>



<p class="wp-block-paragraph">With that being said, let&#8217;s dig into the code. We first need to convert the &#8220;GAME_DATE&#8221; collumn to a pandas datetime object. Next, we need to sort based on three columns, first by &#8220;SEASON_ID&#8221;, second by &#8220;PLAYER_ID&#8221;, and third by &#8220;GAME_DATE&#8221;. The logic behind this is straightforward: We want each player&#8217;s per season stats, sorted in ascending order by game date (to prevent data leakage as mentioned above).</p>



<p class="wp-block-paragraph">After the sorting is done, we do a groupby on &#8220;SEASON_ID&#8221;, &#8220;PLAYER_ID&#8221;, and &#8220;TEAM_ID&#8221; to ensure that if a player gets traded midseason, we&#8217;re counting his stats only with the current team he&#8217;s on (as per the game date in the row). We apply a lambda function to the stats columns we defined above, and shift everything by 1 day to make sure that we&#8217;re not accidentally counting the player&#8217;s stats from that day towards his averages for predicting that day (again a data leakage problem). For each unique SEASON_ID, PLAYER_ID, GAME_DATE group, the first row should be null. That&#8217;s because of the shift(1) we performed above.</p>



<pre class="wp-block-code"><code># full_df is a dataframe with the player stats on each game_date

full_df&#91;"GAME_DATE"] = pd.to_datetime(full_df&#91;"GAME_DATE"])
full_df.sort_values(by=&#91;"SEASON_ID", "PLAYER_ID","GAME_DATE"], inplace=True)
full_df.reset_index(inplace=True,drop=False)

moving_average_dataframe = full_df.groupby(&#91;"SEASON_ID", "PLAYER_ID","TEAM_ID"])&#91;stats].apply(lambda x: x.expanding().mean().shift(1)).reset_index(drop=True)
moving_average_dataframe.columns = "1_day_lag_season_average"+moving_average_dataframe.columns
full_df = full_df.join(moving_average_dataframe)

full_df.drop(columns=&#91;'index'],inplace=True)</code></pre>



<figure class="wp-block-image size-full"><img decoding="async" width="752" height="419" src="https://aibettingedge.com/wp-content/uploads/2022/05/nba-season-average.png" alt="nba-season-average" class="wp-image-438" srcset="https://aibettingedge.com/wp-content/uploads/2022/05/nba-season-average.png 752w, https://aibettingedge.com/wp-content/uploads/2022/05/nba-season-average-300x167.png 300w" sizes="(max-width: 752px) 100vw, 752px" /></figure>
<p>The post <a rel="nofollow" href="https://aibettingedge.com/calculating-season-averages-for-nba-betting-features/">Calculating Season Averages for NBA Betting Features</a> appeared first on <a rel="nofollow" href="https://aibettingedge.com">AI Betting Edge</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://aibettingedge.com/calculating-season-averages-for-nba-betting-features/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
