<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Josh Weiner on Medium]]></title>
        <description><![CDATA[Stories by Josh Weiner on Medium]]></description>
        <link>https://medium.com/@josh-weiner?source=rss-ae404173ac9c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sC-cs_ZfBAD7rbRH-be1NQ.jpeg</url>
            <title>Stories by Josh Weiner on Medium</title>
            <link>https://medium.com/@josh-weiner?source=rss-ae404173ac9c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:28:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@josh-weiner/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Untangling the Mesh: An Exploration of Offline Network Engineering]]></title>
            <link>https://medium.com/codex/untangling-the-mesh-an-exploration-of-offline-network-engineering-9269df3f6a07?source=rss-ae404173ac9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9269df3f6a07</guid>
            <category><![CDATA[network-engineering]]></category>
            <category><![CDATA[mesh-networks]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[projects]]></category>
            <dc:creator><![CDATA[Josh Weiner]]></dc:creator>
            <pubDate>Wed, 06 Dec 2023 14:32:55 GMT</pubDate>
            <atom:updated>2023-12-07T12:04:27.206Z</atom:updated>
            <content:encoded><![CDATA[<h4>How you can use cheap components and creative engineering to build your own private network and take your communications with others offline.</h4><p>As a software &amp; machine learning engineer, I often deal with programming for hardware in the abstract sense: software is built on top of an understanding of how computer components partition resources when it comes to runtime and memory. Rarely, however, have I built directly on top of the hardware layer– save a handful of classes in operating systems and computer architecture. It’s always good practice to expand one’s comfort zone– and I decided that learning how to program Arduino and basic electrical engineering components would be a good first step.</p><p>The motivation behind this project to create an offline mesh network was twofold:</p><ol><li><strong>Humanitarian / Open-access Principles<br></strong>A well-constructed offline mesh network would work in disaster relief zones, areas of the developing world without internet coverage, be end-to-end encrypted (for safe use in situations where say <a href="https://journals.sagepub.com/doi/10.1177/2056305119827002">a government is limiting access to the internet</a> / disrupting communications), and resilient. Ideally if a node were to be removed from the network, so long as it’s not a <a href="https://faculty.etsu.edu/gardnerr/5340/notes-Bondy-Murty-GT/Bondy-Murty-GT-5-2.pdf">cut vertex</a>, the network should remain intact and usable.<br>With the minimal requisite components, this project should provide a cost-efficient platform for people in these situations to be able to communicate.</li><li><strong>Unfinished Business<br></strong>As an overly-ambitious high school student, I participated in a student developer program at Google where our team sought to build WiFi-enabled mesh networks between Android devices for the above purposes. A lack of experience and knowledge in this domain, and in Android programming, seriously hindered our ability to succeed– so why not give it another shot, albeit five years later!</li></ol><p>Before we continue, I would like to credit the good people at IffyBooks in Philadelphia for renewing my interest in this project. Check out their <a href="https://iffybooks.net/wp-content/uploads/zines/Iffy_Books_Pocket_Wifi_Portal_Zine_screen.pdf">guide to setting up a pocket wifi library portal</a> for a very cool, less involved project along similar principles!</p><p>But without further ado, let’s jump right into the project. Feel free to follow along on my abbreviated <a href="https://x.com/jmweiner_/status/1731459998343917658?s=20">Twitter/X thread</a> or <a href="https://github.com/JoshWeiner/offline-mesh-network">view the GitHub</a> repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ygu3jAjo2Jbzp-EF" /><figcaption>Photo by <a href="https://unsplash.com/@avkshift?utm_source=medium&amp;utm_medium=referral">Victor Aznabaev</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong>Getting Started</strong></h4><p>Because this is a hardware and software-enabled project, we will need a few components to get started.</p><ul><li>Multiple ESP8266 WiFi Microchips with 16MB of Flash Memory<br>(Between $2-$6 each)</li><li>USB/USB-C to Micro-USB Cables<br>(Between $2–$6 each)</li><li>Multiple devices and/or multiple low-voltage power sources</li></ul><p>You should also be sure to download the Arduino IDE or PlatformIO extension for VSCode, this will allow us to write our programs to flash memory, monitor the activity on the chips, and upload any files we need to serve over the network to users.</p><p>To get familiar with our IDE, and how to work with these chips, let’s first focus on writing a simple program to create a WiFi portal and have the chips blink an LED. I will skip over the details of how to compile and upload files to the ESP8266 chips, as these can be found in the <a href="https://iffybooks.net/wp-content/uploads/zines/Iffy_Books_Pocket_Wifi_Portal_Zine_screen.pdf">IffyBooks guide</a>.</p><pre>#include &lt;ESP8266WiFi.h&gt;<br>// Setup is only run once<br>void setup() {<br>  pinMode(LED_BUILTIN, OUTPUT);<br>  WiFi.mode(WIFI_AP);<br>  WiFi.softAP(&quot;Free Reading Wifi&quot;);<br>}<br><br>// Loop is going to run continuously<br>void loop() {<br>  digitalWrite(LED_BUILTIN, HIGH);<br>  delay(1000);<br>  digitalWrite(LED_BUILTIN, LOW);<br>  delay(1000);<br>}</pre><p>Success! Now we are confident that we can write to the chips and have them do something. The floodgates are open, and there is little better than this feeling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*vhRKxfR8JoPlyE-wWdEz7Q.gif" /><figcaption>Blink if you’re excited about network programming!</figcaption></figure><h4>Establishing and Testing a Mesh Network</h4><p>This is the portion of the project in which we must carefully think around our system and network design. Let’s review some of the constraints, and what we hope to build:</p><ul><li>We want to build a mesh network: a group of ESP8266 nodes that share a network and send information among themselves. This means that some of the chips will have to be Access Points, and others will be station nodes. This leads us to a “star” model as follows:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*QrHtpJhQxhP60kJdUoeckg.png" /><figcaption>Clients connect to access points, which themselves connect to the rest of the mesh network. This leads to the “star” diagram model we see here. We can extend the range of the network by adding more station nodes that connect access points, which would otherwise be out of range for some devices.</figcaption></figure><ul><li>We also want to build a chat interface: some way for users connected to the mesh network to communicate with each other. However, because the chips comprising the network do not have a lot of memory, and to reduce the amount of total information being streamed at one time over the network, we will store chat histories on the client devices. This will also allow us to build client-side encryption: which offers a much higher level of privacy for our chat app.</li></ul><p>With these considerations in mind, let’s start to build the mesh network. First, using the PainlessMesh library, we build the connection, send message, and receiving callbacks. This allows nodes to connect to the mesh and communicate with each other.</p><p>Now, we write some functions that we can start the network on each node, join and say hello to the network, and list the other nodes making up our mesh. These last two aren’t necessary, but allow us to see if the correct behavior occurs in the Serial Monitor.</p><pre>#define LED_BUILTIN 2<br>#define MESH_PREFIX &quot;YOUR NETWORK NAME&quot;<br>#define MESH_PASSWORD &quot;CHANGE ME AND KEEP ME A SECRET&quot;<br>#define MESH_PORT 5555<br><br>const int HTTP_PORT = 80;<br>const int WS_PORT = 1337;<br><br>painlessMesh mesh;<br><br>void sendMessage();<br><br>void sendMessageClient(String msg) {<br>  Serial.printf(&quot;Sending to node %u msg=%s\n&quot;, mesh.getNodeId(), msg.c_str());<br>  mesh.sendBroadcast(msg);<br>}<br><br>void receivedCallback( uint32_t from, String &amp;msg ) {<br>  Serial.printf(&quot;Received from %u msg=%s\n&quot;, from, msg.c_str());<br>  webSocket.broadcastTXT(msg.c_str());<br>}<br><br>void newConnectionCallback(uint32_t nodeId) {<br>  Serial.printf(&quot;New Connection, nodeId = %u\n&quot;, nodeId);<br>}<br><br>void changedConnectionCallback() {<br>  Serial.printf(&quot;Changed connections\n&quot;);<br>}<br><br>void nodeTimeAdjustedCallback(int32_t offset) {<br>  Serial.printf(&quot;Adjusted time %u. Offset = %d\n&quot;, mesh.getNodeTime(),offset);<br>  webSocket.loop();<br>}<br><br>void broadcastTestMessage() {<br>  String msg = &quot;Hello from node &quot; + String(mesh.getNodeId());<br>  mesh.sendBroadcast(msg);<br>  Serial.println(&quot;Test message sent: &quot; + msg);<br>}<br><br>unsigned long previousMillis = 0;<br>const long interval = 5000;<br><br>void listNodes() {<br>  auto nodes = mesh.getNodeList();<br>  Serial.printf(&quot;The mesh has %u nodes:\n&quot;, nodes.size());<br>  for (auto &amp;id : nodes) {<br>    Serial.printf(&quot;Node ID: %u\n&quot;, id);<br>  }<br>}<br><br>void StartMesh() {<br>  mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION );<br>  mesh.init( MESH_PREFIX, MESH_PASSWORD, MESH_PORT );<br>  mesh.onReceive(&amp;receivedCallback);<br>  mesh.onNewConnection(&amp;newConnectionCallback);<br>  mesh.onChangedConnections(&amp;changedConnectionCallback);<br>  mesh.onNodeTimeAdjusted(&amp;nodeTimeAdjustedCallback);<br>  broadcastTestMessage();<br>}</pre><p>Make sure to set your own SSID and password to keep the network secured. Especially if you plan to use open-source code to build this (<a href="https://blog.gitguardian.com/yes-github-copilot-can-leak-secrets/">see this article about sensitive information leakage from LLMs</a>).</p><p>In addition to establishing a mesh network, some nodes will need to serve as WiFi Access Points (APs) as we established earlier. Not sure if this was due to the properties of the ESP8266 chips, the properties of APs or painlessMesh nodes, or issues within my code, but I quickly learned that the mesh won’t work if all nodes are APs with the same SSID information. This means the dispersal of APs on the mesh needs to be purposeful. This is why we will build the network with the star model design from earlier– with all APs out of range of eachother.</p><p>Once we flash some of the chips as APs, and all as nodes on the mesh network, let’s actually test if the network is established and the nodes communicate!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*8wOE4b2URQjFksM2NLdU_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*9QaMAs-WysgoYRpfa4MWwg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*vIZ25I_F4lJd36nBj8UeHg.png" /><figcaption>When chips talk…</figcaption></figure><p><strong>Setting up a File System &amp; Serving Static Files</strong></p><p>With the network set up and operational, we need to shift our focus to making this full-stack enabled. We need to open a Web Socket that can communicate with a frontend, access the chips’ filesystems, and establish a DNS server.</p><pre>// Functions for WebSocket<br>void onWebSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {<br>  switch(type) {<br>    case WStype_DISCONNECTED:<br>      Serial.printf(&quot;[%u] Disconnected!\n&quot;, num);<br>      break;<br>    case WStype_CONNECTED:<br>      {<br>        IPAddress ip = webSocket.remoteIP(num);<br>        // Serial.printf(&quot;[%u] Connected from %d.%d.%d.%d url: %s\n&quot;, num, ip[0], ip[1], ip[2], ip[3], payload);<br>      }<br>      break;<br>    case WStype_TEXT:<br>      Serial.printf(&quot;[%u] get Text: %s\n&quot;, num, payload);<br>      webSocket.broadcastTXT(payload, length);<br>      sendMessageClient((char*)payload);<br>      break;<br><br>    case WStype_BIN:<br>    case WStype_ERROR:<br>    case WStype_FRAGMENT_TEXT_START:<br>    case WStype_FRAGMENT_BIN_START:<br>    case WStype_FRAGMENT:<br>    case WStype_FRAGMENT_FIN:<br>    default:<br>      break;<br>  }<br>}</pre><p>The following allow us to serve static files stored on the chip to the client once the file system has been mounted:</p><pre>void onIndexRequest(AsyncWebServerRequest *request) {<br>  IPAddress ip = request-&gt;client()-&gt;remoteIP();<br>  request-&gt;send(LittleFS, &quot;/index.html&quot;, &quot;text/html&quot;);<br>}<br><br>void onCSSRequest(AsyncWebServerRequest *request) {<br>  IPAddress ip = request-&gt;client()-&gt;remoteIP();<br>  request-&gt;send(LittleFS, &quot;/styles.css&quot;, &quot;text/css&quot;);<br>}<br><br>void onJSRequest(AsyncWebServerRequest *request) {<br>  IPAddress ip = request-&gt;client()-&gt;remoteIP();<br>  request-&gt;send(LittleFS, &quot;/scripts.js&quot;, &quot;text/js&quot;);<br>}</pre><p>Let’s put it all together: mounting the file system, creating routes on HTTP requests for the server, connecting to the Web Socket, and starting our DNS server.</p><pre>void StartFilesystem() {<br>  if(!LittleFS.begin()){<br>    Serial.println(&quot;An Error has occurred while mounting LittleFS&quot;);<br>    return;<br>  }<br>}<br><br>void ConnectToServer() {<br>  server.on(&quot;/&quot;, HTTP_GET, onIndexRequest);<br>  server.on(&quot;/styles.css&quot;, HTTP_GET, onCSSRequest);<br>  server.on(&quot;/scripts.js&quot;, HTTP_GET, onJSRequest);<br>  server.onNotFound([](AsyncWebServerRequest *request) {<br>    request-&gt;send(LittleFS, &quot;/index.html&quot;, String(), false);<br>  });<br>  server.begin();<br>}<br><br>void ConnectToWebSocket() {<br>  webSocket.begin();<br>  webSocket.onEvent(onWebSocketEvent);<br>}<br><br>void StartMDNS() {<br>  if (!MDNS.begin(&quot;esp8266&quot;)) {<br>    Serial.println(&quot;Error setting up MDNS responder!&quot;);<br>    while(1) {<br>      delay(1000);<br>    }<br>  }<br>  Serial.println(&quot;mDNS responder started&quot;);<br>  MDNS.addService(&quot;http&quot;, &quot;tcp&quot;, HTTP_PORT);<br>}</pre><p>We’re now essentially done with the server portion of things (skipping a few minor details), so long as we update the mesh network and web sockets constantly, and process requests through our DNS server! Let’s shift focus towards building the client-side application.</p><h4>Building the Chat Application</h4><p>The way we’ve set up our network is to bring up a captive portal whenever the user connects to the WiFi. Because our network is served on an IP address of our choosing, it would be difficult for the average user to navigate to that address in a web-browser– so we just make it easier for them by automatically directing them there.</p><p>Going over the code of the frontend doesn’t accomplish much for the purposes of this article: anyone reading should be able to create any application or interface they wish to. Instead, let’s discuss the important parts, namely accessing our browser memory (local storage), setting up &amp; accessing the IndexedDB, and communicating with the network.</p><p>First, let’s store something simple in our local storage: a username. When we connect to the Chat Application, we should have users enter a username so others can see who is messaging them!</p><p>We define the following function and event listener in our “scripts.js” file mounted onto the chip (this assumes we have a form with a “nameField” and an “enter chat room” button):</p><pre>function enterChatRoom() {<br>    const name = document.getElementById(&#39;nameField&#39;).value;<br>    if (name) {<br>        localStorage.setItem(&#39;username&#39;, name);<br>        window.location.href = &#39;chat.html&#39;;<br>    } else {<br>        console.log(&quot;Please enter your name.&quot;);<br>    }<br>}<br><br><br>enterButton.addEventListener(&quot;click&quot;, async function (e) {<br>    e.preventDefault();<br>    enterChatRoom();    <br>    <br>});</pre><p>Now, let’s go over how connect to and setup tables in IndexedDB in the client browser. <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API">IndexedDB</a> is a feature of client-side browsers that allows us to store sizable amounts of structured data. This will be great for our chat server as we can store encrypted or decrypted messages in a table: maintaining a table of usernames, timestamps, and message content.</p><pre>let db;<br>const request = indexedDB.open(&quot;ChatAppDB&quot;, 1);<br>var socket = new WebSocket(&#39;ws://192.168.4.1:1337&#39;);<br><br>request.onerror = function(event) {<br>    console.error(&quot;An error occurred with IndexedDB:&quot;, event.target.errorCode);<br>};<br><br>request.onsuccess = function(event) {<br>    db = event.target.result;<br>};<br><br>request.onupgradeneeded = function(event) {<br>    let db = event.target.result;<br>    let userStore = db.createObjectStore(&quot;User&quot;, { keyPath: &quot;ip&quot; });<br>    userStore.createIndex(&quot;name&quot;, &quot;name&quot;, { unique: false });<br>    let chatStore = db.createObjectStore(&quot;Chat&quot;, { autoIncrement: true });<br>    chatStore.createIndex(&quot;message&quot;, &quot;message&quot;, { unique: false });<br>};</pre><p>Note above how we define multiple functions that handle errors accessing the database, make a request to the database, and finally, create the tables in IndexedDB if they don’t exist yet. Also, note how the WebSocket connects to the IP of the network (192.168.4.1) at the established port (1337) we defined in our backend.</p><p>Let’s now integrate the above with our flow of sending and receiving messages.</p><ol><li>When we load the chat application, we should fetch any existing messages from the database. If the database doesn’t exist, we should create it.</li><li>Any existing messages should be “decrypted” and rendered in our chat window. Again, this assumes that we have written the requisite HTML elements to interact with.</li><li>When we send a message on the frontend, we should send them to the mesh network through the WebSocket. We should also “encrypt” them before doing so.</li><li>Finally, when we receive a message from the server, we should add it to our database, decrypt it, and render it.</li></ol><pre>function fetchAndRenderMessages() {<br>    openDatabase().then(db =&gt; {<br>        const transaction = db.transaction([&quot;Chat&quot;], &quot;readonly&quot;);<br>        const store = transaction.objectStore(&quot;Chat&quot;);<br>        const request = store.getAll();<br><br>        request.onerror = (event) =&gt; {<br>            console.error(&quot;Error fetching messages:&quot;, event.target.errorCode);<br>        };<br><br>        request.onsuccess = (event) =&gt; {<br>            let messages = event.target.result;<br><br>            //console.log(&quot;messages: &quot;, messages);<br>            let decryptedMessages = messages.map(message =&gt; {<br>                const decryptedMessage = JSON.parse(decryptData(message));<br>                return {<br>                    ...decryptedMessage,<br>                    message: decryptedMessage,<br>                    timestamp: new Date(decryptedMessage.timestamp)<br>                };<br>            });<br><br>            console.log(&quot;decrypted: &quot;, decryptedMessages);<br><br>            decryptedMessages.sort((a, b) =&gt; a.timestamp - b.timestamp);<br><br>            decryptedMessages.forEach(msg =&gt; {<br>                renderMessage(msg);<br>            });<br><br>            updateScroll();<br>        };<br>    });<br>}<br><br>socket.onmessage = function(event) {<br>    console.log(&quot;Message!&quot;);<br>    let decryptedData = JSON.parse(decryptData(event.data));<br>    renderMessage({<br>        message: decryptedData,<br>        timestamp: new Date(decryptedData.timestamp)<br>    });<br>    openDatabase().then(db =&gt; {<br>        const transaction = db.transaction([&quot;Chat&quot;], &quot;readwrite&quot;);<br>        const store = transaction.objectStore(&quot;Chat&quot;);<br>        store.add(event.data);<br>    });<br>    updateScroll();<br>}<br><br>window.onload = () =&gt; {<br>    fetchAndRenderMessages();<br>    updateScroll();<br>};</pre><p>The rest of the code for the frontend can be found in the GitHub repository.</p><p>Voilà! Putting this all together, we should have a functioning chat application that only works when connected to our own private, offline mesh network. If you followed the steps in this overview, or simply cloned the linked repository, you should get an app that looks like this! Happy chatting!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FciqS4nS5kKo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DciqS4nS5kKo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FciqS4nS5kKo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c9f4b67389657b541bcfa19acf596a0/href">https://medium.com/media/9c9f4b67389657b541bcfa19acf596a0/href</a></iframe><p>As discussed in the opening remarks, the use cases for an application like this are wide-ranging. This is furthered by the facts that the individual components of the network are very low cost, allowing us to establish large networks with wide coverage.</p><h4>Further Research &amp; Next Steps</h4><p>While we’ve certainly built a lot today, there is still so much more that can be done to improve the safety, resiliency, and abilities of our chat application. Some examples include:</p><ol><li><strong>Better encryption</strong>. We currently use base64 encoding and decoding of messages client side, which is not secure at all– just unreadable to humans.</li><li><strong>Private chat rooms</strong>. Right now, when users connect to the application they all enter one chat room. This has its uses, but most messaging is done in one-on-one settings and smaller groups. Implementing this would require more complex database design and such as: storing private chat encryption keys, different tables for different chats, and a table of available users on the network. We should also be more stringent with which messages are sent to the intended users on the server, as opposed to sending each message to every connected user.</li><li><strong>Route Optimization. </strong>Instead of sending packets around the network across every node, we should ideally route messages more efficiently towards their intended destinations based on things such as traffic demands and network topology. This is quite complex, but could be a great area to explore using machine learning alongside graph-traversal algorithms on top of our network.</li></ol><p>I hope this was as entertaining and informative of a read as this project was for me to build.</p><p>If you have any questions, feedback, or comments please feel free to reach out to me via <a href="https://twitter.com/jmweiner_/">Twitter</a>, <a href="https://www.linkedin.com/in/joshuamaxweiner/">LinkedIn</a>, or by opening an issue on the <a href="https://github.com/JoshWeiner/offline-mesh-network/tree/main">GitHub repository</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9269df3f6a07" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/untangling-the-mesh-an-exploration-of-offline-network-engineering-9269df3f6a07">Untangling the Mesh: An Exploration of Offline Network Engineering</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Predicting the outcome of NBA games with Machine Learning]]></title>
            <link>https://medium.com/data-science/predicting-the-outcome-of-nba-games-with-machine-learning-a810bb768f20?source=rss-ae404173ac9c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a810bb768f20</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Josh Weiner]]></dc:creator>
            <pubDate>Tue, 05 Jan 2021 18:33:33 GMT</pubDate>
            <atom:updated>2022-07-15T14:43:23.533Z</atom:updated>
            <content:encoded><![CDATA[<h4>How we used (and you can too) machine learning to better understand the role statistics play in sports.</h4><p>When deciding on a final project for our Big Data Analytics class, my partners Jack Rosener, Jackson Joffe and I looked to combine an interest in sports with the principles learned throughout the semester. After a few days of discussion, we settled on a project that would aim to predict the outcome of NBA games. While implementing our goal, we found it helpful to distill the project into the following steps with the following questions:</p><ol><li><strong>Scraping Relevant Data</strong> – where do we gather the relevant team and player statistics over several seasons from?</li><li><strong>Cleaning and Processing the Data</strong> – how can we efficiently combine our scraped data so that it is both readable and usable?</li><li><strong>Feature Engineering </strong>— what additional metrics can we append to our datasets that would help any user or ML model to better understand and predict, respectively, outcomes and trends from the data?</li><li><strong>Data Analysis</strong> — can we determine any collinearity or other relations within the data that may better inform our predictions?</li><li><strong>Predictions</strong> – which models and features would be most useful for us in developing an accurate prediction? Do we focus on team or aggregated individuals’ statistics?</li></ol><p>Before we get into the nitty-gritty of our workflow, let’s take a moment to review and acknowledge the other work done on this exact topic. First, in 2013 <a href="https://homepages.cae.wisc.edu/~ece539/fall13/project/AmorimTorres_rpt.pdf">Renato Torres from the University of Wisconsin-Madison</a> set out to accomplish a similar goal as we did and predict specific season outcomes of NBA data using different machine learning models. He used several techniques featured in our project, primarily feature reduction to eliminate multicollinearity from the available data, and also explored different models to explore those with the highest accuracies. Like our project, his selected features included points scored, but unlike our project had a particular focus on win-loss percentage at home and away. (We will explore our feature analysis later.)<br>A lot of other fantastic work on this has been done before and can be read here:</p><blockquote><a href="https://www.researchgate.net/publication/312236952_Predicting_the_Outcome_of_NBA_Playoffs_Based_on_the_Maximum_Entropy_Principle">Cheng, Ge &amp; Zhang, Zhenyu &amp; Kyebambe, Moses &amp; Nasser, Kimbugwe. (2016). Predicting the Outcome of NBA Playoffs Based on the Maximum Entropy Principle</a>.<br><a href="https://library.ndsu.edu/ir/bitstream/handle/10365/28084/Predicting%20Outcomes%20of%20NBA%20Basketball%20Games.pdf?sequence=1&amp;isAllowed=y">Jones, Eri. (2016) Predicting the Outcomes of NBA Games. North Dakota State University</a>.<br><a href="https://towardsdatascience.com/building-my-first-machine-learning-model-nba-prediction-algorithm-dee5c5bc4cc1">Fayad, Alexander. Building My First Machine Learning Model | NBA Prediction Algorithm. Towards Data Science</a>.<br><a href="https://projects.fivethirtyeight.com/complete-history-of-the-nba/#lakers">The Complete History of the NBA. FiveThirtyEight.</a></blockquote><p>Through our research, we found that the best published model had a prediction accuracy of 74.1% (for playoff outcomes), with most others achieving an upper bound between 66–72% accuracy. Most published research, too, focused on predicting playoff scores — which may lend towards biased data: playoff teams are more consistent in a number of stats throughout the regular season, and playoff game expected outcomes likely experience less variance as a result. Critically, note that the upset rate across the entire season in the NBA averages <a href="https://www.oddsshark.com/sports-betting/which-sport-do-betting-underdogs-win-most-often">32.1%</a>. In the playoffs, the upset rate — as defined by teams with a lower regular season record winning— drops to <a href="https://www.theringer.com/nba/2019/4/12/18307008/nba-playoff-momentum">22%</a> (which actually means most NBA-playoff prediction models <em>underperform</em>). Because our project looked to predict the outcome of any NBA game and is playoff agnostic, we were looking to develop a model that could reach and hopefully beat a 67.9% accuracy — and in doing so predict some upsets.</p><p>Feel free to follow along <a href="https://colab.research.google.com/drive/1uohYLF9MRSKdMi-8mhXaewjovbmdo68o?usp=sharing">here</a> or view our files <a href="https://github.com/JoshWeiner/NBA_Game_Prediction">on GitHub</a>.</p><h3>Scraping our Data</h3><p>We scraped our data from available information at <a href="http://synergysports.com/">Synergy Sports </a>— which has extremely detailed team and player data for each game played since the 2008–2009 season. Scraping took several days due to rate-limiting (as we had to query the results of each game over 12 seasons), and was initially compiled into a JSON format and finally saved to csv files.</p><blockquote><strong>Author’s Note:</strong> We accessed data from Synergy Sports with funding from the University of Pennsylvania. As an unfortunate consequence of this, we are not at liberty to provide public access to our dataset. However, we have compiled a list of alternative datasets through which one can replicate and improve upon our data:<br><a href="https://www.basketball-reference.com/leagues/">https://www.basketball-reference.com/leagues<br></a><a href="https://www.kaggle.com/datasets/wyattowalsh/basketball">https://www.kaggle.com/datasets/wyattowalsh/basketball</a><br><a href="https://www.kaggle.com/datasets/nathanlauga/nba-games">https://www.kaggle.com/datasets/nathanlauga/nba-games</a><br><a href="https://www.kaggle.com/datasets/drgilermo/nba-players-stats">https://www.kaggle.com/datasets/drgilermo/nba-players-stats</a></blockquote><h3>Cleaning the Data</h3><p>We now had both player stats and team stats for each NBA season saved as seperate csv files. Our next step was to read in all this data and combine it into two large dataframes: one will containing the player stats for the past 12 seasons, and the other containing the team stats. Once created, we would clean the dataframes to remove invalid statistics (negative minutes) and columns that served little purpose to us (charges taken/committed, for example).</p><p>We then saved these new dataframes to the following csv files, which allowed us (and you) to skip the laborious and lengthy steps of both scraping and cleaning the data when restarting our notebook’s runtime:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc8690435a964db72a6802acf5774771/href">https://medium.com/media/cc8690435a964db72a6802acf5774771/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70c08046c05ba3eec5589a67da4e1e3f/href">https://medium.com/media/70c08046c05ba3eec5589a67da4e1e3f/href</a></iframe><h3>Feature Engineering</h3><p>This is where the fun stuff begins. Our primary goal was to make all of the available data understandable: game-by-game rebounds for an entire team don’t help us much unless we can use that data in a higher-level analysis that leads us to our ultimate goal – predicting wins and losses. To that end, we sought to create five different features which we would use in understanding how our teams progressed and regressed throughout each season:</p><ol><li><strong>Elo Ratings</strong></li></ol><p>This is perhaps the best existing method to relativize NBA team strength and performance over many seasons. The way Elo Ratings are calculated is simple: all teams start at a median score of 1500 and are either given or subtracted points based on the final score of each game and where it was played with weights being given to point difference, upsets, and location. In essence, it’s a more sophisticated win-loss record. Most NBA-prediction models don’t look at Elo Ratings but instead amalgamate a simple win-loss record with several other stats. We wanted to use Elo to appropriately weight quality wins (and losses), while also recognizing that not all teams are created equal.<br>The exact formula is as follows:<br>If 𝑅_𝑖 is the current Elo rating of a team, its Elo rating after its played its next game is defined as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*I3seQH7BtmnrrbFsjI6DWA.png" /><figcaption>We calculate ELO for each team and each game for every season of data that we have.</figcaption></figure><p>Here, <em>S_team</em> is a state variable: 1 if the team wins, 0 if the team loses. E_team represents the expected win probability of the team, which is represented as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*qQcOY9AJ661992Wf9M-NJQ.png" /></figure><p><em>k </em>is a moving constant, dependent on both the margin of victory and difference in Elo ratings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*-eMhTFl7GzKpKqJdXITpXg.png" /></figure><p>It’s also important to note that Elo ratings carry over from season-to-season (as all teams are not created equal, good teams tend to stay good or at least gradually decline — very rarely do teams drop onto or off of the map). If R represents the final Elo of a team in one season, it’s Elo Rating at the beginning of the next season is approximately:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*cgt_EexYKcntM1RIXeCWpQ.png" /></figure><p>We can actually take a look at this metric over time, randomly selecting three teams to view, and immediately see that we can get key insights about the strength of teams throughout seasons:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ENw3eZdgDj6Jfhal4wHPQ.png" /><figcaption>Here we can actually see that Elo Ratings track quite well with teams’ performances in given seasons: the years in which Golden State and Cleveland appeared and dueled in the NBA Finals is apparent by the upper peaks of their Elo Ratings. We can also see what was widely confirmed by most basketball analysts at the time: that the Western Conference was much tougher than the East — as exhibited by the influence of quality wins on Elo for the Warriors versus the Cavaliers. We can also see how far these teams fell quickly after their championship seasons and as they all suffered from roster losses and injuries. (Image by Author)</figcaption></figure><p>2. <strong>Recent Team Performance (Avg. stats over 10 most recent games)</strong></p><p>These are pretty self-explanatory, we are simply looking to average the stats for each team over their last 10 games. To do this we wrote a simple function that would calculate a sliding average for a given team’s stats and a window of n games:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdc886333bfac7e8ef18dc15a3c92e12/href">https://medium.com/media/fdc886333bfac7e8ef18dc15a3c92e12/href</a></iframe><p>After saving this data into a new dataframe, we sought to separate each game (which contains stats for both home and away teams) into its own rows by team, which allows us to group-by and aggregate team stats much more easily and simplifies existing features. Finally, we added a win state-variable column to include the most critical measurement to our project: wins and losses.</p><p>3.<strong> Recent Player Performance (Avg. stats over 10 most recent games)</strong></p><p>We create our player_recent_performance dataframe using similar methods to the above section, this time with individual players as opposed to teams. This created a dataframe of each player’s performance over the past 10 games.</p><p>4. <strong>Player Season Performance</strong></p><p>We also sought to include the average player stats over the entire season: unlike teams, players themselves get injured or fall in and out of the rotation and it’s perhaps more critical for us to understand how player performances in individual games track with their averages. We will use this later in our models to see if it will allow for accurate predictions on the team-level.</p><p>5. <strong>Player Efficiency Ratings (PER)</strong></p><p>Critically, just as we had done with teams via Elo Ratings, we wanted to be able to relativize player performance using a metric that combines seemingly unrelated statistics. Our hope was that we could use <a href="https://bleacherreport.com/articles/113144-cracking-the-code-how-to-calculate-hollingers-per-without-all-the-mess">Hollinger’s Player Efficiency Ratings</a> to compare and predict team performance by the aggregated PER scores of their players. In the NBA, it is easy for players to experience wildly inflated or deflated statistics (such as points per minute) simply by virtue of the amount of playing time they get, against bench players or versus starters, number of games played, or even from outlier performances. We did not want to rely solely on player averages simply because of their ability to skew. PER solves that problem by weighting certain in-game statistics by the inverse of number of minutes played, which creates a metric that defines player performance relative to the number of minutes played.<br>Thus for each player, we added a column for PER in a given game according to the following formula:</p><blockquote>PER = (FGM x 85.910 + Steals x 53.897 + 3PTM x 51.757 + FTM x 46.845 + Blocks x 39.190 + Offensive_Reb x 39.190 + Assists x 34.677 + Defensive_Reb x 14.707 — Foul x 17.174 — FT_Miss x 20.091 — FG_Miss x 39.190 — TO x 53.897) x (1 / Minutes)</blockquote><h3>Data Analysis</h3><p>Our data analysis was centered around the use of Elo Ratings as our test metric. Essentially, could we be confident that Elo correlates with and correctly aggregates other statistics? Furthermore, would it be more appropriate for us to predict game outcomes using team stats (Elo Ratings) or averaged player stats (PER Ratings)?</p><p>First, let’s explore the density of Elo Ratings across the NBA on a per-season basis. This tells us a little about the level of parity across the league: if we can see Elo Ratings approach a normal distribution that would suggest the league’s teams are relatively well-matched. Otherwise, we see large disparities and the development of “super-teams”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQBp4kIV-PgiwMrhso9Mtw.png" /><figcaption>Twelve seasons of league Elo densities. (Image by Author)</figcaption></figure><p>Moving away from an understanding of Elo Ratings from a league-perspective, we endeavored to see how Elo Ratings tracked against an individual team’s performance in other statistics.</p><p>First, we looked to plot the distribution of Elo for a random team against the average number of points scored in recent games:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*Fo0idAMqZZJTLzCvQmu58A.png" /><figcaption>(Image by Author)</figcaption></figure><p>We can actually see from this that there is some correlation between the average number of points a team scores versus its Elo Rating — the higher the average points scored across a window of games the higher the Elo Rating seems to climb. However, we can also see that the Elo may also exhibit a high variance across similar scoring figures. So, to better understand how Elo Ratings track with points scored, we examine how the average points scored compares to season averages across the league – from there we can determine if points scored improves ELO, provided that high scoring is relative to the rest of the league. To do this, let’s look at that same team for the same seasons and plot the distribution of points scored against its opponents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rbWHH37Y-oXci-AHDUYVaA.png" /><figcaption>(Image by Author)</figcaption></figure><p>This confirms our suspicions, as we can see that when the distribution of average points is greater than those of its opponents, or is more concentrated at an equal or higher level, the Elo is higher for those seasons. When the groupings approach an even or lesser value, those seasons’ Elo ratings for the given team are lower. Therefore, average points scored is a alone a solid determinant of predicting game outcomes, but better when <strong><em>relativized</em></strong>. This demonstrated for us that Elo would be a much better determinant in predicting wins for us than points, as it is by design a relative statistic.</p><p>Shifting away from team statistics, we sought to understand if Elo tracks better with player performance than it does team performance. To do this, we took a similar approach to how we plotted Elo Ratings with average points scored for the same random team, this time with PER.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z12X_HVuRa1oZsqt3gzIBg.png" /><figcaption>(Image by Author)</figcaption></figure><p>From the plotted data, we can see that aggregated PER as compared to opponents doesn’t show much of any correlation with the strength of a team as determined by Elo Rating. Instead, points scored translates better — which makes some sense as a player’s efficiency isn’t necessarily tied to scoring the most points — and points scored against opponents is the determinant of winning a game and therefore impacting Elo.</p><p>We can see this further by mapping the Orlando Magic’s mean and median PER ratings against its opponents for the same given seasons, and find that there is almost no relation between team-PER averages or medians and team strength.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66jabhRfKS5YinyFvS10gg.png" /><figcaption>From these and the above plotted distribution, we see that Average PER — while having a slight correlation to Elo Ratings throughout the season — generally show us little about how individual player efficiency impacts team strength when tracked against opponents. (Image by Author)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dGqDRwrNwGnvjpGxZf2VTA.png" /><figcaption>Median PER ratings show even less of a correlation to Elo Ratings throughout a given season. Here we can observe that in winning seasons (2011–12), the Orlando Magic had a lower median PER than its opponents for most games, yet they had their highest Elo Ratings and best record in recent years. (Image by Author)</figcaption></figure><p>From all of our analysis of relativized team versus aggregated player statistics, it looks clear to us that our Elo Rating and its determinants would be better features to train our models on when it comes to predicting the outcome of NBA games.</p><h3>Predicting the Outcome of Games Based on Team Statistics and Elo Ratings</h3><p>Our first step here was to split our data into features and columns. Reading from our dataset, once split, we then used sklearn to randomly split our data into train and test sets with an 80:20 ratio.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbc38bb4bbb1c11a7aca0fa285ef28b8/href">https://medium.com/media/cbc38bb4bbb1c11a7aca0fa285ef28b8/href</a></iframe><p>The first model we aimed to use to predict the outcome of an NBA game was a Logistic Regression model. Unlike a Linear Regression model which predicts outcomes on a range of values between (and sometimes outside) 0 and 1, <a href="https://towardsdatascience.com/logistic-regression-explained-and-implemented-in-python-880955306060">Logistic Regression models</a> aim to group predictions into binary outcomes. Since we are predicting wins and losses, this type of classification suits us perfectly.</p><p>To begin, we used a simple non-parameterized LR model with our team stats and Elo Ratings as parameters using sklearn:</p><p>After playing around with some hyperparameter tuning, we found that using max_iter=131 and verbose=2 slightly improved our initial testing accuracy to 66.95%. Definitely not bad for a non-parameterized model and very close to our desired prediction accuracy. However, we sought to see if we could better tune our hyperparameters to improve our overall accuracy. Essentially, we would try out many combinations of possible hyperparameters on our data to give us the absolute best weights for our LR model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b598b03bbe3cf8fcad61bf1cf30926ee/href">https://medium.com/media/b598b03bbe3cf8fcad61bf1cf30926ee/href</a></iframe><p>We accomplished this using cross-validation: because we only have a vague idea of the parameters we might want to use, our best approach is to narrow our search is and evaluate a wide range of values for each hyperparameter.</p><p>Using RandomizedSearchCV, we searched among 2 * 4 * 5 * 11 * 3 * 3 * 5 * 3 = <strong>59,400</strong> possible settings – and so the most efficient way to do this would be to take a random sample of the values.</p><p>Running our model with the best parameter values of the random samples actually decreased the accuracy of our model to 66.27%, which showed us that while random sampling helped us narrow down our hyper parameter tuning within a distribution, we would have to explicitly check all combinations with GridSearchCV.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/246158662c1a40c7dd5aa079ff303d31/href">https://medium.com/media/246158662c1a40c7dd5aa079ff303d31/href</a></iframe><p>In this case, implementing GridSearch only marginally increased our accuracy with our LR model.</p><p>The second model we looked to implement was a <a href="https://builtin.com/data-science/random-forest-algorithm">RandomForestClassifier</a>, which can be efficiently used for both regressions and classifications. In this case, we will see if the Classifier can build a proper decision tree to determine wins from the given team-stats.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fd8bfb58f38041112c9d555fdf480a6/href">https://medium.com/media/9fd8bfb58f38041112c9d555fdf480a6/href</a></iframe><p>Immediately, we get that the RandomForestClassifier reaches an initial accuracy of 66.95%, which again is pretty good. Like with the LR model, we attempted to tune the hyperparameters to give us more accurate results — first using RandomizedSearchCV.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0ea6d1dd210fc5944d2f4a9baa6249b/href">https://medium.com/media/a0ea6d1dd210fc5944d2f4a9baa6249b/href</a></iframe><p>Unlike with the LR model, we find that RandomizedSearch improves our hyperparameter tuning, giving us a better accuracy of 67.15%.</p><p>Running GridSearchCV in a similar manner to what we did above, we also sought to explicitly test 2 * 1 * 6 * 2 * 3 * 3 * 5 = 1080 combinations of settings instead of randomly sampling a distribution of settings. GridSearch also gave us an improvement from the base RandomForestClassifier, with an accuracy of 67.11%.</p><p>Overall, when running both a LinearRegression and RandomForestClassifier on the team stats and Elo Ratings, we achieved a win-prediction accuracy of <strong>66.95%–67.15%</strong>. For basketball games, which as we established earlier are quite variable in their actual versus predicted results, this is a significant result.</p><h3>Predicting the Outcome of Games Based on Individual Player Statistics and Scoring</h3><p>We then took a different approach to predicting the outcome of a game to see if we can achieve any better perfomance. Using the larger dataset of individual player statistics that we’ve collected, we will train a model to predict how many points a player will score in a given game. We will predict this based on a players average season stats up until the game we are trying to predict as well as their average performance over the past 10 games. We already created this data in the feature engineering section above. We will also make use of Elo ratings in our prediction as well, as presumably the higher rating of the opposing team the less points a player will score. Once we have this model we can predict how many points a team will score in a game by summing the predicted number of points of each individual player will score. With this information we will be able to predict which team will score more points and thus win the game.</p><p>Before we run our models, we need to clean our data slightly. For some games in this dataset, we have the statistics for one teams’ players, but not for the other team — generally only for the first game that other team plays in the season. Thus, we will remove all these games from the dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a61d2b84395ceb521f8f6d1e4a58de0/href">https://medium.com/media/9a61d2b84395ceb521f8f6d1e4a58de0/href</a></iframe><p>Unlike with the above games, we can’t randomly split our data into train and test sets. We are looking to use individual player statistics to predict the final score of a team, thus we must keep all players playing in the same game together. To do this, we will split up our train and test sets by game so players playing in the same game stay together. About 80% of the games will be in the train set and 20% will be in the test set:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/229bcebb322155a4565451e5fae3f443/href">https://medium.com/media/229bcebb322155a4565451e5fae3f443/href</a></iframe><p>Instead of using a Logistic Regression model, for player scoring we will use a Linear Regression model as we are looking to predict a range of possible values (points scored) instead of simply predicting a win or a loss. Our RMSE (Root Mean Squared Error) for all players was 5.56, or the equivalent of each player making or missing around 2–3 baskets game around their averages.</p><p>On the test set, we grouped each team’s predicted scoring for each game and compared it with their actual scoring numbers. Computing the numbers of games won versus the winner based on predicted scoring gave us a ratio of 1483/2528, or an accuracy of <strong>58.66%</strong>. Clearly, and as we realized earlier when looking at PER distributions of teams versus their opponents, aggregated player performance is too variable of a determinant to accurately predict the outcome of games — especially when compared to team performance which tends to be more consistent across games.</p><h3>Conclusions and Future Considerations</h3><p>As avid NBA fans, we felt that creating a model to predict the outcome of NBA games would be an interesting project and taught us a lot about building classifiers for professional sports game outcomes. We were able to utilize many of the concepts learned in our Big Data Analytics class for this project — including scraping, data cleaning, feature analysis, building models and hyperparameter tuning — and want to thank Professor Ives for his fantastic work in teaching throughout the semester.</p><p>Our Random Forest Regression model, with parameters optimized through RandomSearchCV, gave us the highest testing accuracy of 67.15%. It is slightly higher than the Logistic Regression model, and it is much higher than the Linear Regression model based on individual player statistics. Optimizing parameters using GridSearchCV and RandomizedSearchCV was time consuming and computationally costly, and it resulted in only marginal changes in testing accuracy. If we had more time, we’d likely spend less time optimizing parameters and more time selecting a model.</p><p>The best NBA game prediction models only accurately predict the winner about 70% of the time, so our logistic regression model and random forest classifier are both very close to the upper bound of predictions that currently exist. If we had more time, we would explore other models and see just how high of a test accuracy we could get. Some of those candidates include an SGD Classifier, linear discriminant analysis, convolutional network, or a naïve Bayes classifier.</p><p>Hopefully, you enjoyed reading about our work as much as we enjoyed making it — and learned something from it too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a810bb768f20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-the-outcome-of-nba-games-with-machine-learning-a810bb768f20">Predicting the outcome of NBA games with Machine Learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>