<?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 Hanna Lee on Medium]]></title>
        <description><![CDATA[Stories by Hanna Lee on Medium]]></description>
        <link>https://medium.com/@hannalee?source=rss-206d85c68c89------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pr_fa0LwOmxIZ7X749z9PQ.png</url>
            <title>Stories by Hanna Lee on Medium</title>
            <link>https://medium.com/@hannalee?source=rss-206d85c68c89------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 21:33:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hannalee/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[3D Computer Vision) Quantifying Hippocampus Volume for Alzheimer’s Progression]]></title>
            <link>https://hannalee.medium.com/3d-computer-vision-quantifying-hippocampus-volume-for-alzheimers-progression-a8190ed0f4eb?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8190ed0f4eb</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 18:08:57 GMT</pubDate>
            <atom:updated>2023-08-24T18:42:50.822Z</atom:updated>
            <content:encoded><![CDATA[<p>code: <a href="https://github.com/hungryPanko/3D_CV_hippocampal_volume">https://github.com/hungryPanko/3D_CV_hippocampal_volume</a></p><h3>Background</h3><p>Alzheimer’s disease (AD) is a progressive neurodegenerative disorder that results in impaired neuronal (brain cell) function and eventually, cell death. AD is the most common cause of dementia. Clinically, it is characterized by memory loss, inability to learn new material, loss of language function, and other manifestations.</p><p>For patients exhibiting early symptoms, quantifying disease progression over time can help direct therapy and disease management.</p><p>A radiological study via MRI exam is currently one of the most advanced methods to quantify the disease. In particular, the measurement of hippocampal volume has proven useful to diagnose and track progression in several brain disorders, most notably in AD. Studies have shown a reduced volume of the hippocampus in patients with AD.</p><p>The hippocampus is a critical structure of the human brain (and the brain of other vertebrates) that plays important roles in the consolidation of information from short-term memory to long-term memory. In other words, the hippocampus is thought to be responsible for memory and learning (that’s why we are all here, after all!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*qtuu-2yrMPsY6lkxhFhd5w.gif" /></figure><p>Humans have two hippocampi, one in each hemisphere of the brain. They are located in the medial temporal lobe of the brain.</p><p>According to Nobis et al., 2019, the volume of hippocampus varies in a population, depending on various parameters, within certain boundaries, and it is possible to identify a “normal” range taking into account age, sex and brain hemisphere.</p><p>You can see this in the image below where the right hippocampal volume of women across ages 52–71 is shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*R_g9i_ux5gLluVeliwm1dg.png" /></figure><p>There is one problem with measuring the volume of the hippocampus using MRI scans, though — namely, the process tends to be quite tedious since every slice of the 3D volume needs to be analyzed, and the shape of the structure needs to be traced. The fact that the hippocampus has a non-uniform shape only makes it more challenging. Do you think you could spot the hippocampi in this axial slice below?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*4qXWt5mywqcxkLjeLkFW1Q.png" /></figure><p>In this project, we will focus on the technical aspects of building a segmentation model and integrating it into the clinician’s workflow, leaving the dataset curation and model validation questions largely outside the scope of this project.</p><h3>Project Overview</h3><p>This project has an end-to-end AI system which features a machine learning algorithm that integrates into a clinical-grade viewer and automatically measures hippocampal volumes of new patients, as their studies are committed to the clinical imaging archive.</p><p>Fortunately, we don’t need to deal with full heads of patients. Our (fictional) radiology department runs a HippoCrop tool that cuts out a rectangular portion of a brain scan from every image series, making your job a bit easier, and our committed radiologists have collected and annotated a dataset of relevant volumes, and even converted them to NIFTI format!</p><p>The dataset contains the segmentations of the right hippocampus and you will use the U-Net architecture to build the segmentation model.</p><h3>The Dataset</h3><p>We are using the “Hippocampus” dataset from the Medical Decathlon competition. This dataset is stored as a collection of NIFTI files, with one file per volume, and one file per corresponding segmentation mask. The original images here are T2 MRI scans of the full brain. As noted, in this dataset we are using cropped volumes where only the region around the hippocampus has been cut out. This makes the size of our dataset quite a bit smaller, our machine learning problem a bit simpler and allows us to have reasonable training times. You should not think of it as “toy” problem, though. Algorithms that crop rectangular regions of interest are quite common in medical imaging. Segmentation is still hard.</p><h3>EDA — Preparing the dataset for hippocampus segmentation</h3><h4>Loading NIFTI images using NiBabel</h4><p>NiBabel is a python library for working with neuro-imaging formats (including NIFTI). Our dataset sits in two directories — <em>images</em> and <em>labels</em>. Each image is represented by a single file (we are fortunate to have our data converted to NIFTI) and has a corresponding label file which is named the same as the image file. Let’s visualize a few slices from the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*VOlpYAJq98nJJv60c4Kc9Q.png" /></figure><p>We can check 3D view using 3D slicer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*YXonSVLDJMIiYd-yI8MBqA.png" /></figure><p>We can get hippocampus volume from metadata.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*tRSNJfzpYBFpVoZU2NKwdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*kTgFzGVYjcd6NqmFvIEYhw.png" /></figure><p>Let’s plot a histogram of all volumes that we have in our dataset and see how our dataset measures against a slice of a normal population represented by the chart below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*KupaBqKaQY7qCzLYzVWl_A.png" /></figure><h3>Train Validate Model</h3><p>You will be using <a href="https://pytorch.org/"><strong>PyTorch</strong></a> to train the model, similar to exercises in the Segmentation &amp; Classification Lesson, and we will be using <a href="https://www.tensorflow.org/tensorboard/"><strong>Tensorboard</strong></a> to visualize the results.</p><p>You will use the script run_ml_pipeline.py to kick off your training pipeline.</p><pre>&quot;&quot;&quot;<br>This file contains code that will kick off training and testing processes<br>&quot;&quot;&quot;<br>import os<br>import json<br><br>from experiments.UNetExperiment import UNetExperiment<br>from data_prep.HippocampusDatasetLoader import LoadHippocampusData<br><br>class Config:<br>    &quot;&quot;&quot;<br>    Holds configuration parameters<br>    &quot;&quot;&quot;<br>    def __init__(self):<br>        self.name = &quot;Basic_unet&quot;<br>        self.root_dir = r&quot;/Users/hannalee/Documents/Udacity/AI_healcare/3D_FinalProj/section1/out&quot;<br>        self.n_epochs = 5<br>        self.learning_rate = 0.0002<br>        self.batch_size = 8<br>        self.patch_size = 64<br>        self.test_results_dir = &quot;/Users/hannalee/Documents/Udacity/AI_healcare/3D_FinalProj/section2/result&quot;<br><br>if __name__ == &quot;__main__&quot;:<br>    # Get configuration<br><br>    # TASK: Fill in parameters of the Config class and specify directory where the data is stored and <br>    # directory where results will go<br>    c = Config()<br><br>    # Load data<br>    print(&quot;Loading data...&quot;)<br><br>    # TASK: LoadHippocampusData is not complete. Go to the implementation and complete it. <br>    data = LoadHippocampusData(c.root_dir, y_shape = c.patch_size, z_shape = c.patch_size)<br><br>    # Create test-train-val split<br>    # In a real world scenario you would probably do multiple splits for <br>    # multi-fold training to improve your model quality<br><br>    keys = range(len(data))<br><br>    # Here, random permutation of keys array would be useful in case if we do something like <br>    # a k-fold training and combining the results. <br><br>    split = dict()<br><br>    # TASK: create three keys in the dictionary: &quot;train&quot;, &quot;val&quot; and &quot;test&quot;. In each key, store<br>    # the array with indices of training volumes to be used for training, validation <br>    # and testing respectively.<br><br>    # TASK: create three keys in the dictionary: &quot;train&quot;, &quot;val&quot; and &quot;test&quot;.<br>    train_size = int(0.7 * len(keys))<br>    val_size = int(0.2 * len(keys))<br>    split[&quot;train&quot;] = keys[:train_size]<br>    split[&quot;val&quot;] = keys[train_size:train_size + val_size]<br>    split[&quot;test&quot;] = keys[train_size + val_size:]<br><br>    # Set up and run experiment<br>    <br>    # TASK: Class UNetExperiment has missing pieces. Go to the file and fill them in<br>    exp = UNetExperiment(c, split, data)<br><br>    # You could free up memory by deleting the dataset<br>    # as it has been copied into loaders<br>    # del dataset <br><br>    # run training<br>    print(&quot;\nStart Running&quot;)<br>    exp.run()<br><br>    # prep and run testing<br>    # TASK: Test method is not complete. Go to the method and complete it<br>    print(&quot;\nStart Testing&quot;)<br>    results_json = exp.run_test()<br><br>    results_json[&quot;config&quot;] = vars(c)<br><br>    with open(os.path.join(exp.out_dir, &quot;results.json&quot;), &#39;w&#39;) as out_file:<br>        json.dump(results_json, out_file, indent=2, separators=(&#39;,&#39;, &#39;: &#39;))<br></pre><p><strong>Model: </strong>Encoder-Decoder Architecture for Semantic Segmentation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*_gGuNGevu80keoxcxNkzgQ.png" /></figure><ol><li><strong>Encoder</strong>:</li></ol><ul><li>The encoder is typically a pre-trained CNN, such as VGG16, ResNet, etc.</li><li>The main goal of the encoder is to capture the context from the input image. It does this by successively reducing the spatial dimensions of the input, i.e., making the image smaller while making the feature maps deeper.</li><li>Pooling layers (like max pooling) are used to downsample the image. These layers reduce the spatial dimensions, allowing the network to focus on broader contextual features.</li></ul><p>2. <strong>Decoder</strong>:</p><ul><li>The decoder takes the feature map from the encoder and gradually upsamples it to bring it back to the original input size. This upsampled output can then be compared to the ground truth to calculate the loss and update the model’s weights during training.</li><li>The main goal of the decoder is to restore the spatial dimensions and use the context learned by the encoder to predict a label for each pixel.</li><li>Typically, transposed convolution or up-convolution layers are used for upsampling.</li></ul><p>3. <strong>Skip Connections</strong>:</p><ul><li>These are connections that skip one or more layers. In the context of semantic segmentation, they are used to provide local features to global features.</li><li>They help in restoring the spatial details that are lost during the encoding (downsampling) process. By combining the deeper layer’s contextual information with the shallower layer’s spatial details, skip connections allow the decoder to make more accurate segmentation predictions.</li></ul><p>In this project, U-net is used, which is very popular for biomedical applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*idtyHe6Vk3AFHyEkz1GliQ.png" /></figure><p>After some training, we can see training and validation loss is reduced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*mkyt63gKywvDwa4nENuRAw.png" /></figure><p>Here are some snapshots of ground truth images and our prediction. It looks beautiful. Isn’t it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*nW7den023ustVoPaOZAOkQ.png" /></figure><h3>Evaluation</h3><p>Now, let’s evaluate our model. Segmentation models have some metrics that you can use to evaluate the performance.</p><ul><li><a href="https://en.wikipedia.org/wiki/Sensitivity_and_specificity"><strong>Sensitivity and Specificity</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0b4G-6QYItKZ1oDD-XBt0g.png" /></figure><ul><li><a href="https://en.wikipedia.org/wiki/Jaccard_index"><strong>Jaccard Index</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*fjPcF9aUvlW5I_aVPJscwg.png" /></figure><ul><li><a href="https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient"><strong>Dice Similarity Coefficient</strong></a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*uvB_R19Ja7RSmqHW5Mj8PQ.png" /></figure><p>The dice model has some shortcomings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m6q5HdNTvaq5h_N0ruRfNw.png" /></figure><ul><li><a href="https://en.wikipedia.org/wiki/Hausdorff_distance"><strong>Hausdorff Distance</strong></a></li></ul><p>Hausdorff&#39;s distance model overcomes such shortcomings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRsltU-KvGPEkv4GQyJ_WA.png" /></figure><p><strong>Here is the result:</strong></p><p>I used the dice and Jaccard model. It gives around 90% and 82% of similarity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*jSa4cddJCqWbA-kgug3kGg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8190ed0f4eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Computer Vision) Pneumonia Detection]]></title>
            <link>https://hannalee.medium.com/computer-vision-pneumonia-detection-6862da35addb?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/6862da35addb</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 23:15:53 GMT</pubDate>
            <atom:updated>2023-08-16T06:08:02.956Z</atom:updated>
            <content:encoded><![CDATA[<p>Code: <a href="https://github.com/hungryPanko/1_2D_Medical_Image">https://github.com/hungryPanko/1_2D_Medical_Image</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*fMHOhg862QiBk3YTwUAVHg.png" /></figure><pre># _00_Project_Pneumonia_Detection_Chest_Xray<br><br>## **Project Overview**<br>The purpose of this project is to analyze data from the NIH Chest X-ray Dataset and train a CNN to classify a given chest x-ray for the presence or absence of pneumonia. <br>This project will culminate in a model that can predict the presence of pneumonia with human radiologist-level accuracy that can be prepared for submission to the FDA for 510(k) clearance as software as a medical device. <br>As part of the submission preparation, it will formally describe the model, the data that it was trained on, and a validation plan that meets FDA criteria.<br>It containsthe medical images with clinical labels for each image that were extracted from their accompanying radiology reports.<br>The project will include access to a GPU for fast training of deep learning architecture, as well as access to 112,000 chest x-rays with disease labels acquired from 30,000 patients.<br><br><br>## **Project Highlight**<br>This project is designed to give you hands-on experience with 2D medical imaging data analysis and preparation of a medical imaging model for regulatory approval.<br>It contians:<br>- Recommend appropriate imaging modalities for common clinical applications of 2D medical imaging<br>- Perform exploratory data analysis (EDA) on medical imaging data to inform model training and explain model performance<br>- Establish the appropriate ‘ground truth’ methodologies for training algorithms to label medical images<br>- Extract images from a DICOM dataset<br>- Train common CNN architectures to classify 2D medical images<br>- Translate outputs of medical imaging models for use by a clinician<br>- Plan necessary validations to prepare a medical imaging model for regulatory approval<br><br><br>## **Project Steps**<br><br>This project has the following steps.<br>- Exploratory Data Analysis<br>- Building and Training Your Model<br>- Clinical Workflow Integration<br>- FDA Preparation<br><br><br>## **About Files**<br>- EDA.ipynb: This is the file you will be performing the EDA.<br>- Build and train model.ipynb: This is the file you will be building and training your model.<br>- Inference.ipynb: This is the file you will be performing clinical workflow integration.<br>- .dcm files: They are the test files to test the clinical workflow integration.<br>- sample_labels.csv: This is the file that should be used to assess images in the pixel-level.<br>- FDA_Submission_Template.md: This is the template to create the FDA submission.</pre><h3>EDA</h3><p>EDA is open-ended, and it is up to you to decide how to look at different ways to slice and dice your data. A good starting point is to look at the requirements for the FDA documentation in the final part of this project to guide (some) of the analyses you do.</p><p>This EDA should also help to inform you of how pneumonia looks in the wild. E.g. what other types of diseases it’s commonly found with, how often it is found, what ages it affects, etc.</p><p>Note that this NIH dataset was not specifically acquired for pneumonia. So, while this is a representation of ‘pneumonia in the wild,’ the prevalence of pneumonia may be different if you were to take only chest x-rays that were acquired in an ER setting with suspicion of pneumonia.</p><p>Perform the following EDA:</p><p>The patient demographic data such as gender, age, patient position,etc. (as it is available)</p><p>The x-ray views taken (i.e. view position)</p><p>The number of cases including:</p><p>number of pneumonia cases,</p><p>number of non-pneumonia cases</p><p>The distribution of other diseases that are comorbid with pneumonia</p><p>Number of diseases per patient</p><p>Pixel-level assessments of the imaging data for healthy &amp; disease states of interest (e.g. histograms of intensity values) and compare distributions across diseases.</p><p>Note: use full NIH data to perform the first a few EDA items and use sample_labels.csv for the pixel-level assessments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4CKbr5icY6vR7VPfhAmNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*eeyjqzpB7rRmrTvfIOTNLQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*XgPqf4zNUA_SOKgq0ufhig.png" /></figure><p>Above, I see the relative frequencies of each disease in my dataset. It looks like ‘No Finding’ is the most common occurrence. <strong><em>‘No Finding’</em></strong> can never appear with any other label by definition, so we know that in <strong><em>53.8%</em></strong> of this dataset, there is no finding in the image. Beyond that, it appears that <strong><em>‘Infiltration’</em></strong> is the most common disease-related label, and it is followed by <strong><em>‘Effusion’</em></strong> and <strong><em>‘Atelectasis.’</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*H2YomV3YFSVRqOwO6PmTiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2_Z1yjQXSgGS1z_0G-11YA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vo6B6iJ9JpOkk4QCY7xUFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*gSxHCTszmSzsrK55pqpm8Q.png" /></figure><p>From the X-ray, we can interpret that a lung with pneumonia has white spots (called infiltrates) that indicate an infection. As we can see from the distributions of intensity values of the pixel-level data within images, a lung with pneumonia has more pixels in the range of 125–150, whereas a lung without pneumonia has a plateau peak at 150–200. This suggests that a lung with pneumonia has more bright pixels, which might be caused by white spots.</p><h3>Build and train model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*UekyhqvOg2ZyFcFSjEvCxw.png" /></figure><p>Our train_test_split made sure that we had the same proportions of Pneumothorax in both sets!</p><h4><strong>Condition 1 — To have an EQUAL amount of positive and negative cases of Pneumothorax in Training</strong></h4><p>But…. we know that we want our model to be trained on a set that has <em>equal</em> proportions of pneumothorax and no pneumothorax, so we’re going to have to throw away some data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*GEiu9NN6Phqr8IkeKzGP9Q.png" /></figure><p>Ta-da! We randomly chose a set of non-Pneumothorax images using the sample() function that was the same length as the number of true Pneumothorax cases we had, and then we threw out the rest of the non-Pneumothorax cases. Now our training dataset is balanced 50–50.</p><h4>Condition 2 — To have 20% positive cases of Pneumothorax in the Test Set</h4><p>Finally, we want to make the balance in our validation set more like 20–80 since our exercise told us that the prevalence of Pneumothorax in this clinical situation is about 20%:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*B4zZjA4u03V9Nq6IJqwLSw.png" /></figure><h3>Now we can begin our model-building &amp; training</h3><h4>1. image augmentation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*7RYsRVcNYO5JrcsDdcdNNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*zu_0UIIGKtgLjWBYUS2Nig.png" /></figure><h3>Now we’ll load in VGG16 with pre-trained ImageNet weights:</h3><p>Using a pre-trained network downloaded from Keras for fine-tuning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*RYHGBejmHXJF5D9NnmAF1w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/536/1*HtmRU7Vu2a9qIlQ-jqpfQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*-0-6vNSAn8slF9hPgzAhCw.png" /></figure><p>Added more layers on top of VGG16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*_v_5p8dEr8FqC5cxT9LVcw.png" /></figure><h3>Start Training!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*BDnefqjP9ZS_Zr_rt_Ja2w.png" /></figure><p>After some epochs, validation accuracy increased to 73%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p59bDDAyM7oPNU4HDEFbfw.png" /></figure><p>Our prediction value is ranging from 0 to 1. We want to find the best threshold to separate into 0 and 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*GURyOegXOrisc63kZqs-xw.png" /></figure><h3>Finally, prepare for the FDA submission!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9wKOttdciIMGNuWDfFssuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*crp3CNVUsdFSASXTzkPSpA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*RDraLkQ2pgJuhtFIwKChEQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*vV1drMuPWPZQ7BvhEwvUKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*_URYOplhaakDnPkwcSbT-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*OBMEnqNssZEQ4X7fmA9a-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/583/1*oYxR5THtx5tQsn5aIB8Y3w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6862da35addb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Neuroengineering Research Proposal) Utilization of Transcranial Focused Ultrasound Optogenetics to…]]></title>
            <link>https://hannalee.medium.com/neuroengineering-technology-research-proposal-185eef8eb9a0?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/185eef8eb9a0</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 18:30:24 GMT</pubDate>
            <atom:updated>2023-08-08T22:48:56.438Z</atom:updated>
            <content:encoded><![CDATA[<h3>(Neuroengineering Research Proposal) Utilization of Transcranial Focused Ultrasound Optogenetics to Stimulate Medial Prefrontal Cortex Drd1 for the Treatment of Anxiety Disorders</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2XHfrtB4hz9mNVBnK8QaOA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkA6BySHGMljKZQL9ktJ4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HfMmWh8ggB54Pw8JqVR5Lw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nP89EPs9kPm3M3DeREb15g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CEfG4RhVVXYzuZ0AvJPmrQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NhKka75ufHvrZU4BXpApA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_NjbfN6OK7N4Pr3dJbUikA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=185eef8eb9a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Processing) Linear stretching; Histogram equalization; and Histogram specification]]></title>
            <link>https://hannalee.medium.com/image-processing-linear-stretching-histogram-equalization-and-histogram-specification-a04febc86167?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/a04febc86167</guid>
            <category><![CDATA[contrast]]></category>
            <category><![CDATA[image-processing]]></category>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Thu, 06 Apr 2023 23:51:00 GMT</pubDate>
            <atom:updated>2023-04-06T23:51:00.459Z</atom:updated>
            <content:encoded><![CDATA[<p>In digital image processing, various techniques can be used to enhance the contrast of an image. Three common methods are linear stretching, histogram equalization, and histogram specification:</p><h3>Linear stretching</h3><p>Linear stretching, also known as normalization or contrast stretching, is a technique that improves the contrast of an image by redistributing the intensity values across the entire intensity range. It maps the minimum pixel value in the input image to 0 and the maximum pixel value to the highest value in the intensity range (usually 255 for 8-bit images), while linearly scaling the values in between. Linear stretching increases the contrast in images with narrow intensity ranges by stretching the pixel values over a wider range.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*7u14BH3dveOgYs7fKEQSBg.png" /></figure><h3>Histogram equalization</h3><p>Histogram equalization is a more advanced contrast enhancement technique that redistributes the pixel values in an image so that the output image has a uniform histogram (i.e., equal frequency of occurrence for each intensity level). This method can be particularly useful for images with poor contrast due to uneven lighting or sensor limitations. Histogram equalization increases the global contrast of an image and makes hidden details more visible by spreading out the pixel values across the entire intensity range.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*G_niu9l3VDFkxgiIi_0kPg.png" /></figure><h3>Histogram specification (or histogram matching)</h3><p>Histogram specification is a technique that transforms the pixel values in an image so that its histogram matches a desired target histogram. This method can be used to standardize the appearance of images acquired under different conditions or to impose a specific histogram shape for aesthetic or other purposes. Histogram specification involves two main steps: first, perform histogram equalization on the input image; second, perform inverse histogram equalization on the equalized image using the target histogram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*JM2vwqWaDZHwjnXao9b8lQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a04febc86167" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Computer Vision Library in C]]></title>
            <link>https://hannalee.medium.com/computer-vision-library-in-c-96577b56cc48?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/96577b56cc48</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 02:37:12 GMT</pubDate>
            <atom:updated>2023-08-08T21:53:02.314Z</atom:updated>
            <content:encoded><![CDATA[<p>Code: <a href="https://github.com/hungryPanko/ComputerVision">https://github.com/hungryPanko/ComputerVision</a></p><h3><strong>[Panorama Stitching Algorithms]</strong></h3><p>The panorama stitching algorithm encompasses various computer vision techniques. These include finding <strong>key points</strong> in an image, <strong>describing</strong> them, <strong>matching</strong> them with key points in another image, computing the <strong>transformation</strong> between the two images, and ultimately <strong>stitching</strong> them together to create a panorama.</p><pre>image panorama_image(image a, image b, float sigma, float thresh, int nms, float inlier_thresh, int iters, int cutoff)<br>{<br>    // Calculate corners and descriptors<br>    descriptor *ad = harris_corner_detector(a, sigma, thresh, nms, &amp;an);<br>    descriptor *bd = harris_corner_detector(b, sigma, thresh, nms, &amp;bn);<br><br>    // Find matches<br>    match *m = match_descriptors(ad, an, bd, bn, &amp;mn);<br><br>    // Run RANSAC to find the homography<br>    matrix H = RANSAC(m, mn, inlier_thresh, iters, cutoff);<br><br>    // Stitch the images together with the homography<br>    image comb = combine_images(a, b, H);<br>    return comb;<br>}</pre><p>So we’ll find the corner points in an image using a Harris corner detector. Then we’ll match together the descriptors of those corners. We’ll use RANSAC to estimate a projection from one image coordinate system to the other. Finally, we’ll stitch together the images using this projection.</p><h3>1. Harris corner detection</h3><p>Before diving into the Harris corner algorithm, let’s address a question: Why corners? We aim to match patches in one image to patches in another image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*FITrbzo_soJZqCedio8Tjw.png" /></figure><p>Sky: bad</p><ul><li>Very little variation</li><li>Could match any other sky</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*FNF_V2fw029xxSjfWaIGhw.png" /></figure><p>Edge: ok</p><ul><li>Variation in one direction</li><li>Could match other patches along same edge</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*Q9pJgnWxdLl46FYukeNPhQ.png" /></figure><p>Corners: good!</p><ul><li>Only one alignment matches</li></ul><p>We can measure self-difference to find the corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*nZU-UZsfveAQ3neCCeZFCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*vMtvlKr86YoqM6RYClm6UQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*zRssPxNCfYAjn1m-v0WhTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*F-8kQ9tbjyDlpKefKDb7dA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0y91Sut1O-BV3ZTaVp9H0w.png" /></figure><p>However, self-difference is still expensive, it requires lots of summing.</p><p>We can use a <strong>gradient </strong>instead.</p><p>Look at <strong>nearby</strong> <strong>gradients</strong> <strong>Ix</strong> and <strong>Iy</strong></p><p>(SKY)</p><ul><li>If gradients are mostly zero, not a lot going on</li><li>Low self-difference</li></ul><p>(Edge)</p><ul><li>If gradients are mostly in one direction, edge</li><li>Still low self-difference</li></ul><p>(Corner)</p><ul><li>If gradients are in twoish directions, corner!</li><li>High self-difference, good patch!</li></ul><p>Using a structure matrix (Weighted sum of gradient information), the Eigenvectors/values of this matrix summarize the distribution of the gradients nearby.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*oUHyBI8ZORdmDf5EG2Uk4g.png" /></figure><p>λ1 and λ2 are eigenvalues. <br>(Sky) <strong>λ1 and λ2 both small</strong>: no gradient<br>(Corner)<strong> λ1 &gt;&gt; λ2</strong>: gradient in one direction<br>(Edge) <strong>λ1 and λ2 similar</strong>: multiple gradient directions, corner</p><p>Okay. Let’s look into Harris Corner Dectionec algorithms. We need to detect corners as regions of interest. The basic algorithm is:</p><pre>Calculate image derivatives Ix and Iy.<br>Calculate measures IxIx, IyIy, and IxIy.<br>Calculate structure matrix components as weighted sum of nearby measures.<br>Calculate Harris &quot;cornerness&quot; as estimate of 2nd eigenvalue: det(S) - α trace(S)^2, α = .06<br>  det(S) - α trace(S)^2 = λ1λ2 - α(λ1+λ2)2  (If these estimates are large, λ2 is large)<br>Run non-max suppression on response map</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*iIY4TPXk560liuBGDnzorg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*P6u6G80uGDrdLUIFRkq0bg.jpeg" /></figure><p>I also used some filterings and non-maximum suppression so that the matching is easier. Corners are marked with crosses. They seem pretty sensible! Lots of corners near where snow meets rock and such.</p><p>Ok, we found corners, now what?</p><p>Yes, We need to match image patches to each other.</p><h3><strong>2. Patch matching: Descriptors!</strong></h3><p>We want a way to represent an image patch. We can use descriptor. It can be very simple, we can use just <strong>pixels</strong>!<br>Finding matching patch is easy, distance metric: Σx,y (I(x,y) — J(x,y))2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmdYBW-OZNE7LDcGB3RS6g.png" /></figure><p>Yes, Actually descriptors can be more complex. Look at the image below. What if the second image rotates a little bit? Using just pixel doesn’t work to find the match in this case. We need more information such as gradient, scaling, translation, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6mxC7XPTKDcjXRP95csvDg.png" /></figure><p>To find the match, we could warp one image into the other. One image can have many image transforms and we need to successfully map them. Let’s take a look at how can we transform images.</p><p>Given a point x, map to new point x’ using M.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*p72NhoNDjI0_ViQUYNl1OQ.png" /></figure><p><strong>Scaling</strong> is just a matrix operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*_Ghxutl3-IV2Fj6E" /></figure><p><strong>Translation</strong>: add another row (called Augmented Vector) in the point X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*kv-DMxbMJivgovpe" /></figure><p><strong>Euclidean</strong>: rotation + translation</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2ON0MYsueF4xvL6x" /></figure><p><strong>Similarity</strong>: scale, rotate, translate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*HR4RlW5loUKp1rbK" /></figure><p>Affine: scale, rotate, translate, shear</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*a7VHkq3B1GUTb9p1" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P3g7FF3xbZ4yhx7FvFBGYg.png" /></figure><p>Say you want to translate, then rotate, then translate back, then scale.</p><p><strong>x’</strong> = <strong>S t R t x̄ = M x̄</strong>,</p><p>If <strong>M = (S t R t)</strong><br>M is still affine transformation. Wait, but these are all 2x3, how to we multiply them together? We can simply add [0,0,1] at the last row.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*xPHXyPuICT3PWnmK" /></figure><p>Let’s say we want affine transformation. Want to estimate <strong>A</strong> that maps from <strong>x</strong> to <strong>x’</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*EX4Qao4g9fpuxAvh" /></figure><p>For many x and x’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BtEtpUxK-kUICQ0M" /></figure><h3>Solve <strong>M a</strong> = <strong>b</strong></h3><p>Want to solve an overdetermined linear system:<br>M a = b<br>Want to minimize squared error: || b — M a ||². This is convex and minimized when gradient = 0. we take the derivative wrt a and set = 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*PNum3zxmVfCiZPDItKcHRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*48uthyv6bATMp4xnsK4PDg.png" /></figure><p>Oh, wait..</p><p>I found the <strong>best matches </strong>from the left image to the right image using descriptors. In a will, each descriptor only matches with one descriptor in b, but multiple descriptors in b can match with the same descriptor in a, which can cause problems. To avoid this, <strong>sort the matches by distance </strong>and <strong>remove any duplicate matches</strong> so that each match is one-to-one. This can be done by looping through the matches, keeping track of which elements in b have already been seen, and discarding any duplicates. The number of one-to-one matches can be determined with a single pass through the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sa5JCZm01EwcvmzpfwWPpA.jpeg" /></figure><h3><strong>3. RANSAC</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*v_KaxW70d6h_YicQSADkBQ.png" /></figure><p>How can we fit the model to inliers but ignore outliers? Using <strong>RAN</strong>dom <strong>SA</strong>mple <strong>C</strong>onsensus. Try a bunch of models, and see which ones are best!</p><p>To predict the projection between two sets of points using matches, we need to fit the projection to the data. However, this is difficult because there are many noisy matches and outliers in the data. One way to address this is by iterating through the points, projecting them using the homography(homography matrix), and verifying whether the projected point is close enough (L2 distance) to the corresponding point in the other image, using a specified threshold distance. Then, I used RANSAC to estimate a new model, drawing random matches.</p><p>Let’s look at the result by matching the corresponding corners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DLB9VLSdX7IcNtEaryvF9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sYCtrYtbkJMwq4auoTIHkA.png" /></figure><h3>4. Fitting the projection to the data</h3><p>To stitch two images together using a homography, follow these steps:</p><ol><li>Project the corners of b back onto the coordinate system for a using Hinv() to determine the bounds of the new image.</li><li>Place image a in the correct position in the new image.</li><li>Iterate over pixels that may map to image b, perform the mapping, and fill in the corresponding pixel in the new image using bilinear interpolation to determine the pixel value.</li></ol><p>Then, Voila!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ug0jE2gR8sadi3NneDDSkw.jpeg" /></figure><h3><strong>[Optical Flow Algorithms]</strong></h3><h4>1. Integral images and smoothing</h4><p>Optical flow is used on video, so it must be fast. To do this, structure matrices are calculated by doing aggregated sums over image regions. <a href="https://en.wikipedia.org/wiki/Summed-area_table">Integral images</a> are used instead of Gaussian filters to simulate smoothing with a box filter. I used the integral image to quickly calculate the sum of regions of an image.</p><h4>2. Lucas-Kanade optical flow</h4><p>Then, I implemented <a href="https://en.wikipedia.org/wiki/Lucas%E2%80%93Kanade_method">Lucas-Kanade</a> optical flow. We can use a structure matrix but this time with temporal information as well. The equation we’ll use is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oDJcUThjN4_FQzh2jT4nFA.png" /></figure><p>To compute the optical flow, a time-structure matrix is required, which includes both spatial and temporal gradient information. Spatial gradients are computed as usual, while the time gradient is calculated as the difference between the previous and the next images in a sequence.</p><h4>3. Calculating velocity</h4><p>Then, the velocity of each pixel in the x and y direction is calculated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wgNZxfdDGLjQgIFfh3SlMA.jpeg" /></figure><p>Check out my GitHub for much more about CV algorithms(NN, machine learning, filtering, convolutions, resizing, etc)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96577b56cc48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(Neural Engineering) Extracting multi-unit activity from ECog recording]]></title>
            <link>https://hannalee.medium.com/neural-engineering-extracting-multi-unit-activity-from-ecog-recording-d0ab1b722993?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0ab1b722993</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 09:11:21 GMT</pubDate>
            <atom:updated>2023-08-08T23:17:23.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JA401xHJS0HMnDOEFd-YeQ.png" /></figure><p><strong>Code: </strong><a href="https://github.com/hungryPanko/NeuralEngineering"><strong>https://github.com/hungryPanko/NeuralEngineering</strong></a></p><p>The objective is to extract and plot multi-unit activity from ECoG recordings with simultaneous optogenetic stimulation from a non-human primate cortex.</p><p>In the dataset, there are three signals corresponding to different stimulation patterns.</p><blockquote>Signal 1. Constant illumination for 1 second.</blockquote><blockquote>Signal 2. Illumination with 3Hz sign wave for 1 second</blockquote><blockquote>Signal 3. Illumination with 10Hz sign wave for 1 second.</blockquote><p>Each pattern is repeated 50 times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*zRbhw2sUZNRjFtHEKmlr3Q.png" /></figure><figure><img alt="Filtering signal between 500Hz to 5000Hz." src="https://cdn-images-1.medium.com/max/1024/1*vtElxhryhQikgjvmDqfZWw.png" /><figcaption>Filtering between 500–5000 Hz</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WxOMmLLLYzTs5QZwrbdEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vrj6rEDV5onl-CbwUOBp4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*wjIIZ0yzORlSu52d7vo8tg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*ABdBIosJLcMWHAn3VsOQmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kuOEsMBkXtWMabexsxM9Kw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*grxAvdXN2paNXMkHDMhj1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*_DUWlDDFpxjIL3x_joFZmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*-7MXOmdwbNlD9MHYNaJU1w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0ab1b722993" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI (Game Playing)]]></title>
            <link>https://hannalee.medium.com/ai-game-playing-b581af20f419?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/b581af20f419</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Tue, 14 Feb 2023 17:27:42 GMT</pubDate>
            <atom:updated>2023-02-14T17:27:42.685Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Minimax with alpha-beta pruning</strong></h3><p>code: <a href="https://github.com/hungryPanko/GamePlaying.git">https://github.com/hungryPanko/GamePlaying.git</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*z1ak6O2anRDgTft9qt9_Gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3-QVggf_dSGU0LcAU3d0Zg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*Bae-r2TnLoWZAUauUrCqHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*ky4EaDpi4nCwjHPMv5nXZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*FzBRIweUzDK0BND5CxZhZg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b581af20f419" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Road Sign Detection]]></title>
            <link>https://hannalee.medium.com/road-sign-detection-adae8b6a88a8?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/adae8b6a88a8</guid>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Tue, 14 Feb 2023 17:01:13 GMT</pubDate>
            <atom:updated>2023-02-19T09:15:30.457Z</atom:updated>
            <content:encoded><![CDATA[<h3>(Computer Vision) Road Sign Detection Tasks</h3><h3>Computer Vision — Multiple Object Detection</h3><p>Code: <a href="https://github.com/hungryPanko/MultipleObjectDetection">https://github.com/hungryPanko/MultipleObjectDetection</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHPVZYQmC01FDyO_nTcIxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*yEF1reOXpfl0gwY3FVs9jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*VUDYkvYGair0zy7e6P1s8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*Max2-_07a3lHIN61l4J78g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*NnZhF2ObVLRKs-JzHbk_pQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*yNGC_KLF4ygL9-RwvM2wRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*sv73jaMQEm1vxuGs3nqkOw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*SVkAxUTs3E3sapmjaEMSYA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*fJxvUx5jH5kU-4QfAjZ0Iw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*a92RS0DeZtL7h-KJUaqIQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*dDFP8cKl84Zy_am3fn0_5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*qFj8JN5g2rPjbPvndk9vHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*kJClULXWXp58W4Mh9ak7sA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*7vOYHu7BCR5zOeuqXcnm7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*hKoOnfUNs3TOBwjSjGkEqA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*6CDQvxyPfLSUHKTgdzPMfw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*XxYYquzL9osw3_tVmVJoug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*c4xj26ug1YT4E357n8ZXZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*MtenKxeCyXvV9D_LesfkQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*RuxBebt7d6Xk9JFAdtCgPQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*n-9hHbxuRTmxsOU2w0Ofvg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adae8b6a88a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building my own ML library from scratch]]></title>
            <link>https://hannalee.medium.com/building-my-own-ml-library-from-scratch-d6ca723f4fa9?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6ca723f4fa9</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Sat, 22 Oct 2022 18:10:11 GMT</pubDate>
            <atom:updated>2022-10-23T07:36:56.470Z</atom:updated>
            <content:encoded><![CDATA[<p>Code: <a href="https://github.com/hungryPanko/MachineLearning">https://github.com/hungryPanko/MachineLearning</a></p><p>I built my own ML library. This is not good as Sklearn, but it made me learn a lot of details in ML algorithms.</p><ol><li>Logistic Regression using Gradient Descent (Batch and Stochastic)</li></ol><p>2. Linear SVM and Gaussian Kernel SVM</p><p>3. Lasso</p><p>4. Decision Tree and Random Forest</p><p>5. Clustering) k-Nearest Neighbor Classifier</p><p>6. Clustering) Bipartite Graph Matching using the Hungarian Algorithm</p><p>7. Clustering) Spectral Clustering</p><p>8. Clustering) Clustering + k-Nearest Neighbor Classifier</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6ca723f4fa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Twitter Sentiment Analysis (Kaggle Competition)]]></title>
            <link>https://hannalee.medium.com/twitter-sentiment-analysis-kaggle-competition-a9491989a6b8?source=rss-206d85c68c89------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9491989a6b8</guid>
            <category><![CDATA[twitter-sentiment]]></category>
            <category><![CDATA[data-preprocessing]]></category>
            <category><![CDATA[kaggle-competition]]></category>
            <dc:creator><![CDATA[Hanna Lee]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 21:33:57 GMT</pubDate>
            <atom:updated>2022-03-10T21:33:57.812Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>1. Introduction/Objective</strong></h3><p>In this project, the data set will have “targets” or “labels” that can have 2 options for each tweet — positive, or negative. Even if the sentiment was predicted right for a tweet, the question is if the prediction of the model is also explainable to a lay person. On the other hand, if the prediction was off — What factors contributed to the missing prediction and how can this be improved. In this project, feature selection models, different ML algorithms, and avoiding bias and overfitting are explored to improve models.</p><h3><strong>2. ML Pipeline</strong></h3><h4>2–1.Data extraction and analysis:</h4><p>- Gather the data(download the file in the project) and analyze some Twitter messages to check how to do data preparation. I have noticed that there are so many webpage links and hashtags and check whether such data affect sentiments. Also, many words start with ** which means abusive words.</p><h4>2–2. Data preparation</h4><p>- Twitter messages are cleaned removing stopwords, changing words to stem words, removing webpage links, changing changed ** to ‘abuse’. After comparing the f1 score between with hashtags and without hashtags, I decided to remove them.</p><h4>2-3. Model training</h4><p>- TF-IDF, Word of Bags mixed with Naive Bayes, Word to Vector models are used for feature extraction. For each one, 2–4 classification ML models(Logistic Regression w/ threshold, Xboost, Neural Network, or Gaussian NB)are used to see the performance.</p><h4>2-4. Model evaluation and validation</h4><p>- Plot the learning curve and F1 score to see a high variance or bias per the number of features and regularization parameter. For the logistic regression, tune the threshold that gives the best f1 score.</p><h4>2-5. Trained and Test</h4><p>- Train the model with parameters, the number of features, and a threshold that gives the best performance. Then, test on the Kaggle evaluation set.</p><h3><strong>3. Evaluation Metric</strong></h3><p>F1 score is being used as the evaluation metric. It is the weighted average of Precision and Recall. Therefore, this score takes both false positives and false negatives into account. It is suitable for uneven class distribution problems.</p><p>The important components of F1 score are:</p><p>- True Positives (TP) — These are the correctly predicted positive values which mean that the value of the actual class is yes and the value of the predicted class is also yes.</p><p>- True Negatives (TN) — These are the correctly predicted negative values which mean that the value of the actual class is no and value of the predicted class is also no.</p><p>- False Positives (FP) — When actual class is no and predicted class is yes.</p><p>- False Negatives (FN) — When actual class is yes but predicted class is no.</p><p>- Precision = TP/TP+FP</p><p>- Recall = TP/TP+FN</p><p>- F1 Score = 2(Recall * Precision) / (Recall + Precision)</p><h3><strong>4. Loading the dataset</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SxmdSpcZ0u2zuBTb" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a5CWrOMBvPSxWo3u" /></figure><h3><strong>5. Data Preprocessing</strong></h3><p>1. Removing webpage, link, user, special characters, number, and hashtags</p><p>2. Replacing ***** by ‘abuse’</p><p>3. SnowballStemmer (It is the process of reducing the word to roots of words, e.g) cared -&gt; care, sings -&gt; sing)</p><p>4. not changed to negative, because word ‘not’ plays an important role in sentiment analysis</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M7WB1Ljy1qS4Cp_-" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*QNCgcBtoKzTGGAGa" /></figure><h3><strong>6. Train/ Valid/ Test splits</strong></h3><p><strong>x_train, x_valid, y_train, y_valid = train_test_split(df[‘tweet’], df[‘target’], random_state=42, test_size=0.2)</strong></p><p>‘Twitter_sentiments_data.csv’ is split into a train and validation set. The ratio is 8:2. The test set is the Kaggle evaluation dataset.</p><h3><strong>7. Feature selection and ML models</strong></h3><h4><strong>### (Model1) TF-IDF, Logistic Regression</strong></h4><p><strong>[TF-IDF Feature Selection]</strong></p><p>Compare F1 score between different algorithms on TF-IDF feature selection model. TF-IDF (term frequency-inverse document frequency) is a statistical measure that evaluates how relevant a word is to a document in a collection of documents.</p><p>(Insight)</p><p>- Pros: a word vector represents a document as a list of numbers, with one for each possible word of the corpus. Vectorizing a document is taking the text and creating one of these vectors, and the numbers of the vectors somehow represent the content of the text. TF-IDF enables us to associate each word in a document with a number that represents how relevant each word is in that document. Then, documents with similar, relevant words will have similar vectors, which is what we are looking for in a machine learning algorithm.</p><p>- Cons: In the preprocessing, many important words changed to stem words. For example, ‘not’ changed to ‘nega’ at the end. This might occur too often, thus the effect of these important features would be lower. Also, using n-gram, the relevance of the n-gram words would decrease as n increases. Also, it needs to tune min_df and max_df, which affects the performance a lot.</p><p><strong>##### Optimization</strong></p><p>1. Select the <strong>best number of feature</strong> to avoid underfitting and overfitting (Plot f1 scores and training/validation loss per the number of feature)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-RuMUKi71LNUsars" /></figure><p>2. Select the <strong>best hyperparameter</strong> (Plot f1 scores and training/validation loss per the hyperparameter value)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cFGAAcHp8ONrrtr3" /></figure><p>(Red line is validation loss and blue line is training loss on Loss curve graphs)</p><p>3. Select the <strong>best logistic regression threshold</strong> which predicts 1 if hypothesis is greater or equal to threshold. (Plot the validation f1 score per threshold)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3V7g1ZcbcloXzlrL" /></figure><p><strong>##### Insight</strong></p><p>The bi-gram gives much better performance (about 2% higher in F1 score) than Uni-gram. L1 regularization gives a little better performance than L2, because the TF-IDF bi-gram is a sparse model.</p><p>- Pros: faster than any other ML algorithms. Because of its efficient and straightforward nature, it doesn’t require high computation power, is easy to implement, easily interpretable.</p><p>- Cons: Many points to fine-tuning; L1 or L2 penalty selection, hyperparameter, the number of features, and hypothesis threshold. It is vulnerable to overfitting. If I select too many features, then validation loss increases a lot.</p><p><strong>##### Scalability</strong></p><p>I found Logistic Regression is much faster than other ML algorithms. Even if there is more data, this model would be great to scale. However, As the number of data increases, there are many points to do feature tunings: find the number of features, hyperparameter (regularization parameter), and hypothesis threshold.</p><p><strong>##### Interpretability/Explainability</strong></p><p>With a combination of TF-IDF feature sections, it has good interpretability/explainability. We can find the features having large weights. I used the function get_feature_names_out() to see the words with the highest weight.</p><h4><strong>### (Model2) Bag of Words Model with Naive Bayes feature selection, Logistic Regression</strong></h4><p>- Basic Logistic Regression with Naive Bayes Bag of Word model has good performance and is fast, thus this is selected as “Model no.2” with optimization. Also, it is good to compare with model no.1 which uses TF-IDF features.</p><p><strong>[Bag of Words Model with Naive Bayes feature selection]</strong></p><p>Compare F1 score between different algorithms on Bag of Words feature selection model. Features are selected based on the Naive Bayes model. Words with higher posterior probability are selected as features. The Naive Bayesian classifier is based on Bayes’ theorem with the independence assumptions between predictors. In the bag-of-words model, a text (such as a sentence or a document) is represented as the bag (multiset) of its words, disregarding grammar and even word order but keeping multiplicity. Neutral words might occur many times, but would not be helpful in the prediction of sentiments, thus I decided to choose the Naive Bayes model as features.</p><p>(Insight)</p><p>- Pros: A Naive Bayesian model is easy to build, with no complicated iterative parameter estimation which makes it particularly useful for very large datasets. When selecting a small number of features, it has good performance because feature words are selected based on high posterior probability first. Compared to using only the Bag of Words model, Naive Bayes Bag of Words performs better when there is a small data set or features.</p><p>- Cons: We have a lot of datasets (more than a million), thus even selecting a large number of features does not lead to overfitting. Naive Bayes Bag of words (feature selection with highest posterior priority) seems similar to a normal bag of words (feature selection with the highest occurrence) because we can choose high numbers of features because of the large data set.</p><p><strong>## Feature selection(list of words) using Naive Bayes Learning</strong></p><p>- P(positive|word) = P(word|positive)*P(positive)/P(word)</p><p>- P(negative|word) = P(word|negative)*P(negative)/P(word)</p><p>1. Find the common positive and negative words</p><p>2. The results will be used as features</p><p>example)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PIBPWjpVBOB-MAjY" /></figure><p><strong>##### Optimization</strong></p><p>1. Select the best number of features to avoid underfitting and overfitting (Plot f1 scores and training/validation loss per the number of features). Naive Bayes function returns the number of features with highest posterior probability words in positive and negative sentiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jAPwcA3KF6aCqXMa" /></figure><p>(Red line is validation loss and the blue line is training loss on Loss curve graphs)</p><p>2. Select the best logistic regression threshold which predicts 1 if the hypothesis is greater or equal to a threshold. (Plot the validation f1 score per threshold)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a4oavn6bY9bjXSAW" /></figure><p><strong>#### Insight</strong></p><p>L1 regularization gives a little better performance than L2, because Bag of Words is a sparse model.</p><p>- Pros: faster than any other ML algorithm. Because of its efficient and straightforward nature, it doesn’t require high computation power, is easy to implement, and is easily interpretable. Features are selected based on Naive Bayes words, thus no need to set parameters max_df=1.0, min_df=1 for BoW.</p><p>- Cons: Many points to fine-tuning; L1 or L2 penalty selection, hyperparameter, the number of features, and hypothesis threshold. It is vulnerable to overfitting. If I select too many features, then validation loss increases a lot. Moreover, multi-gram cannot be used. Only unigram can be used because feature words from Naive Bayes, which occurs only one time, are used as train BoW feature selection model.</p><p><strong>##### Scalability</strong></p><p>I found Logistic Regression is much faster than other ML algorithms. Even if there is more data, this model would be great to scale. However, whenever new data comes in, we need to go through all ML pipe lines from Naive Bayes features selection, BoW representation, and work on ML models. Moreover, as the number of data increases, there are many points to do feature tunings: find the number of features, hyperparameter (regularization parameter), and hypothesis threshold.</p><p><strong>##### Interpretability/Explainability</strong></p><p>With the combination of the BoW feature section, it has good interpretability/explainability. The first few words in BoW need to have higher weights, because the Naive Bayes function sorts words based on the highest posterior priority. Thus, we can know that if the first words have higher weights, the function works in the right direction. I used the functions get_feature_names_out() and coef_ to see the words with the highest weight.</p><h4><strong>### (Model3) BoW Model with NB feature selection, Extreme Gradient Boosting (xgboost)</strong></h4><p>- Xboost with Naive Bayes Bag of Word model has good performance but computational cost is high. Because of its performance, this is selected as model no.3 with optimization.</p><p><strong>##### Optimization</strong></p><p>1. Select the depth in trees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EOKSq7YVT5m8HOeQ" /></figure><p><strong>#### Insight</strong></p><p>L1 regularization gives a little better performance than L2, because Bag of Words is a sparse model.</p><p>- Pros: Optimization is straightforward by selecting the depth in trees.</p><p>- Cons: Computational cost is really high. I had to run the xboos model before I went to bed.</p><p><strong>##### Scalability</strong></p><p>XGBoost does not perform so well on sparse and unstructured data. A common thing often forgotten is that Gradient Boosting is very sensitive to outliers since every classifier is forced to fix the errors in the predecessor learners. The overall method is hardly scalable.</p><p><strong>##### Interpretability/Explainability</strong></p><p>If we look at the feature importances returned by XGBoost we see that age dominates the other features, clearly standing out as the most important predictor. For the Twitter sentiment classification, there is no category for words. node decides each word, not by category. Thus it ends up with so many words in each depth. Interpretability is very low because of the too wide tree shape for the project.</p><h4><strong>### (Model4) Word2Vec feature selection, Logistic regression</strong></h4><p>- Logistic Regression with Word2Vec model has good performance, thus this is selected as “Model no.4” with optimization. Also, it is good to compare with other models which use Logistic Regression.</p><p><strong>[W2V]</strong></p><p>Word embeddings are the modern way of representing words as vectors. The objective of word embeddings is to redefine the high dimensional word features into low dimensional feature vectors by preserving the contextual similarity in the corpus.</p><p>- Dimensionality reduction — significant reduction in the no. of features required to build a model.</p><p>- It captures meanings of the words, semantic relationships and the different types of contexts they are used in.</p><p><strong>##### Optimization</strong></p><p>1. Select the best number of features to avoid underfitting and overfitting (Plot f1 scores and training/validation loss per the number of features). → This cannot be done, because the computational cost for building W2V is too high. I set the number of features as 200</p><p>2. Select the best hyperparameter (Plot f1 scores and training/validation loss per the hyperparameter value)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*by1vvjPKtYahMTTu" /></figure><p>3. Select the best logistic regression threshold which predicts 1 if the hypothesis is greater or equal to a threshold. (Plot the validation f1 score per threshold)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gcb8wvBcK5Z9bIXu" /></figure><p><strong>#### Insight</strong></p><p>L1 regularization gives a little better performance than L2, because Bag of Words is a sparse model.</p><p>- Pros: Even with a small feature number, it shows great performance.</p><p>- Cons: Computational cost is high compared to other features selection models, TF-IDF and Word of Bags. I would like to try tuning the number of features, but it is impossible for me because it takes so long.</p><p><strong>##### Scalability</strong></p><p>I found Logistic Regression is much faster than other ML algorithms. Even if there is more data, this model would be great to scale. However, whenever new data comes in, we need to go through all ML pipl lines from Naive Bayes features selection, BoW representation, and work on ML models. Moreover, as the number of data increases, there are many points to do feature tunings: find the number of features, hyperparameter (regularization parameter), and hypothesis threshold.</p><p><strong>##### Interpretability/Explainability</strong></p><p>With the combination of BoW feature section, it has good interpretability/explainability. However, it is hard to show W2V performs better than TF-IDF or BoW because, I need to show covariance between two different vectors and how they affects the performance.</p><h4><strong>### (Model5) W2B, xgboost</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/0*iAW6WIdDQlsRku8J" /></figure><p><strong>#### Insight</strong></p><p>L1 regularization gives a little better performance than L2, because Bag of Words is a sparse model.</p><p>- Pros: Optimization is straightforward by selecting the depth in trees.</p><p>- Cons: Computational cost is really high. It took two days even for an incomplete run.</p><p><strong>##### Scalability</strong></p><p>XGBoost does not perform so well on sparse and unstructured data. A common thing often forgotten is that Gradient Boosting is very sensitive to outliers since every classifier is forced to fix the errors in the predecessor learners. The overall method is hardly scalable.</p><p><strong>##### Interpretability/Explainability</strong></p><p>If we look at the feature importances returned by XGBoost we see that age dominates the other features, clearly standing out as the most important predictor. Compared to WoB Xgboost, W2V Xgboost has narrow trees because we can choose small features selection. This is good for interpretability. However, it is hard to show W2V performs better than TF-IDF or BoW because I need to show covariance between two different vectors and how they affect the performance.</p><h3><strong>8. Other tested ML models</strong></h3><h4><strong>TF-IDF, Neural Network</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e9oNcYDaGoMs8YY_" /></figure><p>→ The last F1 scores I tested gave 0.78 but I don’t have time to run this model again. Computational cost is so high that feature selection is impossible with my computer.</p><h4><strong>BoW, Gaussian NB</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4IgvCPAHBuwhCyQ8" /></figure><h3><strong>9. Conclusion</strong></h3><p><strong>TF-IDF bi-gram with LR </strong>gives the best score:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x-9-RHaJdlRsiLlh" /></figure><p><strong>TF-IDF bi-gram with LR </strong>details:</p><p>TfidfVectorizer(min_df=20, max_df=0.9, ngram_range=(1, 2))</p><p>The number of features: 25,000, hyperparameter c=0.9, prediction threshold: 0.4368421052631579</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/0*KFwRSaEhAy5Wp8WG" /></figure><p>Change from unigram to bigram, L1 penalty, min_df, number of features, hyperparameter, and LR threshold play an important role in improving F1 Score.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9491989a6b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>