<?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 Tatiana Tikhonova on Medium]]></title>
        <description><![CDATA[Stories by Tatiana Tikhonova on Medium]]></description>
        <link>https://medium.com/@ttikh?source=rss-39354b54e835------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vCrd3rdwpYgPF5WPQaKdhw@2x.jpeg</url>
            <title>Stories by Tatiana Tikhonova on Medium</title>
            <link>https://medium.com/@ttikh?source=rss-39354b54e835------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 15:52:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ttikh/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[What would Alan Watts say if he were here with us today?]]></title>
            <link>https://medium.com/analytics-vidhya/what-would-alan-watts-say-if-he-were-here-with-us-today-1de4c14199ca?source=rss-39354b54e835------2</link>
            <guid isPermaLink="false">https://medium.com/p/1de4c14199ca</guid>
            <category><![CDATA[speech-synthesis]]></category>
            <category><![CDATA[speech-to-text-api]]></category>
            <category><![CDATA[text-to-speech]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[voice-synthesis]]></category>
            <dc:creator><![CDATA[Tatiana Tikhonova]]></dc:creator>
            <pubDate>Mon, 17 Apr 2023 01:40:41 GMT</pubDate>
            <atom:updated>2023-04-19T13:24:40.065Z</atom:updated>
            <content:encoded><![CDATA[<h4>(a practical guide to speech synthesis and text generation)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*Ud0gu3JXwWfEnPgGrU99pg.png" /><figcaption>Image generated by Stable Diffusion GRisk GUI 0.1</figcaption></figure><p>I found myself at a crossroads at the end of 2022: I needed a new project to have fun and learn something new but wasn’t sure which direction to take. After speaking with a couple of smart people, an idea began to take shape. If you think about skills you would like to develop and things that interest you, what might be at the center of your Venn diagram?</p><p>For me, it was the intersection of NLP and philosophy. I decided to gain some exposure to <strong>speech synthesis (</strong><a href="https://github.com/NVIDIA/tacotron2"><strong>Tacotron2</strong></a><strong> and </strong><a href="https://github.com/NVIDIA/waveglow"><strong>Waveglow</strong></a><strong>) </strong>that I hadn’t worked with before and also leverage <strong>text generation (</strong><a href="https://docs.aitextgen.io/generate/"><strong>aitextgen</strong></a><strong>)</strong>, thus finetuning 2–3 separate models that would think and speak like one of my favorite philosophers of all times.</p><p>As Alan Watts put it, “<em>the only way to make sense out of change is to plunge into it, move with it, and join the dance</em>”, and so the dance began.</p><h3>Material and Tech Specs</h3><p>I had over 50 hours of Alan Watts’ lectures, videos, audiobooks, and a small number of written materials. Equipped with a 16-core CPU and 8GB GPU Nvidia Geforce RTX 2070, I was aiming to achieve at the minimum half-decent results in a reasonable timeframe (or at least, that’s what I thought before noticing smoke coming out of my computer; but hey, getting a new motherboard and replacing CPU with a newer model only boosted the speed of the experiment).</p><p>I had to deal with a number of environment setup issues, and I covered some of them <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/debugging_errors.py">here</a> if it helps. Feel free to ignore the “Poor alignment” section altogether because it is missing the most important garbage-in-garbage-out cause, which you’ll read about below. (And yes, as you may have noticed, I’m using Windows).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01cdcff32ccf38c52c9159ff8d44ef7d/href">https://medium.com/media/01cdcff32ccf38c52c9159ff8d44ef7d/href</a></iframe><h3>Model Overview</h3><p>Let’s quickly get on the same page as to what we’re dealing with here.</p><ul><li><a href="https://github.com/NVIDIA/tacotron2"><strong>Tacotron2</strong></a><strong> </strong>(<a href="https://arxiv.org/pdf/1712.05884.pdf">original paper</a>)<strong> </strong>is an end-to-end neural network text-to-speech (TTS) system that takes a sequence of characters as input and outputs a sequence of mel-spectrogram frames, which represent the acoustic features of the speech. The model’s architecture includes an encoder network that converts text into a high-level semantic representation, an attention mechanism that aligns the input text with the generated spectrogram, and a decoder network that converts the aligned spectrogram into a raw audio waveform. By training the model on a specific person’s speech data, the model can learn unique patterns and nuances of that person’s speech style and generate spectrograms that reflect that style, which would include the unique patterns of their speech, intonation, rhythm, and emphasis on certain words. While we can take advantage of the Tacotron2 decoder network to directly convert the aligned mel-spectrograms into raw audio waveforms, the quality of those may not be optimal in terms of naturalness, clarity, and overall fidelity, and that’s why we need Waveglow.</li><li><a href="https://github.com/NVIDIA/waveglow/"><strong>Waveglow</strong></a><strong> </strong>(<a href="https://arxiv.org/pdf/1811.00002.pdf">original paper</a>) is a flow-based generative model that takes mel-spectrograms (generated by Tacotron2) and produces natural-sounding synthesized speech by modeling the probability distribution of audio waveforms using a deep neural network architecture, which enables it to capture the complex structure of speech signals. It also creates a set of conditioning parameters that are used to guide the generation of the audio waveform and which help ensure that the generated audio waveform captures important aspects of the speaker’s voice, such as pitch, tone, and accent, making it sound natural and realistic.</li><li><a href="https://docs.aitextgen.io/"><strong>Aitextgen</strong></a><strong> </strong>is a transformer-based language generation model. It is built on top of the popular Hugging Face Transformers library and uses OpenAI’s GPT-2 architecture for natural language processing tasks such as text generation, summarization, and question-answering. I was exhausted by the end of my struggle with Tacotron2/Waveglow, and so working with a more straightforward, simple model like Aitextgen was the long-awaited reprieve.</li></ul><h3>Preprocessing for Text Generation</h3><p>Pretty straightforward here: <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/text_generation/text_convert_to_txt.py">convert ebooks to text</a> and <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/text_generation/text_cleanup.py">clean</a> thereafter. <a href="https://towardsdatascience.com/nlp-working-with-books-fc82d8e9b0dc">Helpful writeup</a> if you are working with books. As mentioned, I was using Aitextgen for generating text (more on that below); the exact preprocessing steps will, of course, depend on the model that you are planning to leverage.</p><h3>Preprocessing for Speech Synthesis</h3><p>This is where things get convoluted, partially due to my being utterly unfamiliar with speech synthesis, and partially due to the objective complexity of the endeavor. Two high-level overviews helped me approach this unknown terrain: <a href="https://docs.aitextgen.io/helpful-notes/">jaimeleal’s short guide</a> and <a href="https://youtu.be/T5TwFCp-np8">a youtube guide on training a custom voice model</a> — that’s on top of the official model repos, internet surfing, and Q&amp;A with ChatGPT (also planning to integrate 4 beta with a Telegram bot later down the line).</p><p>What we need to understand is that for training Tacotron2, we need pairs of audio clips and their corresponding subtitles, with mapping defined in a separate file. Waveglow only requires audio to be trained, so not much hassle there.</p><p>I tried to keep steps chronological in my repo if you decide to reference it, and here are the main highlights:</p><p><a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/0_audio_convert_to_wav.py">1. Bring all audio to the same denominator</a>, i.e. сonvert mp4, mp3, avi, etc. to wav. If you have multiple cores at your disposal, Multiprocessing (or Celery task queue paired with Redis broker) comes to the rescue.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9735623fce7c0e04c80a2cebadd7578c/href">https://medium.com/media/9735623fce7c0e04c80a2cebadd7578c/href</a></iframe><p><a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/1_reduce_noise.py">2. Reduce noise</a>. The overall quality of Alan Watts’ lectures was on the low end, and sometimes noise reduction only exacerbated the issue. After many launch attempts, I can’t remember if I settled on using it but may be worth trying.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49c0e7d107c3ac906fe870a92bac61ca/href">https://medium.com/media/49c0e7d107c3ac906fe870a92bac61ca/href</a></iframe><p><a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/2_remove_silence.py">3. Remove silent parts if applicable</a>. May not be worth doing before you split your audio files into smaller segments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/058f0229ca3b110b009b7423c5813d06/href">https://medium.com/media/058f0229ca3b110b009b7423c5813d06/href</a></iframe><p><a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/3_audio_split_into_segments.py">4. Split audio</a>. It’s embarrassing to admit how long it took me to realize that the shorter segments the better the model would train and the faster it would converge. I started with 60-second segments, reducing and retraining on 15, and finally 4–7 sec. Do not repeat my mistakes. :)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/398504856fab3a10bafbb7525dce1d32/href">https://medium.com/media/398504856fab3a10bafbb7525dce1d32/href</a></iframe><p><a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/4_audio_Google_transcribe_with_multiprocessing.py">5. Transcribe</a>. Speaking of embarrassing mistakes, I <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/4_audio_Autosub_transcribe_with_multiprocessing.py">tried leveraging a free Autosub library</a>, and after seeing that it returned a word error rate of under 30 for a couple of files that I tested, I launched the training process only to hear my AI-Alan moo and hiss during inference. After some uneventful but time-consuming debugging dives, it finally occurred to me to eyeball the transcripts, and it all became clear: garbage in, garbage out. I spent a few dollars on transcribing audio via <a href="https://cloud.google.com/speech-to-text?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=na-US-all-en-dr-bkws-all-all-trial-e-dr-1605212&amp;utm_content=text-ad-none-any-DEV_c-CRE_553443483826-ADGP_Desk%20%7C%20BKWS%20-%20EXA%20%7C%20Txt%20_%20AI%20%26%20ML%20_%20Speech-to-Text_Speech%20to%20Text_General-KWID_43700066933719490-kwd-21425535976&amp;utm_term=KW_google%20speech%20to%20text-ST_google%20speech%20to%20text&amp;gclid=CjwKCAjwue6hBhBVEiwA9YTx8DSMwhM5w5_ypETWLY1upKFrY9wd2STyzADlqY2ixsXpM9VQ_kOYFBoCx-YQAvD_BwE&amp;gclsrc=aw.ds">Google Speech to Text</a> API after that, making my AI-Alan’s speech graduate from the animal kingdom to sapiens. (Cost me under $78 to transcribe over 50 hours of audio and took less than a couple of hours, with almost perfect WER — compare that to almost 10 hours of processing by Autosub distributed by Multiprocessing over 16 cores, with barely intelligible transcription in the end).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23609ccd239296b230fed9654bf90734/href">https://medium.com/media/23609ccd239296b230fed9654bf90734/href</a></iframe><p><a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/5_audio_transcript_cleanup_filelists_setup.py">6. Create reference files</a>. This step mostly boils down to removing transcripts that have no matching audio and vice versa, plus setting up the lists of files that both Tacotron2 and Waveglow models require. Your Tacotron2 <em>audio_text_test_filelist.txt</em> or <em>metadata.csv </em>would consist of pairs of path_to_file and transcript, like “…/1_1_The_Four_Noble_Truths.wav|you realized that is impossible to do because the motive”. Waveglow’s file would just be a list of audio to train on, no transcripts required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/454b6daefee83f3b275f46de68a0d374/href">https://medium.com/media/454b6daefee83f3b275f46de68a0d374/href</a></iframe><p>7. Download pre-trained models published in the official repos for Tacotron2 as well as Waveglow (links are in the corresponding repo README).</p><p>8. And finally, get your mind broken by trying to figure out the appropriate hyperparameters to get it all to work. I give all credit to Tacotron2 Issues opened in the repo, ChatGPT, and Stackoverflow for helping me figure out what is what. Made some notes for future travelers <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/tacotron2_waveglow_model_files/tacotron_hparams.py">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3df7d4edee503e811984d58f4d1b7157/href">https://medium.com/media/3df7d4edee503e811984d58f4d1b7157/href</a></iframe><p>It all made sense to my tired brain at the time, but do let me know if you spot inconsistencies. I’ll talk more about parameters below and why after tons of experimentation I ended up going mostly with defaults.</p><h3>Speech Synthesis: Tacotron2</h3><p>The number of hours I spent debugging why the alignment wouldn’t form before realizing that I all I had to do was<strong> cut the audio duration and get the correct subtitles</strong> is too painful to admit.</p><p>With my modest 8GB GPU and clips of 4–7 second duration, I was able to snatch a batch size of 32, starting with the learning rate of 1e-3 and ending on 1e-7 towards the end. After fixing the main issues with audio/transcripts, I no longer had to spend time fine-tuning Tacontron’s hyperparameters, everything just finally fell into place.</p><p>I trained for about 500 epochs, which took a (very) long time considering a single GPU and 44,151 audio clips per epoch, but patient turtles win the race 🐢. I could’ve switched over to the cloud as I did for text generation or audio transcribing, but after setting up all of the environments locally, it felt unbearable to transition.</p><p>I didn’t speak much about the <strong>setup </strong>(traumatic memories — let the sleeping dogs lie), but you do obviously need to clone the repos and install all of the dependencies, incl. Pytorch with CUDA. Make sure your GPU is cuda-compatible; here’s <a href="https://stackoverflow.com/questions/60987997/why-torch-cuda-is-available-returns-false-even-after-installing-pytorch-with">a MUST-read via Stackoverflow</a> to confirm that both GPU and drivers support the CUDA version you’ve installed (or are about to install).</p><p>I ended up using the Anaconda terminal, and would typically have 3 sessions open:</p><ul><li>1 for training,</li><li>1 for checking logs in Tensorboard,</li><li>and 1 with a Jupyter for an occasional inference check via <a href="https://github.com/NVIDIA/tacotron2/blob/master/inference.ipynb">inference.ipynb</a>.</li></ul><p>So, after the pre-processing step #8 above, where you need to update your hyperparameters to point to the correct file paths, you might want to decide to <strong>warm start from the Tacotron2 pre-trained model</strong> that you’ve downloaded in #7. For those unaware, warm-starting can be used to initialize the encoder and decoder networks with pre-trained weights from another model, which helps the model to learn more quickly and effectively from the available training data, thus leading to faster convergence.</p><pre># warm start from a pretrained model<br>conda activate pytorch3<br>python E:/tacotron2/train.py - output_directory E:/tacotron2/checkpoints - log_directory E:/tacotron2/logdir - max-split-size-mb 8000 -c tacotron2_statedict.pt - warm_start<br><br># resume from a checkpoint (session #1)<br>python E:/tacotron2/train.py - output_directory E:/tacotron2/checkpoints - log_directory E:/tacotron2/logdir - max-split-size-mb 8000 -c checkpoints/checkpoint_50000<br><br># launch Tensorboard (session #2)<br>conda activate pytorch3<br>tensorboard - logdir=&quot;E:/tacotron2/logdir/&quot; - launch the board<br><br># debug if Tensorboard is empty<br>tensorboard - inspect - logdir=&quot;E:/tacotron2/logdir/&quot; # check if it&#39;s seeing the event files<br><br># run inference (session #3)<br>conda activate pytorch3<br>cd /d e:/tacotron2<br>jupyter notebook # inference.ipynb</pre><p>I was mostly interested in making sure that the<strong> training loss </strong>(how well the model is able to fit the training data) and <strong>validation loss </strong>(how well the model is performing against the validation set) are both steadily trending downward, and kept an eye on the ever-present alignment.</p><p>In TensorBoard, the x-axis for these two chars represents the number of training steps. The y-axis represents the actual loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nyG_6HuUfxAw1ujvNggvlw.png" /></figure><p>As a general rule of thumb, a reasonable expected decrease in validation loss for Tacotron2 training is around 0.1 to 0.2 per epoch (which typically consists of several thousand steps). When either starts plateauing, I would decrease the learning rate and restart from the latest checkpoint (I started with 1e-3 and ended on 1e-7). I would also run periodic inference using different checkpoints to check synthesis quality.</p><p>Note that you may run into situations when one loss is decreasing, e.g. training loss dropping, and validation loss is staying even or even increasing — this might indicate that the model is overfitting and not generalizing well to the validation data. Hence it’s important to monitor both the training and validation losses and consider techniques such as early stopping, regularization, or increasing the amount of data to prevent overfitting.</p><p><strong>Training time</strong>. You can see in the repo that the <a href="https://github.com/NVIDIA/tacotron2/blob/185cd24e046cc1304b4f8e564734d2498c6e2e6f/hparams.py#L12">suggested number of epochs</a> to train for is 500. What it means is that the model is expected to go over the entire training dataset 500 times. Say, you have 10,000 clips to train on and you can go as high as 32 for your batch size. Therefore the overall training time you might plan for is (500 epochs x 10000 clips) / 32 = 156,250 steps. Generally, it is recommended to train Tacotron2 until it converges and the validation/training loss stops improving significantly.</p><p><strong>Alignment</strong>. Fun fact I’ve learned is that it’s possible that the stable/persistent alignment diagonal may not form at all during training. While the alignment diagonal can be an indication of good model performance, it is not a guarantee of solid synthesis quality. It’s expected to form during the early stages of training when the model is still learning to align each input frame with its corresponding output frame. However, as the model learns to align frames that are not necessarily adjacent, the diagonal attention pattern may dissolve, and the attention mechanism would become more distributed and flexible. This is generally expected to happen in later stages of training when the model has been trained with enough data and given enough time to learn more complex alignments.</p><p>Therefore, you do not need to restart the training if the attention diagonal breaks and dissolves. Instead, it is more important to monitor the training/validation loss, and convergence of the model, and stop training when there is no significant improvement in performance after a reasonable amount of time.</p><p>Quite often I would see no diagonal during training, but get it during inference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7NxA_-2g2teq4gKg.png" /><figcaption>author’s screenshot using <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/tacotron2_waveglow_model_files/inference.ipynb">inference.ipynb</a></figcaption></figure><p>I remember seeing <a href="https://user-images.githubusercontent.com/39617376/68069699-ddd69b00-fd9e-11e9-8d32-eec15e84eb30.gif">this gif</a> showing incremental alignment formation, but to me it felt like an impossible standard as my diagonal would form and dissolve, then form again, which was something I’d expect to happen during training for reasons mentioned above.</p><p>Eventually, I stopped at 621K steps. I had 44,151 audio clips and used a batch size of 32, so it’d take me 1,380 steps to get a full iteration of 1 epoch → dividing 621K by 1380, and we land with around 450 completed epochs. The quality of my MVP was good enough to stop, and stop I did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*um_8pWRoQUUz6NK78s6i5g.png" /></figure><h3>Speech Synthesis: Waveglow</h3><p>Now it was Waveglow’s turn! You can configure params for Waveglow in its <a href="https://github.com/NVIDIA/waveglow/blob/master/config.json">configuration file</a>. I mostly played around with the learning rate and sigma parameters (landed on 1e-4 → 1e-8 towards the end + sigma of 0.666–1), leaving everything else be. Training Waveglow demands more processing power, so I was only able to fit in a batch of 6. As you can see from the config, the suggested number of epochs is 100,000… there was no way I would stick to that many, considering that the goal is a simple proof of concept, so I let it run (gradually decreasing the learning rate as with Tacotron2) until about 754K steps (or ~102 epochs).</p><pre># train<br>conda activate waveglow3 # had one conda env set up for Tacotron2, one for Waveglow - as you can see by number 3, the first two attemps were not as successful)<br>cd /d e:/tacotron2/waveglow<br>python E:/tacotron2/waveglow/train.py -c E:/tacotron2/waveglow/config.json<br><br># tensorboard<br>tensorboard - logdir=&quot;E:/tacotron2/waveglow/checkpoints/logs&quot;<br><br># inference<br>conda activate pytorch3<br>cd /d e:/tacotron2<br>jupyter notebook # inference.ipynb</pre><p>The problem I was having with Waveglow is that if I interrupted training, resuming from a checkpoint thereafter, it’d start logging from 0 (which was different from Tacotron2 where you’d have an accumulative number of iterations with corresponding historical trends in Tensorboard). Not sure if there is a way around it, but it didn’t bug me as much except that it was hard to see the historical trend for training loss and keep track of completed epochs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QnQVeGtV3_-Xf1dH.png" /></figure><h3>Text Generation: aitextgen</h3><p>Towards the end of this endeavor I was inclined to keep it simple and leave sophistication for another project to be, so I went with aitextgen that took me under 15 minutes to set up and start generating results. I’ve published <a href="https://github.com/tikhonova/what_would_alan_watts_say/blob/master/text_generation_with_aitextgen.ipynb">some helpful likes as part of the Colab</a>, and included some snippets of the output that do sound like something Alan Watts might have said. I would generate a sentence, and then feed it back to generate more.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2de13d3d3bc2a7b592d5b21ee5fed8e2/href">https://medium.com/media/2de13d3d3bc2a7b592d5b21ee5fed8e2/href</a></iframe><h3>Results</h3><p>The question is, does the voice sound a little bit like his as well? Reminder that the below results are derived from Tacotron2 trained for ~450 epochs and Waveglow ~100 epochs. I did not have any clean audiobooks available for training, it was mostly recorded live lectures, so the original quality is questionable to begin with. (I know, excuses, excuses…)</p><blockquote>The modern world feels transformed into a marvelous degree, into a single bioelectronic body.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*S4fQ4B0XcQPx0IT-nURt3g.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F1494145870%26show_artwork%3Dtrue&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fsuninmycup%2Fmarvelous%3Fsi%3D009f25147fb34ab78b9f3b088bb3b25c%26utm_source%3Dclipboard%26utm_medium%3Dtext%26utm_campaign%3Dsocial_sharing&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7586d7d157a93effff3bf689795ea9a/href">https://medium.com/media/b7586d7d157a93effff3bf689795ea9a/href</a></iframe><blockquote>In many years, it is going to be absolutely incomprehensible for most people that they are not one with the universe.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*TIY7El-SKFCAE1j1uiOH9w.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F1494163666%26show_artwork%3Dtrue&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fsuninmycup%2Fnot-one-with-the-universe-1%3Fsi%3D7fe17325e3cc4b3dacf6a1def97f57e4%26utm_source%3Dclipboard%26utm_medium%3Dtext%26utm_campaign%3Dsocial_sharing&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4af01a5189fdb22af1f7e12d6120f5c/href">https://medium.com/media/f4af01a5189fdb22af1f7e12d6120f5c/href</a></iframe><blockquote>What is happening now is a game. That is, the whole world is playing.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*qOKtb1uNz07ZndJVKTwKMg.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F1494150760%26show_artwork%3Dtrue&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fsuninmycup%2Fplaying%3Fsi%3Dd9318a3636ff4a478e73219e6bea8273%26utm_source%3Dclipboard%26utm_medium%3Dtext%26utm_campaign%3Dsocial_sharing&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6272da9366b62951de84d77af304128/href">https://medium.com/media/c6272da9366b62951de84d77af304128/href</a></iframe><h3><strong>Conclusion</strong></h3><p>In the words of the one and only Alan Watts, “<em>This is the real secret of life — to be completely engaged with what you are doing in the here and now. And instead of calling it work, realize it is play</em>.” Considering this was my first time working with speech synthesis and transformers in general and these specific models in particular, I pronounce this past game successful and the play fully enjoyed. On to more tech toys and endeavors!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1de4c14199ca" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/what-would-alan-watts-say-if-he-were-here-with-us-today-1de4c14199ca">What would Alan Watts say if he were here with us today?</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From dogs to classifiers]]></title>
            <link>https://medium.com/analytics-vidhya/from-dogs-to-classifiers-2baf495e6a27?source=rss-39354b54e835------2</link>
            <guid isPermaLink="false">https://medium.com/p/2baf495e6a27</guid>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[analysis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[study]]></category>
            <dc:creator><![CDATA[Tatiana Tikhonova]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 00:02:19 GMT</pubDate>
            <atom:updated>2021-05-17T16:20:30.726Z</atom:updated>
            <content:encoded><![CDATA[<p>Breaking down complexity into corgi steps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJJ0Qdebu_-PT29gZCJ6fw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@alvannee">https://unsplash.com/@alvannee</a></figcaption></figure><p>Sometimes you don’t have to choose pleasure over productivity, and in those rare moments, you go all in. Need to prepare a capstone project using neural networks, but still aim to have fun? Puppies to the rescue!</p><p><strong>Problem Statement</strong></p><p>So first things first. The purpose of this project is to use a convolutional neural network (CNN) that would help predict dog breeds. You might argue the breed doesn’t matter, it’s the fluffiness that counts. Well, dog breed identification can in fact be considered essential for many reasons, particularly for understanding individual breeds’ conditions, health concerns, interaction behavior, among other things. If the model I create turns out to be successful, it can be used in reducing the amount of manual effort required to categorize large volumes of unlabelled dog image data.</p><p>The good news is that with contemporary machine learning frameworks like TensorFlow and pretrained models for image recognition, the task can be accomplished with pretty good accuracy without applying too much effort and spending too much time and resource. But that’s all theory, let’s see how it goes in practice!</p><p><strong>Strategy to solve the problem</strong></p><p>I settled on building a pipeline that can be used in the web/app for processing real images taken by users. The model accepts any user-supplied image as input. If a dog is detected in the image, it will estimate the dog’s breed. If a human is detected on the other hand, it will provide a resembling dog breed… Oh, the intrigue! (As you can judge from below, the results may get really disturbing, so I officially mark this project as PG-13.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*-YqzxtTjLs1_rDrTIJo9Pg.png" /><figcaption>Image by Author</figcaption></figure><p><strong>Metrics</strong></p><p>My journey started with building CNN from scratch which resulted in accuracy under 4%. While the result wasn’t pleasant, it was something to be expected, considering how simplistic the model was. It’s important to note, however, that accuracy is not the universal metric that one should be focused on when training their model: while it may serve well for some purposes, for others it may be best to use precision, recall, or F1, for example. The reason why I decided to go with accuracy was because the classes of the dog breed dataset were relatively balanced, therefore a simple accuracy score seemed to be sufficient.</p><p><strong>Data Exploration and Visualization</strong></p><p>Udacity provided me with several datasets: one for dogs, the other for humans.</p><p>The human dataset consisted of 13,233 images of human faces that I detected with an OpenCV algorithm, <a href="https://docs.opencv.org/master/db/d28/tutorial_cascade_classifier.html">Haar feature-based cascade classifier.</a></p><p>The dog dataset consisted of 133 dog breed categories and 8,351 images, of which 6,680 images were used for training, 835 for validation, and 836 for testing. The entire puppy dataset was put to use for training my CNN model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*vc97TyOiPDTHlra0TIn_xg.png" /><figcaption>Image by Author</figcaption></figure><p>As you can see from above, there are on average ~50 images per dog breed, with the minimum being 41 and the maximum reaching 70. While I previously mentioned that the representation is quite balanced, now you can see that for yourselves.</p><p><strong>Data Preprocessing</strong></p><p><em>Human images:</em> it is standard practice to convert the images to grayscale before applying any face detection algorithms. Hence, I used the detectMultiScale(gray) function, which executes the Haar cascade classifier stored in face_cascade and takes the grayscale image as a parameter.</p><p><em>Dog images: </em>the images were presented in different sizes and dimensions, so I had to reduce all to 224 x 224 pixels as part of the pre-processing step in order to fit my network architecture. Then the images were converted to 4D tensor, with applied preprocess_input applied to get the 4D tensor ready for any pre-trained model in Keras.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*Q1LlZq6qF4WaPfvGDngynA.png" /><figcaption>Image by Author</figcaption></figure><p><strong>Implementation &amp; Modeling</strong></p><p>I used the following architecture that delivered the best results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*_lAHnB_b1N2vfMyTbYZvAw.png" /><figcaption>Image by Author</figcaption></figure><ul><li>I defined <strong>four convolutional filters</strong> of increasing size (from 8 to 16 to 32 to 64).</li><li>I used the <strong>stride length of 2 </strong>as it ran much faster as compared to 1 (which was slow and not more accurate).</li><li>I chose <strong>GlobalAveragePooling </strong>as it is recommended in CNNs to reduce spatial dimensions for classification purposes.</li><li>I selected <strong>5 epochs</strong> because that is all it took to get to &gt; 1% accuracy.</li><li>I used <strong>MaxPooling </strong>layer to reduce the dimensions of input images along CNN layers, which should also counteract the danger of overfitting.</li></ul><p>I tried running CNN without the pooling layers, but it ran way slower and the accuracy was much lower. This is because pooling is typically used for dimension reduction. It’s safe to use here since the neighboring pixels are likely similar and downsampling will not reduce the classifier’s ability to detect the image.</p><p><strong>Refinement &amp; Hyperparameter Tuning</strong></p><p>The first version of CNN was far from being epic. Its accuracy was under 4%! But let’s stay positive: it’s still better than random, but yes, there’s plenty of room for improvement. First, I tried utilizing the VGG16 model, which returned the accuracy score of 39%. Then I switched to a different pre-trained model, Inception V3. That’s where things got interesting…</p><p>First, I obtained bottleneck features from the Inception V3 and then built an architecture for it. It performed best with the global average pooling since that method reduces the dimensionality of each feature map while retaining the most important information, which makes it an efficient and tidy architecture. I made sure to add a dropout layer that would reduce overfitting. The final layer of the model was used to predict the dog breed category.</p><p><strong>Model Evaluation and Validation</strong></p><p>Going back to the simple OpenCV human face detector, it performed quite well: it was able to identify 100% of all humans; however, it also identified 11% of dogs as humans…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*R2IstFT4d2ze73rkKc-_Mg.png" /><figcaption>Image by Author</figcaption></figure><p>The dog detector, on the other hand, was able to confirm that 100% of all dogs were dogs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*5OiJSlZB-Eacl2r4rRVprA.png" /><figcaption>Image by Author</figcaption></figure><p>With the dog breed classification model, the training accuracy (after 50 epochs), reached over 95%, with the validation accuracy being way lower (85%). Furthermore, the test accuracy reached only 80%, showing that the model is, unfortunately, overfitting. This is probably because we were still using a very small dataset with only 133 categories and 6,680 training images. But hey, it could’ve been worse!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*fuHq_cSbMQaeYj7xCNAPMA.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*FPej00VU7uk9tNM5_0yNTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*suzFeFHiV0IVnSk6p_Kb4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*YC7u6s7oVTnLNRKFMk-NwA.png" /><figcaption>Image by Author</figcaption></figure><p><strong>Conclusion</strong></p><p>I started from scratch with a CNN model that had an accuracy score of only 3.7% and trained two models with 39% (VGG-16) and 80% (Inception-V3) accuracy using transfer learning. What I found challenging was the act of choosing the right model as well as its lengthy training time. What I found interesting on the other hand was that the model identified a resembling dog breed when supplied an image of a human. Who else would ever show me a picture of a human and claim it resembles a mastiff, if not our very own Mr. Python?</p><p><strong>Improvements</strong></p><p>My model performed as expected: it’s good, but not perfect. The algorithm can still be improved: one could possibly change hyperparameters, increase the training dataset, and use data augmentation techniques that would introduce variations of the images, so the model can generalize its learning better and increase the accuracy even further.</p><p><strong>Resources</strong></p><p>Udacity provided the dataset, so no external sources were required. The actual work done can be found on here on my <a href="https://github.com/tikhonova/dog_classifier">Git</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2baf495e6a27" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/from-dogs-to-classifiers-2baf495e6a27">From dogs to classifiers</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The beast of your Amazon spendings, and the best way to face it.]]></title>
            <link>https://medium.com/data-science/the-beast-of-your-amazon-spendings-and-the-best-way-to-face-it-cebf428178f2?source=rss-39354b54e835------2</link>
            <guid isPermaLink="false">https://medium.com/p/cebf428178f2</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[hands-on-tutorials]]></category>
            <category><![CDATA[regression-analysis]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[editors-pick]]></category>
            <dc:creator><![CDATA[Tatiana Tikhonova]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 03:07:51 GMT</pubDate>
            <atom:updated>2021-01-18T23:19:56.684Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://towardsdatascience.com/tagged/hands-on-tutorials">Hands-on Tutorials</a></h4><h4>Cutting through the haze of data with the CRISP-DM sword, and conquering the money monster with Python by our side.</h4><figure><img alt="A cardboard creature with fearful expression made of Amazon boxes" src="https://cdn-images-1.medium.com/max/1024/1*pCvAG8BFYn775Kug1-HdUg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@helloimnik?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Hello I’m Nik 🎞</a> on <a href="https://unsplash.com/s/photos/amazon?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Do you tend to make small online purchases without thinking how much those add up to? Want to see your total spendings, but too afraid to open your purchase history? Trust me, you and I are in the same rocking boat.</p><p>While I consider myself a rational buyer, not a year went by without me wondering how much of my earnings went down the Amazon drain. On and on I’ve been making one-click purchases, soothing my conscience by ordering via <a href="http://smile.amazon.com/about">smile.amazon.com</a> that donates half a percent of eligible purchase prices to charities, without looking at the summary stats. Up until now, I couldn’t possibly comprehend how to face the reality without spending an additional hundred on anti-anxiety meds, but Data Science came to the rescue.</p><p>“Give me whereon to stand”, said Archimedes, “and I will move the earth.” “Give me a notebook to run Pandas in”, I yelled back, “and I will conquer the Amazon beast!”</p><p>Let us turn our hero quest into a play, covering those sharp stabbing numbers with a blanket of charts in soft color palettes, thus earning a small chance of, if not winning, then at least surviving and keeping our sanity in check.</p><p>First, we need to pick our weapon. Nothing cuts through the haze of data better than the sword of <a href="https://www.datascience-pm.com/crisp-dm-2/">CRISP-DM</a>, an industry-proven framework that would help structure our analytics efforts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9RubVMatfQS80D1_a6pErQ.jpeg" /><figcaption>Edited photo by <a href="https://unsplash.com/@mavrick?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ricardo Cruz</a> on <a href="https://unsplash.com/s/photos/samurai-sword?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4><strong>Business understanding</strong></h4><p>In my case, this means I need to define a set of questions:</p><ul><li>How much did I spend by year? What year did I go on a shopping spree and spend the most? Note that we’re not asking <em>why</em> as that would require a therapy session or two (or a dozen).</li><li>What was purchased during that binge-shopping year?</li><li>Which categories do most of my expenses fall into?</li><li>If we pick top 6 categories, do I tend to spend the same amount every year?</li><li>The most dreaded question, what is the maximum amount I’ve <em>ever</em> spent on the most common expense categories?</li><li>Lastly, what is my predicted purchase total for 2021?</li></ul><h4><strong>Data understanding</strong></h4><p>Here we are going to explore the available data.</p><p><strong>Step 1. Gather data</strong>. Since I was dealing with Amazon, I went straight to Your Account &gt; Your Orders &gt; <a href="https://www.amazon.com/gp/b2b/reports/?ie=UTF8&amp;download-report.x=1&amp;isInternal=0&amp;js=1&amp;reportId=A1YR1JHHGE3WTK">Order History Reports</a>, and downloaded a .csv file with my order history. (Thankfully, I didn’t have to open it just yet.)</p><p><strong>Step 2. Get your Jupyter Notebook going, and load some libraries.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1ccb22f2af0db9c405f3775ed77c62e/href">https://medium.com/media/f1ccb22f2af0db9c405f3775ed77c62e/href</a></iframe><p><strong>Step 3. Familiarize yourself with data and outline data quality and tidiness issues, if any</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0de628d15d781730d770c7e95f0cbcd/href">https://medium.com/media/a0de628d15d781730d770c7e95f0cbcd/href</a></iframe><p>I didn’t see any structure errors so my data was in good shape as far as <strong>tidiness</strong> is concerned. I did end up performing some structural modifications, but that was at the Modeling stage. (By the way, here is a great article if you’d like to learn more on <a href="https://cran.r-project.org/web/packages/tidyr/vignettes/tidy-data.html">what constitutes a tidy dataset</a>.)</p><p>As for <strong>quality</strong>, here are a few things I needed to take care of:</p><ul><li>Drop extra columns I wouldn’t need</li><li>Change ‘Order Date’ format to DateTime</li><li>Extract ‘Year of Purchase’ into a separate column + remove the 2021 values to make a clean break</li><li>Format ‘Item Total’ by removing the $ sign and converting it to Numeric</li><li>Drop or impute missing values</li><li>Give the data more appropriate labels</li></ul><p>Thus, we enter the next stage.</p><h3>Data Preparation</h3><p>Following the task list outlined above:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2730598d33dd55aeb444ca30d1e92e73/href">https://medium.com/media/2730598d33dd55aeb444ca30d1e92e73/href</a></iframe><h3>Data Modeling &amp; Result Evaluation</h3><p>Now on to the fun part, where we locate answers to our questions by performing modeling and statistical analysis. Before we dive in, I wanted to share one of the <a href="https://s3.amazonaws.com/assets.datacamp.com/production/course_15192/slides/chapter4.pdf">seaborn cheat sheets</a> I came across, which is ironically hosted by Amazon AWS via DataCamp. (It was almost like Amazon was nudging me forward.)</p><p>So, my first question comes in 3 parts:</p><p><strong>How much did I spend by year and what year made the largest dent?</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f0b145c3256183f62006f96bb62f71c/href">https://medium.com/media/1f0b145c3256183f62006f96bb62f71c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*plnfVhVJN5Q5j13ef_XdUw.jpeg" /><figcaption>Image by Author</figcaption></figure><p>Judging by the above, it <em>seems</em> like 2014 and 2017-2018 left their imprint (or rather, a gaping hole) on my wallet, but we’ll need a clearer view to confirm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef52a9b90c63d6df0698a9d814034c9e/href">https://medium.com/media/ef52a9b90c63d6df0698a9d814034c9e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*uf3UAr9zFNjo38F3Qid31w.jpeg" /><figcaption>Image by Author</figcaption></figure><p>Yep, there it is, 2018 at almost 10K… In my defense, my husband and I frequently buy home appliances on Amazon — but can I actually claim it’s electronics and smart technologies that got the best of me? Let’s see…</p><p><strong>What comprised the majority of the 2018 purchases?</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af79d868148bf9fd5d053f016d3a9ace/href">https://medium.com/media/af79d868148bf9fd5d053f016d3a9ace/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*eGgHJ3skvyggycbSNxMqdA.jpeg" /><figcaption>Image by Author</figcaption></figure><p>OK, so microphone, headphones, air purifier — that’s all great. But chewing gum, seriously? Wonder what rank it would get if we look at the whole eight-year period. (Although, come think of it, do I <em>really</em> want to know?)</p><p><strong>Which categories most of my expenses fall into?</strong></p><p>First, by quantity:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8feca0b0c3a7fd7bf9513056fe04fc4/href">https://medium.com/media/b8feca0b0c3a7fd7bf9513056fe04fc4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*4dICuUfkZubjSK2KOW_wvw.jpeg" /><figcaption>Image by Author</figcaption></figure><p>Then by amount:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bc36072b326cda7067683fe295ef6f3/href">https://medium.com/media/9bc36072b326cda7067683fe295ef6f3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*numYzY1pHGHJSxZ2BDdVqg.jpeg" /><figcaption>Image by Author</figcaption></figure><p>More pet pads and pet food (owning dachshunds comes at a price…), shoes and beauty — fine, I can deal with all that. Books, thankfully, made it to the first QTY chart — you’ll see them at the very (rock) bottom. Almost $2K on protein bars, though…… Thank goodness for Seaborn’s pretty colors softening the blow.</p><p>Now the question is<strong> if we limit ourselves to the top 6 categories and see the spread over the whole 8-year period, will my expenses vary from year to year?</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22a17c7229767baaeb1547f8ed2adba4/href">https://medium.com/media/22a17c7229767baaeb1547f8ed2adba4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*x25Q7wzx4cEBMRc092bGWg.jpeg" /><figcaption>Image by Author</figcaption></figure><p>And the answer is yes, they do vary. Not sure whether this is good or bad news due to apparently unpredictable buyer behavior… I’ll go with the positive approach since I no longer seem to spend a fortune on those damned protein bars. Plus, beauty and shoe expenses appear to be phasing out these days — courtesy of COVID-19. Guess, in the end, I’m stuck with pet pads. Bad news after all.</p><p>Don’t think it can get worse than this, so I’m ready to answer the most dreaded question of</p><p><strong>What is the maximum amount I ever spent on common categories?</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b989ea8863947120d9c369ccf2ae52e/href">https://medium.com/media/3b989ea8863947120d9c369ccf2ae52e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*G5nyjMYCn3mR341-ozJ1-Q.jpeg" /><figcaption>Image by Author</figcaption></figure><p>If you are yet to become familiar with box plots, note that dots represent <em>outliers</em> (glad to hear I don’t spend $200 on pet food and $300+ on sporting goods every<em> </em>time). The vertical line inside the box shows you the <em>median</em>, with the box itself representing the <em>interquartile range</em> (which is basically the difference between the upper half and the lower half medians). And finally, the outside lines aka <em>whiskers</em> indicate the minimum and the maximum values accordingly.</p><p>Well, I’d say it’s not that bad, especially considering that none of the items in these costly categories made it past $450. Another thing to ask could be, what my most expensive purchases are <em>in general</em>, regardless of whether their category made it into the top 15, but that would be a question for another report…</p><h3>Deployment</h3><p>Speaking of reports, I would say that the final stage of our CRISP-DM framework is complete as well. For me, this meant developing and documenting a plan for deploying the model, generating a report, and communicating findings to stakeholders. Done, done, and done.</p><p>Still, an attentive reader might wonder: what happened to the last question of purchase prediction for 2021? Well, one might think it was so terrifying I decided against sharing it with the public. But in reality, it was my model that was absolutely horrible due to it lacking any relevant features, which means I cannot in all good conscience trust the label it predicted.</p><p>I’m going to share the code and the result with you, regardless, as I only built it for practice. And here’s another incentive — both models predicted <em>much</em> lower spending than in the previous years! Does that mean there will be another quarantine lockdown for 10 months with 0 reasons to acquire things? I guess that depends on your interpretation…</p><p><strong>P.S. Predictive Modeling Practice #1 with sklearn</strong></p><p>When I started working on this, I had to deal with categorical data (item names, amazon categories, etc.), which I subsequently converted into dummy variables. But then I realized, I needed the total amount spent by year (not by item), so I went ahead and grouped the data, throwing in some sample salary values:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29baa46e0e2e37f09099db43d123a4b0/href">https://medium.com/media/29baa46e0e2e37f09099db43d123a4b0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*P8d62sonnYVveyLzn1s3CQ.jpeg" /><figcaption>Image by Author</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df82db66644cdc9808f0a801c658c906/href">https://medium.com/media/df82db66644cdc9808f0a801c658c906/href</a></iframe><p>Well, you can see that we have our model that fits pretty well, considering the ridiculously small amount of data I gave it. It predicted that my 2021 annual Amazon spending will reach $5,777.</p><p><strong>P.P.S. Predictive Modeling Practice #2 with statsmodels</strong></p><p>Here I had to introduce an intercept (and would’ve needed to drop one of the dummy variables, if I were to use them). The code is simple, and it fits better than the first one, so definitely a winner (although it was a bit less optimistic as far as my spendings go, predicting $5,830 worth of annual merchandise).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ee6bc01e6d5d49038398ae8658c3ed4/href">https://medium.com/media/0ee6bc01e6d5d49038398ae8658c3ed4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*u9qZdsqKlzSVl-XX1ykFDg.jpeg" /><figcaption>Image by Author</figcaption></figure><p>I say that’s it for the fun weekend project. Although, it never really ends, does it… Next time, instead of cutting through the haze of data, I say we dissipate it completely, using regression models that have a <em>real</em> weight and value.</p><p>Until we meet again!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cebf428178f2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/the-beast-of-your-amazon-spendings-and-the-best-way-to-face-it-cebf428178f2">The beast of your Amazon spendings, and the best way to face it.</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>