<?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 Vishwak on Medium]]></title>
        <description><![CDATA[Stories by Vishwak on Medium]]></description>
        <link>https://medium.com/@vishwakvv29?source=rss-7dc616ccd0f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LWEsjqmgxDak2z5n5UJsbA.jpeg</url>
            <title>Stories by Vishwak on Medium</title>
            <link>https://medium.com/@vishwakvv29?source=rss-7dc616ccd0f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:46:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vishwakvv29/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[Anomaly Detection on Credit Card Fraud]]></title>
            <link>https://medium.com/@vishwakvv29/anomaly-detection-on-credit-card-fraud-3e9b9c4c5976?source=rss-7dc616ccd0f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e9b9c4c5976</guid>
            <dc:creator><![CDATA[Vishwak]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 04:34:51 GMT</pubDate>
            <atom:updated>2023-03-20T04:53:50.944Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Unsupervised Anomaly Detection on Credit Card Fraud</strong></h3><h4>Using Autoencoder and Isolation Forest to detect anomalies on credit card transactions</h4><p>Project by: Aishwarya Rajeev (ar73945), Juhi Patel (jpp2464), Soumith Reddy Palreddy (sp52466) &amp; Vishwak Venkatesh (vv8257)</p><h3>Introduction</h3><p>Anomaly detection is a powerful technique used to identify unusual patterns or outliers in datasets. This technique has numerous applications, from detecting fraud in financial transactions to identifying network intrusions or industrial equipment failures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qFsKLiyLIvJThgc5.png" /></figure><p>In many cases, anomaly detection requires the ability to identify abnormal instances in datasets without any prior knowledge or labelled examples. This is where unsupervised learning techniques come into play. Unsupervised learning algorithms can automatically identify patterns in data without being explicitly told what to look for.</p><p>In this article, we will explore two popular unsupervised anomaly detection techniques: autoencoders and isolation forest. Autoencoders are a type of neural network that can learn to compress and reconstruct data, while isolation forest is a tree-based algorithm that partitions data points and identifies anomalies based on their isolation scores.</p><p>We will start by introducing the concept of anomaly detection and the importance of unsupervised learning in this context. We will then provide a brief overview of the theory behind autoencoders and isolation forest, including their strengths and limitations. Finally, we will illustrate how to implement these techniques in Python using popular libraries such as TensorFlow and Scikit-Learn, and provide examples of real-world applications.</p><p>Whether you are new to unsupervised anomaly detection or an experienced practitioner, this article will provide you with a practical guide to implementing autoencoders and isolation forest in your projects. By the end of this article, you will have a solid understanding of these powerful techniques and their applications in anomaly detection.</p><h3>Dataset</h3><p>The dataset contains transactions made by credit cards in September 2013 by European cardholders. This dataset presents transactions that occurred in two days, where we have 492 frauds out of 284,807 transactions. The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions.</p><p>It contains only numeric input variables which are the result of a PCA transformation. Unfortunately, due to confidentiality issues, we cannot provide the original features and more background information about the data. Features <em>V1, V2, … V28</em> are the principal components obtained with PCA, the only features which have not been transformed with PCA are <em>Time </em>and <em>Amount</em>. <em>Time</em> contains the seconds elapsed between each transaction and the first transaction in the dataset. <em>Amount</em> is the transaction Amount, this feature can be used for example-dependent cost-sensitive learning. <em>Class</em> is the response variable and it takes value 1 in case of fraud and 0 otherwise.</p><p>Most of our analysis and insights will be shown for this dataset.</p><p>We will also compare the model performances on a second dataset. This dataset consists of simulated credit card transactions containing both legitimate and fraudulent transactions. Some of the features include customer demographics, amount and UNIX time of the transaction. This dataset consists of 556k transactions with the fraudulent class accounting for 0.4% of all transactions.</p><h3>Exploratory Data Analysis</h3><p>A quick glance at the counts of the labels will immediately tell us that this is a very imbalanced dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/0*7jegSLUUUqXNXpex" /></figure><p>Next, we can look at the distribution of both classes with respect to time. Using this, we can try to find if there are any time series elements that can be used to identify fraudulent transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AW8BRI0Y5-q6yE5s" /></figure><p>We see that there are times when there are dips in normal transactions. At the same time, we can also observe spikes in fraudulent transactions. This can be some information taken into account by the model.</p><p>Next, let’s look at the boxplot of transaction amount by class. We see that there are too many outliers for the visualization to be meaningful while using amount as is and so we log transform the transaction amount and create another boxplot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-PxwKtuFHGKoldA1" /></figure><p>We can see that normal transactions have a higher mean than fraudulent transactions. However, the interquartile range is wider for fraudulent transactions.</p><p>Next, in an exercise to visualize the structure of this multi-dimensional data and to see if it’s possible to cleanly separate fraudulent &amp; normal transactions, we’ll use t-SNE. t-SNE is a non-linear dimensionality reduction technique which embeds high-dimensional data into a low-dimensional space for easy visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/0*zvxV7-r8sXGaBcy0" /></figure><p>This image is a two-dimensional summary of the entire dataset. We can clearly see certain fraud clusters on the left that can be distinctly separated. However, there are other fraud cases that are intermixed with normal transactions that may be harder to separate.</p><h3>Feature Pre-Processing</h3><p>We scale the data using the StandardScaler function from scikit-learn. There were no correlated features to remove as the dataset’s features were obtained from PCA and hence had little correlation.</p><h3>Modeling</h3><h4>Autoencoders</h4><p>Autoencoders are a type of neural network that can learn to compress and reconstruct data. They have been used for a wide range of applications, from image and speech recognition to anomaly detection and data generation. At their core, autoencoders consist of an encoder network that maps input data to a lower-dimensional representation, and a decoder network that reconstructs the original data from this representation. The goal of training an autoencoder is to minimize the difference between the input data and its reconstructed output, which encourages the network to learn a compact and meaningful representation of the data. We will demonstrate how to implement autoencoders in Python using the TensorFlow library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*vg-X8CW-oJGd0Eoh" /></figure><p>This code snippet shows how to implement an autoencoder using Keras. The code defines the input layer of the model, which specifies the shape of the input data, and the encoder and decoder layers. The encoder layers map the input data to a lower-dimensional representation, while the decoder layers reconstruct the original data from this representation.</p><pre>input_layer = Input(shape=(input_dim, ))<br>encoder = Dense(encoding_dim, activation=&quot;tanh&quot;, <br>                activity_regularizer=regularizers.l1(10e-5))(input_layer)<br>encoder = Dense(int(encoding_dim / 2), activation=&quot;relu&quot;)(encoder)<br>decoder = Dense(int(encoding_dim / 2), activation=&#39;tanh&#39;)(encoder)<br>decoder = Dense(input_dim, activation=&#39;relu&#39;)(decoder)<br>autoencoder = Model(inputs=input_layer, outputs=decoder)<br>autoencoder.summary()</pre><p>The summary shows the model architecture, including the number of trainable parameters and the output shapes of each layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0LSFDxjk_hwAfbn5" /></figure><p>During training, the autoencoder model learns to compress the input data into a lower-dimensional representation, and then reconstruct the original data from this representation. The performance of the model can be evaluated by looking at the training and validation loss values. In our example, the training and validation accuracy both increase over the course of the 10 epochs, which is a good sign that the model is learning and generalising well to new data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*VHIMqiVWb2B11c5J" /></figure><h4>Reconstruction Error</h4><p>After training the autoencoder model, we can use it to generate predictions for the input data and calculate the reconstruction error as a measure of how well the model is able to reconstruct the original data. Since we don’t have any fraud samples in the training set, we can assume that all the samples are normal and use the reconstruction error as a threshold to detect anomalies in the test set.</p><p>Below are the summary statistics of the reconstruction error distribution for the train, test &amp; fraudulent transactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*brAfVLG1GBm-tb5Imm6bkg.png" /></figure><p>We can use these summary statistics to help us set an appropriate threshold value for identifying anomalous data points based on their reconstruction error. This can help us balance the trade-off between false positives and false negatives in our anomaly detection task.</p><h4>Optimizing Reconstruction Error Threshold based on F1 score</h4><p>The reconstruction error is calculated on the test set, and the F1 score is calculated for each reconstruction error threshold from 1 to 50. We chose F1 score because it is a metric that balances precision and recall, providing a more informative evaluation of the model performance than accuracy, especially when the classes are imbalanced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*3RsnX_8C2pFJjWg5" /></figure><p>We see that a threshold of 8 gives the best F1 score of 0.5022.</p><h4>Distribution of the Reconstruction Loss</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/0*73_JYj89JQANg5Ku" /></figure><p>The resulting plot shows the distribution of reconstruction loss values for clean and fraud transactions. The x-axis represents the range of reconstruction loss values and the y-axis represents the frequency of these values. The green bars represent the distribution of reconstruction loss values for clean transactions, while the red bars represent the distribution of reconstruction loss values for fraud transactions.</p><p>We can see that the majority of the clean transactions have a reconstruction loss less than 2, whereas for fraud transactions, the reconstruction loss can be as high as 10. This suggests that the autoencoder is able to reconstruct clean transactions more accurately than fraudulent ones.</p><p>Here, we can see that setting the threshold at 8 and classify any transaction with a reconstruction loss greater than 8 as fraudulent makes sense.</p><h4>Autoencoder Results</h4><p>Below is the obtained confusion matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*LHhEDyJTqH2ijwU7" /></figure><p>We see that while the model does a good job of predicting normal transactions well, it doesn’t do as well on fraudulent transactions as almost half of the actual fraudulent transactions are predicted as normal. However, considering that this was an unsupervised model, it has done well in achieving these results.</p><h4>Isolation Forest</h4><p>Isolation Forest is another unsupervised anomaly detection technique that is based on decision trees. Isolation forests work on the concept that anomalies are few and different. Here, similar to a random forest, randomly sub-sampled data is processed in a tree structure based on randomly selected features. The samples that travel deeper into the tree are less likely to be anomalies as they require more cuts to isolate them. Similarly, the samples which end up in shorter branches indicate anomalies as it is easier for the tree to separate them from other observations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tozLfKWibdmEBPfs.png" /></figure><p>Isolation Forest gives each data point an ‘anomaly score’ based on the depth of the tree required to arrive at that point. This score is an aggregate measure of the depth obtained from each of the individual trees. An anomaly score of -1 indicates anomalies while 1 indicates normal points. To be consistent with this definition, we have also assigned -1 to the fraudulent transactions &amp; 1 to normal transactions.</p><p>Isolation Forest can be implemented in Python using scikit-learn’s ensemble library. Some of the important hyperparameters include:</p><ul><li><strong>n_estimators</strong>: The number of base estimators in the ensemble</li><li><strong>contamination</strong>: The proportion of anomalies on the dataset. We have set this equal to 0.65%, i.e., the percentage of fraudulent cases in the test set</li><li><strong>max_samples</strong>: The number of samples to draw from X to train each base estimator. We have set this to 100%, i.e., each estimator will be trained using all the samples</li><li><strong>max_features</strong>: The number of features to draw from X to train each base estimator. We have set this also to 100%, i.e., each estimator will be trained using all the features</li></ul><p>We’ll show how to implement this in Python with some code snippets.</p><p>First, let’s run the baseline isolation forest model with no hyperparameter tuning to see what results we get. Below is the code snippet to do this:</p><pre>isofo = IsolationForest(max_features = 1.0, max_samples=1.0, bootstrap=False, random_state=22, contamination = PercFraud)<br>y_pred = isofo.fit_predict(X)</pre><p>Using the predictions, we get the F1 score as 0.4533. Let’s try to optimize our model by varying the number of estimators from 500 to 1200 in steps of 50.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/0*bcrMylhHOrOMsz91" /></figure><p>We see that we get the best F1 score of 0.4634 when the number of estimators is 1150.</p><p>Now, we can train the Isolation Forest model with 1150 estimators. In order to better understand the model’s performance, we print the confusion matrix.</p><h4>Isolation Forest Results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/0*4vl-tKGau3o7R_rZ" /></figure><p>Similar to autoencoders, we see that while the model does a good job of predicting normal transactions well, it doesn’t do as well on fraudulent transactions as almost half of the actual fraudulent transactions are predicted as normal. It actually performs worse than autoencoders classifying &gt;50% of actual fraudulent transactions as normal.</p><h4>Summary of results</h4><p>Shown below is the summary of both models’ performance in terms of recall &amp; F1 scores.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*VkOlsnUkwdGZ4NU1nvnkyg.png" /></figure><h4>Comparison with Dataset 2</h4><p>Now, let’s see how well both models perform on the second dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*CAaN-991NKdbfT5DJ33V8g.png" /></figure><p>We can see that the models perform much better on this dataset. Also, autoencoders still perform better than isolation forest. Again, this is to be expected as this dataset is much larger than the previous one. Hence, we can expect neural networks to outperform tree-based models as more and more training data is available.</p><h3>Conclusion &amp; Future Steps</h3><p>Companies can detect anomalies by harnessing the power of AI &amp; ML. In this project, we have explored how unsupervised ML approaches can be used to detect anomalies. Particularly, the two approaches we have looked at are Autoencoders &amp; Isolation Forests.</p><p>Autoencoders are a neural network architecture which compresses data and reconstructs it back. By training autoencoders on normal data, we train the network to represent the normal transactions and so when an anomaly is passed as input, it will have a high reconstruction error.</p><p>Isolation Forests are a decision tree based approach in which anomalies will have a lower average depth compared to normal data points. Here, we can optimize the model by tuning hyperparameters such as the # of estimators to be used.</p><p>In our case, we found that both models performed well given that the training was unsupervised. However, there is scope to improve the performance of these models by more finely tuning the hyperparameters. We could also perform more feature engineering which might make it easier for the models to separate out the anomalies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e9b9c4c5976" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Heartbeat Audio Classification using Deep Learning]]></title>
            <link>https://medium.com/@vishwakvv29/heartbeat-audio-classification-using-machine-learning-305e568efecc?source=rss-7dc616ccd0f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/305e568efecc</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[heart-disease]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Vishwak]]></dc:creator>
            <pubDate>Fri, 09 Dec 2022 01:35:27 GMT</pubDate>
            <atom:updated>2023-01-17T20:10:18.252Z</atom:updated>
            <content:encoded><![CDATA[<h4>Detect abnormal heartbeats using state-of-the-art ML &amp; DL models to flag early onset of heart diseases</h4><p><em>This project was built by </em><a href="https://medium.com/u/f29cbd256b3"><em>Nittala Venkata Sai Aditya</em></a><em>, </em><a href="https://medium.com/u/cfe5b7e2c4c"><em>Gandhi Disha</em></a><em>, </em><a href="https://medium.com/u/e3bdb5cb797e"><em>Saibhargav</em></a><em> Tetali, Vishwak Venkatesh and </em><a href="https://medium.com/u/d850d65edb32"><em>Soumith Reddy Palreddy</em></a></p><h3><strong>Background</strong></h3><p>Let’s have a heart to heart conversation, shall we?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*z1dLwfLvl5h0DtR-.jpg" /><figcaption>Photo from <a href="https://www.hsph.harvard.edu/nutritionsource/disease-prevention/cardiovascular-disease/">Harvard T.H. Chan School of Public Health</a></figcaption></figure><p>Cardiovascular diseases (CVD) are the leading cause of death, accounting for ~29% of all global deaths. More than four out of five CVD deaths are due to heart attacks and strokes, with one-third of these deaths occurring prematurely. These premature deaths can be prevented by identifying those with highest risk of CVDs and ensuring they can receive appropriate treatment.</p><p>Imagine tapping the power of machine learning to classify heart beats as normal or abnormal. Such a method which can detect signs of heart disease in the first level of screening could have a significant impact on world health. This tremendous potential is what drew our team to this project.</p><p>The first level of screening process is now easier with the widespread usage of mobile phones. A person can use apps which can record their heartbeat through the phone’s microphone . We aim to use these audio recordings of a person’s heartbeat to build a machine learning model that can classify whether their heartbeats are normal or abnormal. These updates will ensure that an individual can get timely treatment before the situation spirals out of control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xl-nAUdUv0uKh0cR.jpg" /><figcaption>Phones have made it much easier than before to get early warnings on heart diseases. Photo from <a href="https://echo-uk.org/2021/05/21/mobile-app-record-sound-of-beating-heart/">ECHO</a></figcaption></figure><h3>The Data</h3><p>A challenge associated with this project was to acquire good-quality labeled data. However, heartbeat data from hospitals would not suffice. As our project aims to provide the first level of screening for CVDs by using heartbeat sounds from people’s phones, we wanted our data to also reflect this. Here we encountered our next challenge in finding heartbeat data from this source.</p><p>After spending some time online, we discovered Peter Bentley’s ‘Classifying Heart Sounds Challenge’ which had the data in the exact way we needed. This data came from two sources:</p><ol><li>From a clinical trial in hospitals using a digital stethoscope</li><li>From the public via the iStethoscope Pro iPhone app</li></ol><p>Our dataset consisted of 585 labeled audio files and 247 unlabeled audio files. For the purposes of this project, we used the labeled audios for building the machine learning model.</p><p>There were five major heart sound classes in our dataset. These include:</p><ol><li><strong>Normal</strong> — Strong rhythmic heartbeats with a distinct lub-dub auditory pattern</li><li><strong>Murmurs</strong> — There is a “whooshing, roaring, rumbling or turbulent fluid” between the lub and the dub</li><li><strong>Extra Heart Sound</strong> — Heartbeats sound as though there is a “galloping noise”​</li><li><strong>Extrasystole</strong> — An out of rhythm heart sound usually due to extra or skipped heartbeats</li><li><strong>Artifact</strong> — Basically, not a heartbeat​ and characterized by a wide range of different sounds (feedback squeals and echoes, speech, music and noise)</li></ol><h3>Exploratory Data Analysis</h3><p>The first part of the project was to understand the data and see if we could get any insights for the different heart sounds. For us to classify into normal and abnormal heart sounds, it was imperative that we see if the samples were different enough to segregate any new data coming into normal and abnormal classes.</p><p>We notice some interesting observations from the amplitude waveplots for the different classes shown below:</p><ul><li>The first graph, i.e., the normal heartbeat graph, shows a uniform distribution of amplitudes and consistency between the lubs and dubs of the sound wave</li><li>Compare that to the murmur heart sound, it seems less consistent and has a lot of sound waves coming in between the lubs and dubs. This could be a sign of some whooshing coming in between the lub and dub</li><li>Extrasystole sounds have a much higher amplitude compared to others and there is a lot of irregularity between the different sound waves indicating that there may be a skip of the heartbeat characterized by extrasystole heart waves</li><li>Extrahls graph is also irregular compared to the normal class. It has a few high amplitude sound waves which could signify the galloping sounds characterized from such heart conditions</li><li>Artifact graph just shows the noisy data that one may encounter when they incorrectly try to take a recording. Since one of the data sources is an app, external sounds may have been mistakenly recorded here</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PqO__0QB730bivke" /><figcaption>Amplitude waveplots for each heart sound class</figcaption></figure><p>Now, let’s put all these waveplots together in one figure. We see that extrasystole heartbeat sounds have high amplitudes compared to others and all the different heartbeat classifications have an irregular rhythm compared to the normal heart sounds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*x-xQpHJu9KY1ScyqxGXhQA.png" /><figcaption>Comparing the heart sound classes in one plot</figcaption></figure><p>Next, we decided to look at the class distribution. Looking at the class distribution, it was quite evident that there is a skewness in the frequency of different classes. Normal category heartbeats are the most abundant both in terms of frequency and audio distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IZAWLNaqaj6JwmPG" /><figcaption>Distribution of classes</figcaption></figure><p>It became evident to us that we needed to do something to handle this <strong>class imbalance</strong>. But wait, what is class imbalance and why do we need to handle this?</p><p>In simple terms, <strong>class imbalance</strong> refers to the case when the target variable in a dataset has more observations in one specific class than the others. A model trained on this data would typically be inaccurate because the model receives significantly more examples from one class (‘<strong>Normal</strong>’) which causes it to be biased towards that particular class. It does not learn what makes the other classes <strong><em>different</em></strong><em> </em>and fails to understand the underlying patterns that allows it to distinguish between classes.</p><p>We will discuss our approach to solving this class imbalance under the Modeling section.</p><h3>Data Augmentation</h3><p>With just 585 audio files to train our model, we decided to increase the size of our dataset by generating synthetic data. We followed the two most popular <strong>data augmentation</strong> methods used for audio data:</p><ul><li>Adding noise</li><li>Changing pitch and speed</li></ul><p>The below pictures show the differences between the original audio file and the synthetic audio files. We can see that there are small differences in the waveforms which will make our classifier robust to unencountered data while still retaining the waveforms&#39; general structure which will help in classification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*46JJjTTKfxgk8A0c" /><figcaption>Waveplots comparing original vs augmented audio</figcaption></figure><h3>Feature Engineering &amp; Extraction</h3><p>Our machine learning models cannot understand the audio data if we input them as it is. We need to first extract features from the audio files to convert them into an understandable format.</p><p>You may ask how in the world can you extract features from a sound wave? Isn’t that like too much science? Well, fortunately for us, there are python libraries specially for these purposes. If you ever foray into music and audio analysis, the <strong><em>librosa</em> </strong>package in Python should be your go to. In short, it will give us the below extracted features which give us different information about the sound waves and help us select features which ultimately will benefit our machine learning model.</p><p>You can learn more about librosa library <a href="https://librosa.org/doc/latest/index.html">here</a>.</p><p>The extracted features include:</p><ul><li><strong>ZCR (Zero Crossing Rate)</strong> — The zero-crossing rate (ZCR) is <strong>the rate at which a signal transitions from positive to zero to negative or negative to zero to positive</strong>. Its value has been extensively used in both speech recognition and music information retrieval for classifying percussive sounds.</li><li><strong>Chroma</strong> — Chroma-based features, which are also referred to as “<strong>pitch class profiles</strong>”, are a powerful tool for analyzing music whose tuning approximates to the equal-tempered scale</li><li><strong>MFCC (Mel Frequency Cepstral Coefficients)</strong> — <strong>mel-frequency cepstrum</strong> (<strong>MFC</strong>) is a representation of the short-term <a href="https://en.wikipedia.org/wiki/Power_spectrum">power spectrum</a> of a sound, based on a <a href="https://en.wikipedia.org/wiki/Cosine_transform">linear cosine transform</a> of a <a href="https://en.wikipedia.org/wiki/Power_spectrum">log power spectrum</a> on a <a href="https://en.wikipedia.org/wiki/Nonlinear_system">nonlinear</a> <a href="https://en.wikipedia.org/wiki/Mel_scale">mel scale</a> of frequency. <strong>Mel-frequency cepstral coefficients</strong> (<strong>MFCCs</strong>) are coefficients that collectively make up an MFC</li><li><strong>RMS (Root Mean Square)</strong> — a measure of the audio’s loudness</li><li><strong>Melspectrogram</strong> — a spectrogram with frequencies in mel scale</li></ul><p>Thus, we can see that our features capture audio information in both the time domain (ZCR, RMS) as well as the frequency/energy domain (Melspectrogram).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FqctqXcmTOXvJpFO" /><figcaption>Flowchart of Feature Extraction</figcaption></figure><h3>Data Modelling</h3><p>Now, after we have augmented our dataset by adding synthetic data and extracting the relevant features, we obtain 1755 rows and 162 features. This dataset was split into training and test sets at a 80–20 ratio.</p><p>The following ML models were trained on the training set and their performance evaluated on the test set:</p><h4>Random Forest Classifier</h4><p>Random forest is an ensemble learning method that operates by constructing a multitude of decision trees. For a classification task such as ours, the output of the random forest is a majority vote, i.e., the class selected by most trees. We used this as our baseline model.</p><h4>Light Gradient Boosting Machine</h4><p>Boosting techniques usually outperform bagging techniques (like random forest) as boosting creates a strong classifier from an ensemble of weak classifiers. Hence, we decided to use LightGBM which is much faster to train compared to an ordinary GBM.</p><h4>CatBoost</h4><p>CatBoost is another boosting technique which we decided to implement. This model offers the advantage of supporting categorical features and performs predictions very quickly.</p><h4><strong>Convolutional Neural Network 1-D</strong></h4><p>CNNs are a type of deep learning algorithm which performs really well on audio and image data. We trained two CNNs. The first model consists of 6 layers of ReLU activation functions with the summary shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/0*_cZ1KrFCTeEHUGAI" /><figcaption>Structure of the first CNN model</figcaption></figure><p>In the second CNN model, we removed all the ReLU activation functions and added 2 layers of ‘tanh’ activation functions as a way to introduce some nonlinearity into the model and a ReLU activation layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rKVEtiqzGLQTBgGl" /><figcaption>Structure of the second CNN model</figcaption></figure><p>All five models have been trained both with and without upsampling of the training dataset. Further, we have also explored converting the original multi-class classification problem to a binary class problem. Let’s discuss these two approaches in more detail.</p><h4>What is upsampling?</h4><p>Our approach to solving the class imbalance present in our dataset was through upsampling. <strong>Upsampling</strong> is a procedure where synthetically generated data points (corresponding to the minority classes) are injected into the dataset. After upsampling, the counts of all classes will be almost equal.</p><h4>What’s the purpose of the m<strong>ulti-class to binary class conversion?</strong></h4><p>In the original dataset, we have five classes — all of which are considerably different from one another. So, we wanted to explore how well our model would perform if we instructed it to just classify heartbeats as normal or abnormal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*hd3S1GliTDLIX9f5dCc17A.png" /><figcaption>Conversion from multi-class to binary class</figcaption></figure><p>We make this conversion by taking the results of the multi-class classification of all models. All the ML models we used actually calculate the probability of a heart sound belonging to a particular class and predicts the class with the highest probability. For example, let’s assume that a datapoint has the following multi-class probabilities:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*Tg-RJBa7ItgQv8BpxneZmw.png" /></figure><p>This datapoint will be classified as Normal. When we are viewing this through a binary classification context, we are just adding the probabilities of all the classes except for normal class and treating the resulting sum of probabilities as abnormal class probability. In the case of our example it would be the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*YAFfi-i5SHYJNhovCxubsQ.png" /></figure><p>Now, this datapoint will be classified as Abnormal. One observation to be noted is that a point classified originally as normal class will remain the same if its multi-class probability of normal is higher than 0.5.</p><p>Let’s briefly discuss some of the pros and cons to this approach.</p><h4><strong>Pros:</strong></h4><p>In the case of a datapoint which has similar features as a normal heartbeat but is actually not a normal heartbeat the probability of it being a normal class would be higher than the individual abnormal classes which would lead to misclassification. But when we combine all the abnormal classes the probability of abnormal class will be higher and hence the data point will be classified correctly.</p><h4><strong>Cons:</strong></h4><p>If the classifier is not good at identifying normal class and assign a marginally higher probability to normal class like in the above example the datapoint will be misclassified as abnormal.</p><h3>Results</h3><p>The following table summarizes each model’s multi-class accuracy score on the test set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*gUrmi6CWHpcQwTCSCuZq8Q.png" /><figcaption>Multi-Class Accuracy of each model on test set</figcaption></figure><p>Here are some observations we noted while implementing these models:</p><ul><li>Both Random Forest &amp; LightGBM models have improved in separating the normal class from the abnormal class after it has been fit on the upsampled training data</li><li>CatBoost model performance has degraded when trained on upsampled training data. This might be due to the overfitting happening because of the high abnormal class data size</li><li>CNN Model 2 performed much better than CNN Model 1. This might be because of the non-linearity introduced to the model via the tanh activation function layers</li></ul><p>Below are the results following the multi-class to binary class conversion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*wPs5Is_HCluwbITOiZjh_g.png" /><figcaption>Binary Class Accuracy of each model on test set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*D6T72T5fqORps7NO8PwgBQ.png" /><figcaption>Binary Class F1 scores of each model on test set</figcaption></figure><p>Here, we see that</p><ul><li>CatBoost classifies a high number of datapoints as abnormal which is increasing recall but at a high cost of decrease in precision and accuracy</li><li>CNN Model 1 is just classifying all test data points as abnormal which would lead 100% recall but very low precision, F1 score and binary accuracy. Hence, this model would not be useful if we have a high cost of misclassifying a normal heartbeat as abnormal</li><li>CNN Model 2 achieved the highest F1 score compared to all the models used</li></ul><p>As our CNN Model 2 gave the best performance, let’s take a closer look at its confusion matrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*OEsPCScfR-610PTtAdJgpg.png" /><figcaption>Multi-class and binary confusion matrices before upsampling</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*TFg6c4gzLlyHuQbtzM9pCA.png" /><figcaption>Multi-class and binary confusion matrices after upsampling</figcaption></figure><p>For the sake of completeness, we also plotted the ROC-AUC &amp; the Precision-Recall curves for all the trained models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*eK2X5GBBd0Rqw7MyBtqYHw.png" /><figcaption>ROC-AUC curve — before (left) &amp; after upsampling (right)</figcaption></figure><p>Here, we can notice that CNN Model 2’s curve is closer to the ideal point (0,1) compared to other curves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*p4LKDd4B9rH6ov49UmkUrA.png" /><figcaption>Precision-Recall curve — before (left) &amp; after upsampling (right)</figcaption></figure><p>On the upsampled training data, we see that CNN Model 2’s curve maintains a precision of 1 until the recall reaches a value of a little more than 0.5 and then remains higher than the other models’ curves.</p><h3>Conclusion</h3><p>Let’s recap what we’ve done so far, shall we?</p><p>First, we started off this project hoping to harness the power of Machine Learning to detect the early onset of heart disease. We then discovered a dataset with audio recordings of normal and abnormal heartbeats to which we injected synthetic data. Next, we extracted relevant features from this augmented dataset to make our data understandable to our ML models.</p><p>We trained and implemented five ML models — on multi-class as well as binary classification — before and after upsampling to understand which model would perform best.</p><p>LightGBM and CNN-1D Model 2 performed the best after upsampling the training data. But, LightGBM did not perform well before upsampling. Although we had other models with similar accuracy scores, CNN Model 2 outperforms other models in all aspects like F1 scores, ROC-AUC and the Precision-Recall curves.</p><p>Hence, the CNN 1-D Model 2 with the tanh activation functions performed best for this problem.</p><h3>Next Steps</h3><p>In the future, we would look into improving the CNN model further and exploring other methods to treat class imbalance. We have already seen how adding non-linearity and upsampling have affected model performance. There is scope to improve upon this.</p><p>Another venture worth looking into would be to obtain better data. The dataset used for this project involved the heartbeats being recorded physically (either through a stethoscope or a mobile). As a result, data quality may be affected by factors like improper positioning of the device, noise caused by the device brushing against clothes, etc. We would like to explore this project further with data obtained through non-invasive technologies (like lasers).</p><p><strong><em>If you’d like to take a look at the data and the code, feel free to check it out </em></strong><a href="https://github.com/GandhiDisha/Heart-Beat-Audio-Classification"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Let us know your thoughts on this!</em></strong></p><h3>References</h3><ol><li>Dataset — <a href="http://www.peterjbentley.com/heartchallenge/">http://www.peterjbentley.com/heartchallenge/</a></li><li>National Library of Medicine — <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8229456/">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8229456/</a>​</li><li>Librosa Documentation —<a href="https://librosa.org/doc/latest/index.html">https://librosa.org/doc/latest/index.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=305e568efecc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How can we leverage ML to predict NBA Championship odds?]]></title>
            <link>https://medium.com/data-science/how-can-we-leverage-ml-to-predict-nba-championship-odds-56290e9870e4?source=rss-7dc616ccd0f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/56290e9870e4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[nba]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[predictions]]></category>
            <dc:creator><![CDATA[Vishwak]]></dc:creator>
            <pubDate>Sun, 29 Nov 2020 10:58:39 GMT</pubDate>
            <atom:updated>2020-12-11T19:18:33.220Z</atom:updated>
            <content:encoded><![CDATA[<h4>An exercise to identify key contributing factors towards winning championships, determine contenders vs non-contenders and more</h4><h3><strong>Introduction</strong></h3><p>The NBA offseason is a wild time. There is a ton of volatility from players moving between teams and raw rookies coming in from college to coaching changes and entire front office shakeups. These moves keep the basketball universe on edge. After all, these moves are executed by teams with the ultimate goal of winning an NBA championship.</p><p>While many pundits and bookmakers tout their picks for the champion during the offseason itself, I have a different idea in mind.</p><p>A better time to predict champions would be before the playoffs begin. A full season of 82 games grants enough time for teams to build chemistry and improve their rosters through mid-season trades. With this thought process in mind, I set about trying to build a machine learning model that could accurately predict who would win the championship.</p><h3>Data Overview</h3><p>The dataset consists of the following data for each team dating all the way back to the 1979–80 season. The dataset is of size 1104 x 12.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*2XnahDcPV2ECaZxK2oU6nw.png" /><figcaption>A sample of the training set</figcaption></figure><p>We can classify the columns shown above into one of four categories:</p><ol><li><strong>Team Information</strong>: Year and Team keep track of the individual rows.</li><li><strong>Team Composition Strength</strong>: The columns from MVP — All Defense measure team strength purely based on its roster. For example, the 2019 Golden State Warriors had 2 MVPs on their roster (Steph Curry &amp; Kevin Durant), so the value under their MVP column is 2.</li><li><strong>Team Performance Strength</strong>: Win % conveniently aggregates several quantifiable performance metrics (Offensive Rtg, Defensive Rtg, etc.) as well as intangibles (Team Chemistry, Synergy).</li><li><strong>Champion</strong>: The million-dollar question — whether a team won the title or not. This field is the target variable for the machine learning model.</li></ol><h3>Unbalanced Dataset</h3><p>Before we can go ahead and build a classification model on this data, we need to understand the problems caused by using an <strong>unbalanced dataset</strong>.</p><p>Well, what is an <strong>unbalanced dataset</strong>? In simple terms, an unbalanced dataset is one in which the target variable has more observations in one specific class than the others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*m0sDHtOGNS_kAajidY-BXA.png" /><figcaption>Comparison between Balanced &amp; Unbalanced Datasets</figcaption></figure><p>In our case, we see that the number of records where teams haven’t won a championship is almost 25 times that of where teams have won one.</p><p>Using the training set as is would result in an inaccurate model because the algorithm receives significantly more examples from one class (‘<strong>Not Winning</strong>’) which causes it to be biased towards that particular class. It does not learn what makes the other class <strong><em>different</em></strong><em> </em>and fails to understand the underlying patterns that allow us to distinguish classes.</p><h3>Balanced Random Forest</h3><p>While there are multiple statistical methods (under-sampling majority class, over-sampling minority class, etc.) to deal with an unbalanced dataset, Python, fortunately, provides a library to deal with this specific problem.</p><p>The library <strong><em>imbalanced-learn </em></strong>offers several re-sampling techniques as well as ensemble classifiers such as <strong>Balanced Random Forest </strong>to deal with unbalanced datasets. Balanced Random Forest tackles this problem by down-sampling the majority class such that the classification tree runs on a subset of the training data which is balanced.</p><p>Now, after we generate training and test sets by performing a 75/25 split on the original dataset, we can run the Balanced Random Forest classifier on the training set.</p><h3>Feature Importance</h3><p>After training the Balanced Random Forest classifier on the training set, we can see which features contribute most towards winning a championship.</p><p>A method of the Balanced Random Forest classifier called <strong><em>feature_importances_ </em></strong>quantifies the importance of features. A higher value indicates that this feature is more important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*qdZ83AJg6L73q5FJAW0R6A.png" /><figcaption>Feature importances</figcaption></figure><p>We can see that the most critical factor is Win % which is a measure of how well the team has performed over the season. The next factor is having an MVP on their team. After these two factors, we see the best offensive and defensive players in the league contribute towards winning it all as well.</p><p>In a nutshell, a superstar loaded team that wins many games is more likely to win a championship compared to a team that wins the same number of games but has no superstars.</p><h3>Evaluating the classifier</h3><p>Now that we have trained the classifier and seen which features are most important, it is time to check if the classifier is any good.</p><p>A very intuitive way of checking the performance of any classifier is by its ROC (Receiver Operating Characteristic) curve and its AUC (Area Under Curve). We can also compare these parameters with that of a baseline model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*3n8P8PcVALkB3g4jtY2W3g.png" /><figcaption>ROC Curve for the classification model</figcaption></figure><p>Without diving into the theory behind ROC curves, it suffices to say that a classifier performs better if it has higher AUC. In this case, the baseline model has an AUC of 0.5 while our model has a much higher <strong>AUC </strong>of <strong>0.95</strong>.</p><p>We can also look at the confusion matrix to calculate Precision and Recall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*LAv1tJon6DHRFBBvL1h3tA.png" /><figcaption>Confusion matrix for the classifier</figcaption></figure><p>Using the confusion matrix, we get <strong>0.9 </strong>as <strong>Recall </strong>and <strong>0.24 </strong>as <strong>Precision</strong>. The Precision of the classifier is low because it identifies multiple potential championship-winning teams. This behaviour resembles real life where we pick more than one team to win it all at the end of the regular season. So we need not try to optimize Precision.</p><h3>Predictions</h3><p>Now that we have completed the model building and its evaluation, let’s dive into what the model predicts.</p><p>Firstly, let’s look at how the winning probabilities vary for the teams that actually won the title over the years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsJPQJQJsP0Hkea38i-12g.png" /><figcaption>Champions’ winning probabilities over the years</figcaption></figure><p>We can take away some fascinating stuff from this plot:</p><ul><li>Teams that went to win it all have a median winning probability of 0.96 — implying that great teams with a lot of wins at the end of the regular season have a very high chance of winning the championship.</li><li>A glaring outlier to this trend is the 1981 Boston Celtics. This team consisted of very young soon-to-be Hall of Fame superstars in Larry Bird, Kevin McHale and Robert Parish. As these players were at the time, still unproven, their winning probability is low.</li><li>The 2019 Champions, the Toronto Raptors, had the second-lowest probability among champions to win a title. They went on to beat two superior teams in the Milwaukee Bucks and the Golden State Warriors to win it all.</li><li>The 1996–98 Chicago Bulls led by Michael Jordan had the best three-year stretch by any teams that won championships consecutively.</li><li>The classifier predicts the 2015 Golden State Warriors to have a 100% chance to win. This prediction is a bit surprising considering that the Warriors were arguably a much better team in the subsequent seasons.</li><li>The 2000s had multiple teams with lower than average winning probabilities go on to win it all. Standing out is the 2004 Detroit Pistons who are renowned for winning without a true superstar.</li></ul><p>Next, we can run a <strong>K-Means Clustering</strong> algorithm on every team’s winning probabilities to identify distinct groups within which each team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZ2fuUSz308G5qssqtqdmw.png" /><figcaption>Scatter plot of every team’s winning probabilities (<strong>Note- * indicates the team won a championship that year</strong>)</figcaption></figure><p>We see that every team falls into one of four distinct clusters. These clusters indicate (from top to bottom):</p><ol><li><strong>Title Contenders</strong> — Teams that are heavily favoured to win a championship in that year. These teams typically have multiple superstars and rank near the top in wins.</li><li><strong>Dark Horses</strong> — These are great teams that have the potential to beat title contenders and go on to win the championship.</li><li><strong>Middle of the Pack</strong> — Decent teams with good players and a good number of wins but nowhere near to properly contend for a title.</li><li><strong>Bottom-dwellers</strong> — These are bad teams with not many good players and losing records.</li></ol><p>Based on this clustering, we can simplify the first two clusters into “Contenders” and the next two into “Non-Contenders”.</p><p>After doing this, we can find out which teams have been title contenders for the most amount of time from 1980 onwards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1OwxxaSacTLRKKTQaYeBMA.png" /><figcaption>Plot showing how long teams have been contending</figcaption></figure><p>The above figure shows each team and what percentage of the time they have been contenders. The bigger the area of the rectangle, the longer the team have been contenders.</p><p>From this, we can take away some observations:</p><ul><li>The Los Angeles Lakers and San Antonio Spurs were in title contention for more than 50% of the time. This incredible consistency was possible due to the team drafting a young superstar along with smart team-building around the superstar. This ensured that the team would be competitive almost always.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sPzJLU8ukxEII-b9" /><figcaption>Photo by <a href="https://unsplash.com/@thevoncomplex?utm_source=medium&amp;utm_medium=referral">Mike Von</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ul><li>Other teams like the Chicago Bulls and the Boston Celtics also enjoyed success led by their all-time great players but dropped off rapidly after these players retired.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iATApfAT4zOO2kYh" /><figcaption>Photo by <a href="https://unsplash.com/@thevoncomplex?utm_source=medium&amp;utm_medium=referral">Mike Von</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ul><li>Apart from a few years, most of the other teams were not in title contention. Multiple factors such as poor drafting, injuries and a lack of culture might explain why these teams never becoming quite good enough.</li></ul><h3>Learnings and Takeaways</h3><p>What started as an exploratory exercise to predict the chances of a team winning a championship led to several learnings and takeaways for me:</p><ul><li>Understood how unbalanced datasets adversely impact the accuracy of a classifier and learnt methods to resolve this issue.</li><li>Learnt additional ways to evaluate classifiers which were extremely useful in this situation.</li><li>Implemented K-Means Clustering algorithm to identify clusters which helped to distinguish contending teams from non-contending teams</li><li>Spotted a few reasons why some teams remain contenders for a long time and why others don’t.</li></ul><p>Before concluding, a final note — my method of measuring Team Composition Strength does not take into account age, injuries and lower productivity. I believe that by correcting this, the classifier would be even more powerful.</p><p><em>Python code — </em><a href="https://github.com/vishwak-29/NBA-Championship-Odds-Prediction/blob/main/NBA%20Championship%20Odds%20Prediction.py"><em>https://github.com/vishwak-29/NBA-Championship-Odds-Prediction/blob/main/NBA%20Championship%20Odds%20Prediction.py</em></a></p><p><em>All data collected from Basketball-Reference.</em></p><p><em>If you enjoyed reading this, be sure to like and share this with all your friends.</em></p><p><em>If you have any thoughts/inputs, connect with me on </em><a href="https://www.linkedin.com/in/vishwak-venkatesh/"><em>LinkedIn</em></a><em> here.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56290e9870e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-can-we-leverage-ml-to-predict-nba-championship-odds-56290e9870e4">How can we leverage ML to predict NBA Championship odds?</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>
        <item>
            <title><![CDATA[Little Known Trends in NBA Champions You Didn’t Know About]]></title>
            <link>https://medium.com/analytics-vidhya/little-known-trends-in-nba-champions-you-didnt-know-about-5f0ebcb69106?source=rss-7dc616ccd0f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f0ebcb69106</guid>
            <category><![CDATA[nba]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[trends]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[basketball]]></category>
            <dc:creator><![CDATA[Vishwak]]></dc:creator>
            <pubDate>Sun, 06 Sep 2020 11:58:50 GMT</pubDate>
            <atom:updated>2020-09-18T14:00:28.669Z</atom:updated>
            <content:encoded><![CDATA[<h4>A deep dive into NBA history to identify new trends</h4><p>Months after the coronavirus pandemic shut down the league, the NBA has returned with the playoffs already in full swing. These playoffs will be one for the ages with the winners probably being titled “Corona Champs” (catchy, isn’t it?). Speaking of winners, these playoffs are the first time in a while that does not have a clear cut title favourite.</p><p>Following a dominant half-decade long stretch by the Golden State Warriors, these playoffs do not have a heavy favourite. Sure, the Los Angeles Lakers and the Los Angeles Clippers are top contenders. However, in the current landscape, other teams such as the Milwaukee Bucks, Boston Celtics, Houston Rockets, Miami Heat and the defending champs, the Toronto Raptors also have a shot at winning it all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cEeUkGD50BiZu85l.jpg" /><figcaption>LeBron James and Kawhi Leonard look to lead their teams to the title</figcaption></figure><p>This got me thinking — considering the very different rosters of each contender, what types of players have teams historically needed to win a championship? How strong have championship teams been through the years? What position does a star player need to play for the team to have a better chance of winning it all? These are some of the questions I will attempt to answer here.</p><h3>Getting started</h3><blockquote>“One man can be a crucial ingredient on a team, but one man cannot make a team” — Kareem Abdul-Jabbar</blockquote><p>Kareem makes an excellent point but teams <strong><em>do</em> </strong>need superstars to win championships. I decided to look at the awards players win each season to understand if a player is a star or not.</p><p>The awards I have chosen to keep track of are:</p><ul><li><strong>MVP</strong> — Most Valuable Player.</li><li><strong>All-NBA</strong> — The 15 best players that season.</li><li><strong>DPOY</strong> — Defensive Player of the Year</li><li><strong>All-Defense</strong> — The ten best defenders that season.</li><li><strong>All-Star</strong> –Generally the best 20–25 players each season.</li><li><strong>6MOY</strong> — Sixth Man of the Year.</li><li><strong>MIP</strong> — Most Improved Player.</li><li><strong>ROTY</strong> — Rookie of the Year.</li></ul><p>By knowing whether a player has won an award or not, I get an idea of whether that player is a superstar or not. I created a “<strong><em>Player Score</em></strong>” by using this formula:</p><blockquote><strong>Player score=MVP + All-NBA+ DPOY + All-Defense + All-Star + 6MOY + MIP +ROTY</strong></blockquote><p>After gathering each championship roster from 1980 onwards, I kept track of which awards a player won <strong><em>before or during </em></strong>the championship season. If a player has won an award, I am counting it as a ‘1’, otherwise ‘0’.</p><p>The reason for counting awards only <strong><em>before or during </em></strong>the championship season is simple. Let me explain with an example:</p><p>Kobe Bryant won a title in his fourth season. At the time, he was still developing into the superstar he would later become. If we consider his entire career achievements for this title, that would provide a skewed picture of the champion’s strength.</p><p>Adding all the player scores gives us the “<strong><em>Champion Score”</em></strong>. This also gives us an idea of how “stacked” a team was.</p><p>After analyzing this data, I discovered some interesting stuff. Let’s look at them, shall we?</p><h3>How has the strength of champions varied over the years?</h3><p>Some interesting things to unpack through the 80s and 90s:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*th1xsGpO2qfiH6U--BrnPQ.png" /><figcaption>Variation of Champions Scores from 1980–1999</figcaption></figure><ul><li>The 80s remain the peak of super teams. Both the Boston Celtics led by Larry Bird and the Los Angeles Lakers of Magic Johnson had some of the highest scores among all 40 championship teams. These two teams also won 8 titles in 9 years demonstrating the influence of superstars to attain the trophy.</li><li>The 1986 Boston Celtics is the most “stacked” championship-winning squad throughout these 40 years.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YLKl-94NicY9rIk7" /><figcaption>Boston and Los Angeles feuded throughout the 80s led by their superstars</figcaption></figure><ul><li>NBA fans remember how one man named Michael Jordan bulldozed through the 90s. Interestingly, his teams weren’t as star-studded as the teams of the 80s!!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*kE94zmhsubiThVch" /><figcaption>Sometimes, all you need is just one man.</figcaption></figure><p>Some fascinating stuff is seen here in the 00s and 10s:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*no_fiP5ttxu5g63I-EyFRQ.png" /><figcaption>Variation of Champions Scores from 2000–2019</figcaption></figure><ul><li>The 2000s features the lowest score by a championship team. These were the 2004 Detroit Pistons most famously known for being the only title-winning team with no superstars. The Pistons prove that a robust team with no superstars and excellent chemistry can also (albeit very rarely) go on to win a title.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6CoooY82zLbn7fj9.jpg" /><figcaption>The 2004 Pistons won the championship without any superstars</figcaption></figure><ul><li>For most of the 2010s, two different dynasties — the Miami Heat and the Golden State Warriors ran roughshod over the league. Not surprisingly, their teams also show up as some of the most “stacked” teams in history.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*OTdWjDb-zT_TlORO" /><figcaption>The Heat and the Warriors were some of the most dominant teams ever.</figcaption></figure><h3>How has the value of positions changed over the years?</h3><p>Basketball has five positions. However, for the sake of this analysis, I am simplifying them into three:</p><ul><li><strong>Guard </strong>— The primary ball-handler/floor general in a team (a la Stephen Curry, Magic Johnson)</li><li><strong>Wing </strong>— Taller than guards but shorter than bigs, they can score, handle, rebound and defend (think LeBron James, Michael Jordan)</li><li><strong>Big </strong>— The tallest players in a team. They mainly operate near the basket (like Shaquille O’Neal, Tim Duncan)</li></ul><p>Generally, an easy way to identify the best player in a championship team is the player who wins Finals MVP. Let’s see which positions have won the most Finals MVP through the decades.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*P2NhpJ75U6WpWMSAWP7Q-w.png" /><figcaption>Number of Finals MVP wins across positions</figcaption></figure><p>Let’s look at this closer, shall we?</p><ul><li>Wings have almost always been the best players on title-winning teams.</li><li>Wings have won an absurd<strong> 9 out of 10 Finals MVPs</strong> in this decade</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*eBBDhJmdvS9Ts1ez" /><figcaption>LeBron James, Kevin Durant and Kawhi Leonard have won 7 out of 10 Finals MVPs this decade</figcaption></figure><ul><li>Bigs have been best players in a title-winning team mostly in the 90s and the 00s but have dropped off since then.</li><li>Apart from a few years in the 80s and the 00s, this award has mostly eluded Guards.</li></ul><p>However, just looking at the best player doesn’t give us context on who the other superstars on the team are. Therefore, I looked at the scores of each position throughout the decades.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*LPk0gk5VEVc80fi8mpPeoA.png" /><figcaption>Player scores across positions</figcaption></figure><p>Now, this gives us a little more context:</p><ul><li>Despite not winning Finals MVP, Bigs have dominated title-winning teams from the 80s with their importance peaking in the 2000s. Their value has dropped off in the 10s, but they are still valuable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GBwW27BSFGntXtqx" /><figcaption>Tim Duncan and Shaquille O’Neal dominated much of the 2000s</figcaption></figure><ul><li>Wings have been important contributors to title-winning teams in the 80s and 90s. After seeing a brief drop-off in the 00s, they have rebounded tremendously to be the most valuable position in the current NBA.</li><li>Historically, title-winning teams have not relied much on guards. However, their importance has increased a lot this decade.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qe6uHEvX_cF3cZl5.jpg" /><figcaption>Stephen Curry and Kyrie Irving were key players for their teams during their title victories</figcaption></figure><h3>Takeaways</h3><p>Historically, teams have indeed relied on superstars to win championships. Modern superteams like the<strong> Golden State Warriors</strong> and the <strong>Miami Heat</strong> are followers of the same principle that the <strong>Boston Celtics</strong> and the <strong>Los Angeles Lakers</strong> of the 1980s followed — when it comes to superstars, the more, the merrier.</p><p>However, it is also possible to win with just one transcendent player. The <strong>Chicago Bulls</strong> of the 1990s and the <strong>San Antonio Spurs</strong> of the 2000s prove this.</p><p>The position a superstar plays also weighs heavily on the team’s winning chances. Just having a superstar big man was enough for a long time until this decade.</p><p>With floor spacing and accurate shooting proving increasingly valuable in the current NBA, <strong>wings who can do everything</strong> from shooting and passing to defending and rebounding are the cornerstones for any contending team.</p><p><em>If you enjoyed reading this, be sure to like and share this with all your friends.</em></p><p><em>Which teams in the current NBA do you think has the best shot at winning a championship? Let me know your thoughts in the comments.</em></p><p><em>If you’d like to reach out to me, connect with me on </em><a href="https://www.linkedin.com/in/vishwak-venkatesh/"><em>LinkedIn</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f0ebcb69106" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/little-known-trends-in-nba-champions-you-didnt-know-about-5f0ebcb69106">Little Known Trends in NBA Champions You Didn’t Know About</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>