<?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 Olutayo Benson-Oladeinbo on Medium]]></title>
        <description><![CDATA[Stories by Olutayo Benson-Oladeinbo on Medium]]></description>
        <link>https://medium.com/@olutayobenson96?source=rss-439a2d527fac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3vW8j3yz9ggOoqBn</url>
            <title>Stories by Olutayo Benson-Oladeinbo on Medium</title>
            <link>https://medium.com/@olutayobenson96?source=rss-439a2d527fac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 18:10:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olutayobenson96/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[Unveiling the Power of Deep Learning in Brain Tumor Classification: An Exploration of CNN and…]]></title>
            <link>https://medium.com/@olutayobenson96/unveiling-the-power-of-deep-learning-in-brain-tumor-classification-an-exploration-of-cnn-and-e5ce22e8e08a?source=rss-439a2d527fac------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5ce22e8e08a</guid>
            <dc:creator><![CDATA[Olutayo Benson-Oladeinbo]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 21:52:14 GMT</pubDate>
            <atom:updated>2023-02-03T21:52:14.134Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unveiling the Power of Deep Learning in Brain Tumor Classification: An Exploration of CNN and Transfer Learning(VGG-16) Techniques</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*qcQvTDTWzLxKKTa4lnswPQ.jpeg" /></figure><p><strong>Introduction</strong></p><p>Brain tumors are a dangerous and life-threatening ailment, affecting millions of people worldwide. The early diagnosis of brain tumors is crucial for effective treatment and improved patient outcomes. One of the most commonly used diagnostic tools for brain tumors is magnetic resonance imaging (MRI). However, manual interpretation of these images is time-consuming and prone to human error.</p><p>Enter deep learning and transfer learning. With the advancement of technology, these cutting-edge techniques have revolutionized the field of medical imaging and made the classification of brain tumors much more accurate and efficient. In this article, we will delve into the world of deep learning and transfer learning and explore their potential in the classification of brain tumors using MRI images.</p><p><strong>Dataset</strong></p><p>The dataset used in this study is a compilation of three datasets, namely figshare, SARTAJ dataset, and Br35H. It comprises 7022 MRI scans of the human brain, which have been categorized into four classes: Meningioma, Notumor, Pituitary, and Glioma. The images for the Notumor class have been sourced specifically from the Br35H dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TrFL_5XjTDTUVgLqZ-oD_Q.jpeg" /></figure><p><strong>Notumor</strong></p><p>Notumor is a term used to describe the absence of a tumor in medical imaging, specifically in brain MRI scans. It is commonly used to categorize brain MRI images that show no signs of a tumor or abnormal growth, indicating a healthy state of the brain.</p><p><strong>Meningioma</strong></p><p>Meningioma is a type of brain tumor that arises from the protective membranes (meninges) that surround the brain and spinal cord. Meningiomas are typically slow-growing tumors and are often benign, meaning they are not cancerous. However, depending on their size, location and rate of growth, meningiomas can cause a variety of symptoms, including headaches, seizures, vision problems and memory loss. Meningiomas are commonly diagnosed using medical imaging techniques such as MRI or CT scans. In the context of medical imaging analysis and diagnosis, Meningioma is one of the possible outcomes or classifications of a brain MRI scan.</p><p><strong>Pituitary</strong></p><p>Pituitary refers to a small endocrine gland located at the base of the brain, just below the hypothalamus. This gland is responsible for producing and secreting hormones that regulate important physiological processes such as growth, metabolism, and reproductive function. The pituitary is commonly referred to as the “master gland” because it controls the activity of other endocrine glands throughout the body.</p><p><strong>Glioma</strong></p><p>Glioma is a type of brain tumor that originates from the supportive tissues of the brain, known as glial cells. Gliomas can be benign (not cancerous) or malignant (cancerous), and they can grow and spread quickly, invading nearby brain tissue. Gliomas are the most common type of brain tumor and can occur in people of all ages. Symptoms of a glioma may include headache, seizures, nausea, vomiting, and changes in personality or vision. The exact cause of gliomas is unknown, but risk factors may include exposure to certain chemicals and a family history of brain tumors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*9sYUdONIf67MXAe8kA3HZg.jpeg" /></figure><p><strong>Project Objectives</strong></p><ol><li>To classify brain tumor MRI scans into different classes (meningioma, notumor, pituitary, and glioma) using deep learning algorithms.</li><li>To implement transfer learning with the VGG-16 model to improve the accuracy of the model.</li><li>To compare the performance of a custom model and the transfer learning model.</li><li>To evaluate the models using various performance metrics such as accuracy, precision, recall, and AUC-ROC curve.</li><li>To deploy the best performing model as a user-friendly web application.</li><li>To investigate the effect of different pre-processing techniques on the performance of the models.</li><li>To explore the potential of deep learning in medical imaging and its impact on the diagnosis of brain tumors.</li></ol><p>You can find the analysis <a href="https://github.com/TeewhyB01/BrainTumorMRIClassification">here</a></p><p><strong>Library Import</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ydNaaWr3WrWSmOGhbut2Hg.jpeg" /></figure><p><strong>Preprocessing Steps</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z71PaK2-EZjSMmjQVKcOYw.jpeg" /></figure><p>The code defines two lists for training data and labels (X_train and y_train) and two lists for testing data and labels (X_test and y_test). The for loop with the first i iterates over the labels (meningioma, notumor, pituitary, glioma) and the second for loop with j iterates over the images in the corresponding folder path.</p><p>The folder path is constructed using the os.path.join function, with root_path and &#39;Training&#39; or &#39;Testing&#39; as the first two arguments, followed by the label i which defines the subfolder name. The os.listdir function is used to list all the filenames in the folder path.</p><p>The cv2.imread function is used to read the image, and the cv2.resize function is used to resize the image to the specified height and width which in this case is 150,150 respectively. The image is then appended to the corresponding X_train or X_test list, and the label i is appended to the corresponding y_train or y_test list. The tqdm function is used to display a progress bar for the for loop, allowing the user to track the progress of the loop.</p><p>The X_train and y_train is then converted into a numpy array and normalized. The labels where encoded using LabelEncoder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sc-1bszW31h8B2aKyZEGxw.jpeg" /></figure><p>3 ImageDataGenerator objects to process the images in training, validation and testing datasets respectively. The first ImageDataGenerator object data_gen is used to generate batches of images from the training dataset with some data augmentation techniques such as fill mode, shear range, zoom range, and horizontal flip. The validation_split argument is set to 0.1, meaning 10% of the training images will be used for validation.</p><p>The flow_from_directory method is used to generate batches of images for training and validation. For training data, train_ds is created with subset=&#39;training&#39; argument and shuffle set to True. For validation data, val_ds is created with subset=&#39;validation&#39; argument and shuffle set to True.</p><p>The second ImageDataGenerator object data_gen2 is created to process the test data with no data augmentation techniques. The test_ds is created using this object with shuffle argument set to False.</p><p><strong>Model Development</strong></p><p>Convolutional Neural Network (CNN)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*2x9-Phb75a53M5udTg5e8g.png" /></figure><p>Convolutional Neural Network (CNN) is a type of Artificial Neural Network designed to recognize and analyze visual patterns directly from pixel images. It is particularly well suited for image classification and recognition tasks. CNNs consist of multiple layers that apply filters to the input image and gradually extract the important features and details that are relevant for the desired task. The extracted features are then passed to the next layer and combined with other features until the final layer produces the final prediction. The most distinctive feature of CNNs is the convolutional layer, where the filters are convolved with the input image to produce feature maps that capture different aspects of the image. The use of pooling layers, non-linear activation functions, and multiple convolutional layers enable CNNs to learn hierarchical representations of the image data, resulting in high accuracy in a wide range of image recognition tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zs6kj37tETJ29rNE9jTvMQ.jpeg" /></figure><p>This code defines a Convolutional Neural Network (CNN) using the Keras library in Python. The network is defined as a Sequential model and is constructed layer by layer.</p><p>The first two layers are a pair of Conv2D and MaxPooling2D layers. The Conv2D layer performs a 2D convolution operation on the input image, which extracts features from the image. The MaxPooling2D layer reduces the spatial dimensions of the feature maps produced by the Conv2D layer. This combination of Conv2D and MaxPooling2D is repeated twice more.</p><p>Next, the Flatten layer is used to flatten the output from the previous MaxPooling2D layer into a 1D vector, which is then used as input to a Dense layer with 256 units and a ReLU activation function. This layer serves as a fully connected layer in the network. A Dropout layer is added next with a rate of 0.5, which helps to reduce overfitting by randomly dropping out 50% of the activations in the previous layer during training. Finally, a Dense layer with 4 units and a softmax activation function is added, which serves as the output layer of the network and produces a probability distribution over the 4 classes.</p><p>The model is then compiled using the Adam optimizer, categorical cross-entropy loss, and accuracy metrics. The summary of the model is printed to provide information about the architecture and number of parameters in the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYzotLhtlFAEAUeCXjwjow.jpeg" /></figure><p>The code defines a list of callbacks for a deep learning model training process. The callbacks are used to monitor the model’s performance during training and to make decisions based on the model’s performance. The callbacks are as follows:</p><ol><li><strong>EarlyStopping</strong>: This stops the training process if the model’s performance, as defined by ‘val_loss’ metric, does not improve after a certain number of epochs (10).</li><li><strong>ModelCheckpoint</strong>: This saves the model weights to a file “BTMC_CNN_Model.h5” whenever the validation loss reaches a new minimum.</li><li><strong>ReduceLROnPlateau</strong>: This reduces the learning rate of the optimizer if the model’s performance, as defined by ‘val_loss’ metric, has not improved after a certain number of epochs (10).</li><li><strong>CSVLogger</strong>: This saves the log of model training to a CSV file “BTMC_CNN_Modellog.log”.</li></ol><p>The model is trained.</p><p><strong>Model Evaluation:</strong></p><p>The model evaluation was conducted using the following metrics:</p><ol><li>Precision Score: This measures the model’s ability to not label negative samples as positive, calculated as the ratio of true positive predictions to the sum of true and false positive predictions (tp / (tp + fp)).</li><li>Accuracy Score: In multi-label classification, this metric calculates the percentage of samples where the predicted labels match the true labels.</li><li>F1 Score: This is a harmonic mean of precision and recall, with the best score being 1 and the worst score being 0. It measures the balance between precision and recall, and its value is determined by the formula: F1 = 2 * (precision * recall) / (precision + recall). In multi-class and multi-label classification, the average F1 score is calculated, weighted based on the average parameter.</li><li>Recall Score: This metric measures the model’s ability to identify all positive samples, calculated as the ratio of true positive predictions to the sum of true positive predictions and false negative predictions (tp / (tp + fn)).</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*MAbjb9YKshnEnfAyfPzi_Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*gFguhRvMexjjfhdzvjSqMA.png" /></figure><p><strong>Confusion Matrix</strong></p><p>A confusion matrix is a performance measurement technique used in machine learning and classification algorithms. It is a table used to evaluate the accuracy of a classification algorithm. It shows the number of true positive, true negative, false positive and false negative predictions made by the algorithm. It is used to evaluate the performance of a classifier model and to identify areas where the model can be improved. The matrix is typically visualised as a table that displays the total number of correct and incorrect predictions made by the algorithm, making it an essential tool for evaluating the accuracy of a machine learning model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*vlorSBgv7dS-hJsmPli2kA.jpeg" /></figure><h3><strong>Transfer Learning</strong></h3><p><strong>VGG-16</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OQ68zRFIceaOPrI_agHB0g.png" /></figure><p>VGG-16 is a deep convolutional neural network architecture developed by the Visual Geometry Group (VGG) at the University of Oxford. It was introduced in the 2014 paper “Very Deep Convolutional Networks for Large-Scale Image Recognition” by Simonyan and Zisserman. VGG-16 is called so because it has 16 layers of convolutional and fully connected layers.</p><p>The architecture is characterised by its use of small 3x3 filters for all of its convolutional layers, and by stacking multiple layers of these filters together to form a deep network. The architecture also uses max pooling layers to reduce the spatial dimensions of the feature maps, and two fully connected layers at the end to perform the final classification.</p><p>VGG-16 has been widely used as a base architecture for many computer vision tasks and has been trained on large image datasets such as ImageNet. It is also often used as a transfer learning model, where the pre-trained weights on a large dataset are used as initialisation for a smaller task-specific dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*HRXYMas0R54stZnXD36K2A.jpeg" /></figure><p>This code defines a function named create_model that creates and compiles a deep learning model using the VGG16 architecture. The model is used for image classification and can be fine-tuned for a specific dataset.</p><p>The function takes the following arguments:</p><ul><li>input_shape: a tuple representing the shape of the input images, where the first and second elements are the width and height of the image, and the third element is the number of channels.</li><li>n_classes: the number of classes that the model should classify images into.</li><li>optimizer: the optimization algorithm used to update the model weights during training. The default is &#39;adam&#39;.</li><li>fine_tune: the number of layers of the pretrained VGG16 model to be fine-tuned. The default is 0, which means that all the layers will be frozen and not updated during training.</li></ul><p>The code starts by loading the pretrained VGG16 model with its weights set to the Imagenet weights. The include_top argument is set to False, which means that the fully-connected layers of the VGG16 model are excluded.</p><p>Next, the code sets the trainable attribute of the layers in the VGG16 model depending on the value of fine_tune. If fine_tune is greater than 0, the fine_tune number of last layers are set to be trainable, and the rest are frozen. If fine_tune is 0, all the layers are frozen.</p><p>After that, the code adds a new set of fully-connected layers on top of the pretrained VGG16 model. These layers include a Flatten layer, a dense layer with 256 neurons and a relu activation function, a Dropout layer with a dropout rate of 0.5, and an output layer with n_classes neurons and a softmax activation function.</p><p>Finally, the code creates a new model object that consists of the VGG16 model and the new fully-connected layers and compiles it using the specified optimizer and a categorical cross-entropy loss function. The model’s accuracy is also tracked during training.</p><p>The code also creates a final model object vgg16_final_model by calling the create_model function with fine_tune set to 0 and prints a summary of the model using the summary method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*wJefwl6IYgEbo2Lo5DLuGg.jpeg" /></figure><p><strong>Model Evaluation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*vgYLgSHtmV-OLJhDh1SdvA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*C8SA_9fr8rp2e6er5W50gA.jpeg" /></figure><p><strong>Model Deployment</strong></p><p>The model was deployed to a streamlit website, where user can upload a brain MRI and the model takes in the image, preprocesses the image: resizes the image, changes it to a numpy array and normalizes it before sending it to the model to make prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kXIAq9S6rbs-_1pCy0HHZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CHezfhf6KvqljR_YjXmmOQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5ce22e8e08a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Healthcare — Predicting the persistency of a drug using Deep Learning and ML Algorithms]]></title>
            <link>https://medium.com/@olutayobenson96/healthcare-predicting-the-persistency-of-a-drug-using-deep-learning-and-ml-algorithms-efeafca81ad5?source=rss-439a2d527fac------2</link>
            <guid isPermaLink="false">https://medium.com/p/efeafca81ad5</guid>
            <dc:creator><![CDATA[Olutayo Benson-Oladeinbo]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 01:17:18 GMT</pubDate>
            <atom:updated>2023-01-20T01:17:18.930Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Healthcare</strong> — Predicting the persistency of a drug using Deep Learning and ML Algorithms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iqsXTLKSI3Pus7FL7wQhuw.jpeg" /><figcaption>Image Source: <a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.healio.com%2Fnews%2Fneurology%2F20220602%2Fdisparities-in-filled-opioid-use-disorder-prescriptions-linked-to-covid19-pandemic&amp;psig=AOvVaw20PDjUET0OuE8NVuU15Fe7&amp;ust=1669392772132000&amp;source=images&amp;cd=vfe&amp;ved=0CA8QjRxqFwoTCPDHneuax_sCFQAAAAAdAAAAABAJ">Source</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>Persistence refers to continuing a course of treatment as advised by a medical professional, often in the context of taking chronic medications such as statins, anti-diabetic drugs, or hormone replacement therapy. It is also known as medication adherence, compliance, or concordance. Persistence is measured by the number of consecutive prescriptions dispensed and the amount of medication in possession over a certain period of time. It is a measure of the duration of use, calculated as the number of days between the start of the treatment (index date) and the first failure to renew the medication, allowing for a permissible gap.</p><p>Analyzing persistence typically involves two types of measures:</p><ol><li>The cumulative treatment persistence rate, which is calculated using Kaplan-Meier failure time analysis and data is censored at the end of the observation period (such as the end of a fiscal year).</li><li>The likelihood of persistence, which is determined by calculating odds ratios using unconditional logistic regression, and taking into consideration potential factors that could influence persistence such as age, sex, number of other medications being taken, number of doctor visits, and number of hospitalizations (specific factors may vary depending on the medication being studied).</li></ol><p><strong>Objective:</strong></p><p>The objective of this machine learning project is to use deep learning and ML algorithms to predict the persistency of a drug in a healthcare setting. By analyzing and modeling various factors that influence drug persistency, such as patient demographics, medical history, and treatment regimen, the project aims to develop a model that can accurately predict and improve medication adherence in patients. By providing a better understanding of the factors that contribute to persistency, this project aims to improve patient outcomes and reduce healthcare costs associated with non-adherence.</p><p><strong>Dataset:</strong></p><p>The dataset contains 3434 rows and 64 features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*k6vd1HC8P8bsDl1Ly5VZtQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*0zaXdggOxGpUq9wyxONVeQ.png" /></figure><p><strong>N/B: At the end of this analysis, you would have learnt:</strong></p><p>a. Exploratory Data Analysis</p><p>b. Label Encoding</p><p>c. Handling Imbalance in the dataset.</p><p>d. Model design</p><p>e. Model testing and Evaluation</p><p>You can find the dataset and analysis <a href="https://github.com/TeewhyB01/Healthcare---Drug-Resistence">here</a></p><p><strong>Importing Libraries</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*-l8PE5Tt-ZDp8YlemDlpkw.png" /></figure><p><strong>Data Overview</strong></p><p>The dataset contains 3434rows and 64 columns.</p><p>The <strong>dataframe.dtypes</strong> function gives you the data type of each column in the dataset.</p><p>The <strong>dataframe.count()</strong> function gives you the total number of Non_null rows in each column in the dataset.</p><p>The <strong>dataframe.isnull().sum()</strong> function gives you the total number of empty rows in each column in the dataset.</p><p>The <strong>dataframe.unique()</strong> function gives you the total number of rows with unique values in each column in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*oaa_hSXLe199nTuacYSDJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*vntQlKClVQxOLhUB9OSk5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*aSOEUn1XNTae8T9JbEaUfA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*VQy_qE8nufUACgbPiJ2gHg.png" /></figure><p><strong>Exploratory Data Analysis</strong></p><p>Exploratory Data Analysis refers to the critical process of performing initial investigations on data so as to discover patterns, to spot anomalies, to test hypothesis and to check assumptions with the help of summary statistics and graphical representations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*wgN9ZRGAmYSYW6wJUeB7FA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*F4t19KS2JdD9fIzvLhnzSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*2sQ1JWVRkrvxBE14IT7frA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*VsrBq4x9YMFZtA43_4pu1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*m7_elpEtAV8JhqldgmVNMA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*R1nJbAYTAaaRM4BQnYqlBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*ZZyII3AcyrC4v5X9XZAtJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Phya3kvy6VeaqB1z3Dxtpw.png" /></figure><p><strong>EDA Summary</strong></p><p>The dataset contains 3424 rows and 69 columns.</p><p>The number of cases where the drugs proved to be non-persistent were higher compared to number od persistency cases.</p><p>The dataset reveal that more females partook in this analysis than male.</p><p>People of Caucasian race when compered to other races were the most common in the study.</p><p>The non-Hispanic ethnic group were the most common in the study.</p><p>There were more people from the Midwest and South region compared to other regions.</p><p>For this study, most people selected are greater than 75 years of age.</p><p>People with a Tscore of &gt;-2.5 have a higher chance of drug being non-persistent.</p><p><strong>Data Pre-processing</strong></p><p>To prepare the data for analysis, it was encoded using the LabelEncoder library. The data was then divided into a training set (70%) and a test set (30%) using Sklearn’s train test split function. To address the imbalance in the dataset, the SMOTE library was used. Four machine learning algorithms were applied to the training set, and an Artificial Neural Network (ANN) algorithm was used to train the final model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4hJyancGsJ4UZUkSn3kZPQ.png" /></figure><p><strong>Model Training:</strong></p><p>The models are evaluated using:</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html"><strong>Precision Score</strong></a><strong>:</strong> The precision is the ratio tp / (tp + fp) where tp is the number of true positives and fp the number of false positives. The precision is intuitively the ability of the classifier not to label as positive a sample that is negative.</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html"><strong>Accuracy Score</strong></a><strong>: </strong>In multilabel classification, this function computes subset accuracy: the set of labels predicted for a sample must <em>exactly</em> match the corresponding set of labels in y_true.</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html"><strong>F1 Score</strong></a><strong>:</strong> The F1 score can be interpreted as a harmonic mean of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. The relative contribution of precision and recall to the F1 score are equal. The formula for the F1 score is:</p><pre>F1 = 2 * (precision * recall) / (precision + recall)</pre><p>In the multi-class and multi-label case, this is the average of the F1 score of each class with weighting depending on the average parameter.</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html"><strong>Recall Score:</strong></a> The recall is the ratio tp / (tp + fn) where tp is the number of true positives and fn the number of false negatives. The recall is intuitively the ability of the classifier to find all the positive samples.</p><p><a href="https://scikit-learn.org/0.17/modules/generated/sklearn.metrics.auc.html">AUC</a>: represents the probability that a random positive (green) example is positioned to the right of a random negative (red) example. AUC ranges in value from 0 to 1. A model whose predictions are 100% wrong has an AUC of 0.0; one whose predictions are 100% correct has an AUC of 1.0.</p><p><a href="https://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html">ROC</a>: ROC curves are typically used in binary classification to study the output of a classifier. In order to extend ROC curve and ROC area to multi-label classification, it is necessary to binarize the output. One ROC curve can be drawn per label, but one can also draw a ROC curve by considering each element of the label indicator matrix as a binary prediction (micro-averaging).</p><p><strong>Logistic Regression</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSc_Ahk7pV0UV64y_SGoHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*CoojCIapfBNdofsDdukT_Q.png" /></figure><p><strong>Support Vector Machine (SVM)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7duH2ZrB6XBVrBi9-ePxUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*PxZmepy4bNwtJ4W3tKtddw.png" /></figure><p><strong>KNearestNeighbours (KNN)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fbP_0JldFpXY35PkrGh6ww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*tNd7_jErTCqokG_eU2kAcg.png" /></figure><p><strong>Gradient Boost</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ep8tbdgbbGoQLo48BJa9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*2OJF1RzcBCaxA9lY2aqT3w.png" /></figure><p>ANN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1Al47BGlyXCeqj1qV_aKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cijkmOEdDSG_r5PHoZHSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*2rkbWK2IKIl-kpOhbUSvkQ.png" /></figure><p><strong>Summary</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*LnKuKs0pVt4BKoRaoK045Q.png" /></figure><p><strong>Conclusion</strong></p><p>In conclusion, this article has demonstrated that the accuracy of a model can vary greatly depending on the problem definition, the nature of the data, and the presence of errors or missing information. It is important to test different models and use hyper-parameters to optimize the model’s performance. In this project, the Gradient Boost algorithm was found to have the highest accuracy score. To improve the model’s performance in future studies, it is recommended to acquire more data, use a deeper neural network model, implement transfer learning in the deep learning architecture, and apply column reduction techniques to increase accuracy. Overall, this project highlights the importance of carefully analyzing and preprocessing the data, as well as testing multiple models, to achieve the best results.</p><p>Thank you.</p><ul><li>Olutayo Oladeinbo (M.sc Data Science)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efeafca81ad5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[End-to-End Stroke Prediction Analysis using Deep Learning and ML Algorithms]]></title>
            <link>https://medium.com/@olutayobenson96/end-to-end-stroke-prediction-analysis-using-deep-learning-and-ml-algorithms-5f22b190507b?source=rss-439a2d527fac------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f22b190507b</guid>
            <category><![CDATA[stroke-prediction]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Olutayo Benson-Oladeinbo]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 14:35:18 GMT</pubDate>
            <atom:updated>2022-07-26T16:25:21.590Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*ZYkR-PrpIkVuELCn2ENbFA.png" /><figcaption>Image Source: <a href="https://www.stroke.org/-/media/Stroke-Images/About-Stroke/Illustration-of-a-Stroke_04.png?h=600&amp;iar=0&amp;mw=600&amp;w=600&amp;hash=AF04436AC864C7D1D7BEDDFF072C7A2A">American Stroke Association</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>A stroke is a life-threatening unforeseen medical crisis that occurs when a section of the brain cells is blocked from receiving the normal level of blood supply that brings in oxygen and glucose to the brain cells, thereby causing the cells affected to die(NHS,2021). According to World Health Organisation (WHO) in the year 2019, stroke ranks second on the chart of global causes of death and third in the global causes of disability. It has been noticed over the years that tracking symptoms such as Body Mass Index (BMI), Heart Disease Status, Hypertension status, Average Glucose Level, Age, Smoking Status, Work Type, and marital Status can help detect stroke patterns early and it can be treated. Stroke can be avoided by making relevant changes to one’s lifestyle and having regular checks on key factors can reduce one’s exposure to stroke. Having a model that can help check these factors regularly and alert the individual when to adjust his or her lifestyle can help with prevention and early treatment. Several studies have been carried out to uncover efficient stroke predictors. Studies have been done to discover the main stroke predictors. Because of this research, Machine Learning algorithms are becoming widely accepted in the medical field to help deal with the early detection of stroke in humans.</p><p><strong>Task:</strong></p><p>Build a Machine Learning and Deep Learning Model that can best predict the occurrence of a stroke in an individual. Using this model, design a website to take in new data from the user and make predictions appropriately.</p><p><strong>Dataset:</strong></p><p>The Data was collected from Kaggle’s Stroke Prediction Dataset link and consists of 12 features and 5110 rows. The features include:</p><ol><li>ID</li><li>Age</li><li>Average glucose level</li><li>Body mass index</li><li>Gender</li><li>Hypertension</li><li>Heart Disease</li><li>Ever Married</li><li>Work Type</li><li>Residence Type</li><li>Smoking Status</li><li>Stroke (Target)</li></ol><p><strong>N/B: At the end of this analysis, you would have learned:</strong></p><p>a. Feature Creation and Extraction</p><p>b. Handling Missing Values</p><p>c. Label Encoding</p><p>d. Model design and Iterative approach</p><p>e. Model testing and Evaluation</p><p>f. Feature Importance.</p><p>You can find the dataset and analysis <a href="https://github.com/TeewhyB01/StrokePrediction">here</a></p><p><strong>Import Libraries</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VoOg1UaUx7qKkkxA0k95fA.png" /></figure><h3><strong>Data Overview:</strong></h3><p>The dataset contains 5110 rows and 12 columns.</p><p>The dataframe.dtypes function gives you the data type of each column in the dataset.</p><p>The dataframe.count() function gives you the total number of Non_null rows in each column in the dataset.</p><p>The dataframe.isnull().sum() function gives you the total number of empty rows in each column in the dataset.</p><p>The dataframe.unique() function gives you the total number of rows with unique values in each column in the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_kO7u3dcZuqMSvQZ0ToXg.png" /></figure><h3><strong>Data Cleaning:</strong></h3><p>Data Cleaning is the process of finding and correcting the inaccurate/incorrect data that are present in the dataset. One such process needed is to do something about the values that are missing in the dataset. In real life, many datasets will have many missing values, so dealing with them is an important step.</p><p>From the investigation done above, it was seen that our dataset has 201 missing values, and 3 gender values, we also can see that the age column is in float, which shouldn’t be.</p><p>Since 201 is less than 5% of the total number of data we have, we can easily just delete them to save us a lot of stress. visit <a href="https://www.analyticsvidhya.com/blog/2021/05/dealing-with-missing-values-in-python-a-complete-guide/">here</a> to learn more about handling missing values.</p><p>On investigation, it is seen that we only have 1 row that has the ‘Other’ gender in the dataset, so we also drop the value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FT4k_NXesxwCXZq5-wLIw.png" /></figure><p>we also change the data type of the Age column:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*SwIafq_hMdlFu9EwedfHXA.png" /></figure><p><strong>Feature Creation</strong></p><p>Feature engineering, also known as feature creation, is the process of constructing new features from existing data to train a machine learning model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_w4V7UsVjMYUuc4xSmaePw.png" /></figure><h3><strong>Data Visualization</strong></h3><p>Data visualization is the discipline of trying to understand data by placing it in a visual context so that patterns, trends, and correlations that might not otherwise be detected can be exposed.</p><p>Python offers multiple great graphing libraries packed with lots of different features.</p><p>visit <a href="https://gilberttanner.com/blog/introduction-to-data-visualization-inpython/">here</a> to learn more.</p><p>Firstly, let’s visualize the percentage of people Healthy and people living with stroke</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*TH2VQoPdMuGrErZ1RIKGxg.png" /></figure><p><strong>Gender Distribution on Stroke:</strong></p><p>There has been an assumption that Male are more susceptible to stroke due to high work-related stress. From the below visualizations, we can see that the assumption is wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*Ea7yGQzWZ_VNGPf7iA30iw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*1svoMvTaq6NdW2IBh7B03w.png" /></figure><p><strong>Age Distribution on Stroke:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C6juyybp5QyvHbGQVAKQFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-rOEosc_1Beg8_utHHo_GQ.png" /></figure><p><strong>BMI Distribution on stroke:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o8fxgkjaIklfxHzNL3E5Eg.png" /></figure><p><strong>Work influence on stroke:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*OX9SclENee4RtIF1y8Eg6Q.png" /></figure><p><strong>How smoking influences stroke</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*qiQDrmYm_tURN9veTX8OZA.png" /></figure><h3><strong>Model Design</strong></h3><p>Data were split into training and test set using sklearn’s <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html">train test split function</a>, after which 5 ML algorithm were used in a grid search CV to get the best parameters to use in training our different models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmaFWiNwC_pfhs71fwqd_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qxSZk3u_MWUCBK5EaWD0Bg.png" /></figure><p>The above table shows the Model and Parameters with the best score in descending order. So we use the Models and the Parameters displayed to train our different models.</p><p><strong>Model Training:</strong></p><p>A function was created to take in our dependent and independent features, the name of the model to be trained, the model, <a href="https://numpy.org/doc/1.16/reference/generated/numpy.random.RandomState.html">random state</a>, and all other parameters. The function then creates an object of the model, <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html">splits</a> the dataset, handles the imbalance in the dataset using <a href="https://machinelearningmastery.com/smote-oversampling-for-imbalanced-classification/">SMOTE</a> library, <a href="https://www.askpython.com/python/examples/standardize-data-in-python">standardizes</a> the training data to better improve the result, trains the data, and evaluates the results. All the scores for the different algorithms are gotten and stored in a data frame for comparison.</p><p>The models were evaluated using:</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html"><strong>Precision Score</strong></a><strong>:</strong> The precision is the ratio tp / (tp + fp) where tp is the number of true positives and fp the number of false positives. The precision is intuitively the ability of the classifier not to label as positive a sample that is negative.</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html"><strong>Accuracy Score</strong></a><strong>: </strong>In multilabel classification, this function computes subset accuracy: the set of labels predicted for a sample must <em>exactly</em> match the corresponding set of labels in y_true.</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html"><strong>F1 Score</strong></a><strong>:</strong> The F1 score can be interpreted as a harmonic mean of the precision and recall, where an F1 score reaches its best value at 1 and worst score at 0. The relative contribution of precision and recall to the F1 score are equal. The formula for the F1 score is:</p><pre>F1 = 2 * (precision * recall) / (precision + recall)</pre><p>In the multi-class and multi-label case, this is the average of the F1 score of each class with weighting depending on the average parameter.</p><p><a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html"><strong>Recall Score:</strong></a> The recall is the ratio tp / (tp + fn) where tp is the number of true positives and fn the number of false negatives. The recall is intuitively the ability of the classifier to find all the positive samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZ32tqa8inC6mTyO2LKRKQ.png" /></figure><p><strong>Random Forest Classifier:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TcyJ9OSIBUyib3DwZPp-iw.png" /></figure><p><strong>K Nearest Neighbour</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T-C9JHF9vZ0YZJGSBDjXfw.png" /></figure><p><strong>Gradient Boost Classifier</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JrkPjawan_ucltFUIYygdw.png" /></figure><p><strong>Decision Tree Classifier</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7EvQGGqyPBlSCUHzvuaE3w.png" /></figure><p><strong>Logistic Regression</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mPcxJRc7El1GyRUuyKyngQ.png" /></figure><p><strong>Deep Learning Model Creation</strong></p><p>Deep learning is a type of <a href="https://www.techtarget.com/searchenterpriseai/definition/machine-learning-ML">machine learning</a> and artificial intelligence (<a href="https://www.techtarget.com/searchenterpriseai/definition/AI-Artificial-Intelligence">AI</a>) that imitates the way humans gain certain types of knowledge. Deep learning is an important element of data science, which includes statistics and <a href="https://www.techtarget.com/searchenterpriseai/definition/predictive-modeling">predictive modeling</a>. It is extremely beneficial to data scientists who are tasked with collecting, analyzing, and interpreting large amounts of data; deep learning makes this process faster and easier.</p><p>At its simplest, deep learning can be thought of as a way to automate <a href="https://www.techtarget.com/searchbusinessanalytics/definition/predictive-analytics">predictive analytics</a>. While traditional machine learning <a href="https://www.techtarget.com/whatis/definition/algorithm">algorithms</a> are linear, deep learning algorithms are stacked in a <a href="https://www.techtarget.com/whatis/definition/hierarchy">hierarchy</a> of increasing complexity and abstraction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fGokv8Ky9ORO3pilDnqvDg.png" /></figure><p><strong>Model Evaluation</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CvL_0FvpFGI7SFTw5I6cnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwDO_hbyiklkIZ2j7xRGMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PG8t9I_Gr2rhoLXLcC1PKw.png" /></figure><h3>Conclusion</h3><p>This article has shown that the accuracy of a model varies largely on the problem definition, the nature of the data, how messy the data is, incorrect entries or omitted entries as seen in the ‘BMI’ column and ‘Unknown’ category in the Smoking column. It is advised to always test different models on a particular data and in some cases use hyper-parameters to get the best parameters to use in the model training. In this project, I recommend using Random Forest as it has the accuracy highest score.</p><p>Future Improvements can be made in the following areas:</p><ol><li>Getting more data.</li><li>Using other ML Algorithms such as SVM.</li><li>Deeper Neural Network model.</li><li>Using Transfer Learning in our Deep Learning Architecture.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f22b190507b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>