<?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 Anand on Medium]]></title>
        <description><![CDATA[Stories by Anand on Medium]]></description>
        <link>https://medium.com/@anand0427?source=rss-265cef965c48------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rQUFpGaF_1pl4qjLTy1IjA.jpeg</url>
            <title>Stories by Anand on Medium</title>
            <link>https://medium.com/@anand0427?source=rss-265cef965c48------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 04:57:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anand0427/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[How should you choose Airbnb?]]></title>
            <link>https://medium.com/@anand0427/how-should-you-choose-airbnb-346a869870f2?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/346a869870f2</guid>
            <category><![CDATA[rental]]></category>
            <category><![CDATA[boston]]></category>
            <category><![CDATA[vacation]]></category>
            <category><![CDATA[airbnb]]></category>
            <category><![CDATA[analysis]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Fri, 24 Jun 2022 08:49:17 GMT</pubDate>
            <atom:updated>2022-06-24T21:50:16.245Z</atom:updated>
            <content:encoded><![CDATA[<p>Data analysis and text mining to find and answer some interesting questions that we will find along the way in the Airbnb data set for Boston.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S3tXEtg-iQM5ESOF" /><figcaption>Photo by <a href="https://unsplash.com/@andreaedavis?utm_source=medium&amp;utm_medium=referral">Andrea Davis</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ul><li><a href="#ba0a">Introduction</a></li><li>Analysis</li><li>Improvements</li><li>Generalization</li><li>Conclusion</li></ul><h4>Introduction</h4><p>In this blog, we will take a look at the analysis of the Airbnb dataset for Boston and take a look at what story the dataset will tell us. We will do some exploratory data analysis, and some data cleaning, and answer some questions involving</p><ol><li>Top and bottom listings,</li><li>Reviewers and their rankings,</li><li>Reviewer’s general mood to check review reliability,</li><li>The mood around listings, customer satisfaction, and positivity</li></ol><p>I will maintain this blog to make sure that it contains a low amount of code but to the musings of my fellow programmers or people who are interested in this project, I will add a few pieces of code. If you are interested in using the project as a starter code for your own, you can clone it from my GitHub, if you find anything interesting send me your findings, I will be interested in checking it out.</p><h4>Analysis</h4><p>Alright, so now that we have preliminary data, we will try to find and answer some questions and see what story our data will tell us.</p><p>When you are searching for an Airbnb for your vacation you would first look at the price and check what you would get for the price. This is a correlation. Let’s create a correlation between price and different features of the list.</p><ul><li><strong><em>How do different features affect the price of a listing?</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*ORbGTYkBxoYSZig91Q3z2w.png" /><figcaption>Correlation among different features of listings</figcaption></figure><p>The stronger the correlation the darker the cell of the image above. Either negative or positive. Looking at the image above not surprisingly the number of people it can accommodate, beds, and bedrooms affect the price quite significantly. But surprising that the number of reviews, minimum nights, and a number of listings of that host do not affect the price in a significant way.</p><p>So now keeping that in mind, what are the best or the worst listings of Boston Airbnb?</p><ul><li><strong><em>Best and worst listings?</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*3WKDA8w0sjlSD1emO1Y6zg.png" /><figcaption>Bar chart for best and worst listings with x-axis as listing ID and y-axis as POS sentiment</figcaption></figure><p>So post our analysis the best listings on Boston Airbnb have a customer satisfaction rate of 0.5 and the worst satisfaction rate of 0.04 (don’t be deceived by the strength of the bar always look at the scale). We know some listings would be bad but 0.04? That is very bad. But how do we get customer satisfaction and how reliable is it?</p><p>Well, that question is fairly simple, we have “reviews” data for each of these listings and we know that we can do some simple text mining and make sure it is in a decent shape. We then use these reviews to perform sentiment analysis on them to get a positive value, negative value, and neutral value. So what you see above in the image is the positive value or pos sentiment of the reviews that the listings have.</p><p>We still have to question the reviewers, some people are just very negative no matter what, aren’t they? Let’s check our top reviewers and how positive their opinions are.</p><ul><li><strong><em>How do our top reviewers usually feel about their stay?</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*eX54dnvQJTEz0hyzFCnPCg.png" /><figcaption>Sentiment and POS values of top reviewers with NB sentiment and textblob sentiment</figcaption></figure><p>We sort our data to get the top reviewers by the number of reviews they have individually given and perform sentiment analysis on their reviews and get the positivity rate and plot them. The top most plot consists of 30 top reviewers vs the number of individual reviews. The second and third plots are the corresponding sentiment positive rates based on two algorithms — Naive Bayes and pattern based sentiment.</p><ul><li><strong><em>Alright then, so which months have the most bookings?</em></strong></li></ul><p>We do not exactly have this data so we improvise a bit. We take in the reviews written by reviewers and calculate the busiest bookings for each month. We should take this information with a pinch of salt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*K33CjDit6fm_iJ9z8Jf4mA.png" /><figcaption>Busiest months for Boston AirBnB</figcaption></figure><h4>Improvements</h4><p>There are a couple of improvements that I would like to make eventually to this.</p><ul><li>I started working on this with the thought of generalizing the functions to suit datasets of different cities from AirBnB. This is something I will still work on, so check out my GitHub for new commits but for now, this would be just for Boston.</li><li>I am working on clustering and geo plotting the different types of listings based on a few features.</li><li>We can of course extract images of these listings and correlate listing images to bookings and how images help.</li><li>More questions like host/super host preferences, seasonality, and trend of prices with local events.</li></ul><h4>Generalization</h4><p>Of course, this existing code may create errors for other datasets even if we would like to generalize for every data we will have to check every column for null values or garbage data, which will take time. I may do it sometime later, but for now, use it as a starter code for your own analysis.</p><p><em>I will add more methods in the future to help this little project.</em></p><h4>Conclusion</h4><p>Thank you for reading my simple analysis of the Boston AirBnB dataset! If you like the blog do let me know and I will consider adding a part 2 for this blog with a few of the above features. Go over to my <a href="https://github.com/anand0427/boston_airbnb_analysis"><strong><em>GitHub</em></strong></a> and check out the code for interactive plots used above and new feature commits.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=346a869870f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Train a Convolutional Neural Network to classify dog breed]]></title>
            <link>https://medium.com/@anand0427/train-a-convolutional-neural-network-to-classify-dog-breed-196bf882ba73?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/196bf882ba73</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[dogs]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Wed, 20 Apr 2022 05:06:35 GMT</pubDate>
            <atom:updated>2022-06-27T12:28:33.791Z</atom:updated>
            <content:encoded><![CDATA[<p>Read how to train different types of CNN for classifying 133 different breeds of dogs (fun little additional feature towards the end).</p><h4>Contents</h4><ol><li>Importing the dataset</li><li>Visualize and Clean the dataset</li><li>Dog Recognition</li><li>Create a CNN model from scratch</li><li>Create a CNN VGG16 model using Transfer Learning</li><li>Metrics</li><li>Classification using the above CNN models</li><li>Improvements</li><li>Conclusion</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qED9YfMGVqBQEe9d" /><figcaption>Photo by <a href="https://unsplash.com/@rstone_design?utm_source=medium&amp;utm_medium=referral">Ryan Stone</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>CNN or Convolutional Neural Network is a deep learning network of neurons that work exceptionally well on images. We will not dive into what CNN is or how it works but we will look at the application of CNN as a fun exercise for classifying dogs. Of course, as is the case for any machine learning or deep learning model we need huge data to solve the model parameter problem, that is find the best possible weights and bias for these models.</p><h4>Importing the dataset</h4><p>We will start with where all good machine learning projects begin, importing the dataset. We get the data and transform it into a numpy type array. We do the same with our targets, except the targets also need to be one hot encoded to convert them to usable input for our model.</p><pre>def load_dataset(path):<br>    data = load_files(path)<br>    dog_files = np.array(data[&#39;filenames&#39;])<br>    dog_targets = np_utils.to_categorical(np.array(data[&#39;target&#39;]), 133)<br>    return dog_files, dog_targets</pre><pre># load train, test, and validation datasets<br>train_files, train_targets = load_dataset(&#39;../../../data/dog_images/train&#39;)<br>valid_files, valid_targets = load_dataset(&#39;../../../data/dog_images/valid&#39;)<br>test_files, test_targets = load_dataset(&#39;../../../data/dog_images/test&#39;)</pre><pre>There are 133 total dog categories.<br>There are 8351 total dog images.<br>There are 6680 training dog images.<br>There are 835 validation dog images.<br>There are 836 test dog images</pre><h4>Visualize and Clean the dataset</h4><p><strong>Let’s visualize one of our images</strong></p><pre>import matplotlib.pyplot as plt<br>import matplotlib.image as mpimg<br>plt.imshow(mpimg.imread(train_files[10]))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*HI6DBPiwTj1qlJab2Sc2eg.png" /></figure><p>We will start by preprocessing the dog image to convert it to a tensor. We get a three-dimensional image and we will return a four-dimensional image by using the expand_dims method in numpy along the axis 0. We will also create a function to convert all our data into a list of tensors. The input would contain many images of various sizes as we see above with 400*390. To feed the images into our model we would like these tensors to be of the same shape. We pick 224*224 to standardize all our images.</p><pre>def path_to_tensor(img_path):<br>    # loads RGB image as PIL.Image.Image type<br>    img = image.load_img(img_path, target_size=(224, 224))<br>    # convert PIL.Image.Image type to 3D tensor with shape (224, 224, 3)<br>    x = image.img_to_array(img)<br>    # convert 3D tensor to 4D tensor with shape (1, 224, 224, 3) and return 4D tensor<br>    return np.expand_dims(x, axis=0)</pre><pre>def paths_to_tensor(img_paths):<br>    list_of_tensors = [path_to_tensor(img_path) for img_path in tqdm(img_paths)]<br>    return np.vstack(list_of_tensors)</pre><p><strong>Let’s check for imbalance and plot</strong></p><p>As we can see while there is an imbalance in different dog breed classes, we can still proceed with our preliminary models and see how the CNN models behave with this data.</p><pre>unique, counts = np.unique(np.argmax(train_targets,axis = 1), return_counts=True)<br>print(dict(zip(unique, counts)))</pre><pre>{0: 64, 1: 58, 2: 52, 3: 63, 4: 77, 5: 64, 6: 50, 7: 66, 8: 34, 9: 50, 10: 66, 11: 66, 12: 46, 13: 69, 14: 73, 15: 59, 16: 62, 17: 50, 18: 48, 19: 62, 20: 64, 21: 47, 22: 65, 23: 62, 24: 37, 25: 41, 26: 64, 27: 35, 28: 74, 29: 52, 30: 56, 31: 65, 32: 45, 33: 64, 34: 53, 35: 65, 36: 50, 37: 57, 38: 69, 39: 53, 40: 69, 41: 63, 42: 50, 43: 64, 44: 53, 45: 67, 46: 54, 47: 54, 48: 50, 49: 50, 50: 62, 51: 49, 52: 47, 53: 57, 54: 50, 55: 65, 56: 71, 57: 50, 58: 47, 59: 60, 60: 61, 61: 53, 62: 53, 63: 39, 64: 42, 65: 33, 66: 34, 67: 63, 68: 51, 69: 47, 70: 62, 71: 48, 72: 42, 73: 41, 74: 44, 75: 64, 76: 43, 77: 40, 78: 59, 79: 46, 80: 56, 81: 61, 82: 46, 83: 50, 84: 37, 85: 53, 86: 66, 87: 51, 88: 53, 89: 58, 90: 57, 91: 44, 92: 35, 93: 44, 94: 49, 95: 43, 96: 50, 97: 46, 98: 42, 99: 34, 100: 48, 101: 29, 102: 58, 103: 42, 104: 31, 105: 50, 106: 46, 107: 26, 108: 45, 109: 33, 110: 44, 111: 54, 112: 39, 113: 35, 114: 63, 115: 30, 116: 48, 117: 53, 118: 31, 119: 39, 120: 28, 121: 32, 122: 44, 123: 50, 124: 34, 125: 30, 126: 41, 127: 30, 128: 48, 129: 44, 130: 30, 131: 26, 132: 30}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*8QYz40s_FlcaEIpoqJPoEw.png" /><figcaption>Imbalance in the dog breeds data</figcaption></figure><h4>Dog Recognition</h4><p>Since we are interested in classifying dogs, we might as well detect if there are dogs at all in the picture before we classify which breed the dog is. To do this we can either build a model from scratch or we can use a model like ResNet50 to classify True or False which indicates the presence of a dog. We will need tensors to process our data into a tensor, so we will use the above-defined path_to_tensor function to do this.</p><pre>def ResNet50_predict_labels(img_path):<br>    # returns prediction vector for image located at img_path<br>    img = preprocess_input(path_to_tensor(img_path))<br>    return np.argmax(ResNet50_model.predict(img))</pre><p>We can then use the above function to predict the presence of a dog. If the prediction label is between 151 and 268(both inclusive), the classes can be found in imagenet class list, we know that the image has a dog.</p><pre>def dog_detector(img_path):<br>    prediction = ResNet50_predict_labels(img_path)<br>    return ((prediction &lt;= 268) &amp; (prediction &gt;= 151))</pre><h4>Create a CNN model from scratch</h4><p>We will create a simple CNN with 3 layers of Conv2D along with max-pooling and the last layer being a dense layer for final classification. Let’s first define our network.</p><pre>model = Sequential()<br>model.add(Conv2D(filters=16, input_shape=(224, 224, 3), kernel_size=2))<br>model.add(MaxPooling2D(2))<br>model.add(Conv2D(32, 2, activation=&quot;relu&quot;))<br>model.add(MaxPooling2D(2))<br>model.add(GlobalAveragePooling2D())<br>model.add(Dense(133, activation=&quot;softmax&quot;))</pre><pre>model.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*260kr78UhLkxhQ9MIX11xQ.png" /><figcaption>Preliminary Model parameters</figcaption></figure><p>We will then compile our model, set the checkpoint, and train the model on the above tensors. The number of epochs can really depend on you and on experimentation here epochs variable is set to 30</p><pre>model.compile(optimizer=’rmsprop’, loss=’categorical_crossentropy’, metrics=[‘accuracy’])</pre><pre>checkpointer = ModelCheckpoint(filepath=&#39;saved_models/weights.best.from_scratch.hdf5&#39;, <br>                               verbose=1, save_best_only=True)</pre><pre>model.fit(train_tensors, train_targets, <br>          validation_data=(valid_tensors, valid_targets),<br>          epochs=epochs, batch_size=20, callbacks=[checkpointer], verbose=1)</pre><p>Let’s load the model from the checkpoint and test it on the test data.</p><p>To test the accuracy we will get the predictions and divide the number of positives by the length of the data points in our test_data. Multiple with 100 and we have a percentage of the test accuracy on the model. Since this is a model from scratch we would not get great accuracy and is around 5 percent.</p><pre>model.load_weights(&#39;saved_models/weights.best.from_scratch.hdf5&#39;)</pre><pre>dog_breed_predictions = [np.argmax(model.predict(np.expand_dims(tensor, axis=0))) for tensor in test_tensors]</pre><pre><br>test_accuracy = 100*np.sum(np.array(dog_breed_predictions)==np.argmax(test_targets, axis=1))/len(dog_breed_predictions)<br>print(&#39;Test accuracy: %.4f%%&#39; % test_accuracy)</pre><p>We will follow similar steps for other models which are pre-trained like VGG16, ResNet50, and InceptionV3.</p><h4>Create a CNN VGG16 model using Transfer Learning</h4><p>To use and train the VGG16 model we will have to first import the model weights and bias. we will also import the bottleneck features data for the training, validating, and testing. The rest of the process is pretty similar to what we have seen above and is going to follow a similar pattern. This is called transfer learning, we use a pre-trained VGG16 model (we do this using the features extracted from the training set using the VGG16 model), we call these bottleneck features, and we then define a few layers that we build to suit our problem.</p><pre>bottleneck_features = np.load(&#39;bottleneck_features/DogVGG16Data.npz&#39;)<br>train_VGG16 = bottleneck_features[&#39;train&#39;]<br>valid_VGG16 = bottleneck_features[&#39;valid&#39;]<br>test_VGG16 = bottleneck_features[&#39;test&#39;]</pre><pre>VGG16_model = Sequential()<br>VGG16_model.add(Conv2D(filters=16, kernel_size=2, input_shape=train_VGG16.shape[1:]))<br>VGG16_model.add(Dropout(0.4))<br>VGG16_model.add(GlobalAveragePooling2D(input_shape=train_VGG16.shape[1:]))<br>VGG16_model.add(Dense(133, activation=&#39;softmax&#39;))</pre><pre>VGG16_model.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*ZmJyGo2Zkt4-b73v6zsmnA.png" /><figcaption>VGG 16 parameters</figcaption></figure><p>The rest of the steps are exactly as we define them above, we compile the model, save checkpoints, load weights, and calculate accuracy.</p><p>ResNet50 and InceptionV3 follow the same exact method as the VGG16 model, but we will need different bottleneck features which were extracted from their respective models. Click on the GitHub link below to see the code and usage of these models along with their architectures.</p><h4>Metrics</h4><p>As we saw above the imbalance in classes is not too high for us to get unusually high accuracy score. Which makes it okay(not perfect) to just use accuracy for this particular problem. We could use other metrics like F1 score, Recall, Precision in addition to accuracy to get a better understanding of the performance of the model.</p><p>The accuracies of all the models are — VGG16 at 71%, ResNet50 at 80.26%, and InceptionV3 at 80.02%.</p><h4>Classification using the above CNN models</h4><p>Finally, once we are done training our models, we will load the model weights into the environment. I am using a small function called dog_breeds to take in an image_path as an input.</p><pre>def dog_breeds(image_path):<br>    from keras.models import load_model<br>    VGG19_model = load_model(&#39;saved_models/weights.best.VGG16.hdf5&#39;)<br>    Resnet50_model = load_model(&#39;saved_models/weights.best.Resnet50.hdf5&#39;)<br>    InceptionV3_model = load_model(&#39;saved_models/weights.best.InceptionV3.hdf5&#39;)<br>    image_tensor = path_to_tensor(image_path) </pre><p>We can use these model objects to predict on the image_path of a dog. The below snippet is written in the dog_breeds function. Compile the results into a list and return them for our convenience.</p><pre>results = [np.argmax(VGG19_model.predict(extract_VGG19(image_tensor))),<br>     np.argmax(Resnet50_model.predict(extract_Resnet50(image_tensor))),<br>     np.argmax(InceptionV3_model.predict(extract_InceptionV3(image_tensor))),<br>     ]<br>    <br>    return [dog_names[i] for i in results]</pre><h4>Improvements</h4><p>A fun exercise within this project is that we can detect if an image has a human face and pass that image to the dog_breeds function to find which dog breed the human face is classified into. Similar to the dog_detector function, but in this case we use the Haar Cascades classifier with the human images to detect a human face.</p><pre>def human_or_dog(image_path=None):<br>    if image_path==None:<br>        return(&quot;Error, human_or_dog: File path cannot be None&quot;)<br>    else:<br>        if dog_detector(image_path):<br>            return(dog_breeds(image_path))<br>        elif face_detector(image_path):<br>            return(dog_breeds(image_path))<br>        else:<br>            return(&quot;Error, human_or_dog: Image does not have a face&quot;)</pre><p>An example output is, that the below image is classified as a Pekingese.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*00E3klqVJtQqUSmIDYctVQ.png" /></figure><ul><li>There are more improvements that can be done in this project. Using image augmentation is one of them and would probably give better results than the models above.</li><li>Hyperparameter tuning to tune the number of epochs, batches, and layers will also result in better accuracy than the above models.</li></ul><h4>Conclusion</h4><p>The notebook for this blog is available on my <a href="https://github.com/anand0427/Deep-Learning-Dog-Breed-Classification-">GitHub</a>. Feel free to reach out for any comments or suggestions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=196bf882ba73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Neural Style Transfer (AI in art) with Keras and TF2]]></title>
            <link>https://medium.datadriveninvestor.com/neural-style-transfer-ai-in-art-with-keras-and-tf2-34392aeaeb39?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/34392aeaeb39</guid>
            <category><![CDATA[dogs]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[art]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Wed, 01 Apr 2020 22:48:40 GMT</pubDate>
            <atom:updated>2020-04-15T03:31:13.390Z</atom:updated>
            <content:encoded><![CDATA[<p>AI in art was inevitable considering the progress it has made in different fields in the last few years. Everything that we have achieved with AI always leaves me awestruck but getting into how each of these components work to make an idea like AI in art is even more of an amazing achievement than the idea itself.</p><p>In this article, I want to highlight in the easiest way possible how to achieve Style Transfer a concept that uses AI in the art to achieve some astonishingly beautiful results.</p><h4>Contents</h4><ol><li>What is Style Transfer?</li><li>What will we use?</li><li>Where do we start?</li><li>Deep Learning model</li><li>Loss Functions</li><li>Calculating gradients</li><li>Optimization</li><li>Reverse the preprocessing on the resulting image</li><li>Sources and credits</li></ol><h4>What is Style Transfer?</h4><p>Style transfer is a concept which basically adopts the visual style of one image on another image. Let’s take a classic example of a picture of <a href="https://en.wikipedia.org/wiki/Katsushika_Hokusai">Katsushika Hokusai</a>’s great wave image as a reference style image and a dog image as the content image combining together should result in the dog image shown with the style of the great wave image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vyVUw3k2ciGTX5trZcc47g.jpeg" /><figcaption>Content Image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AEfXJgEnLgxnB8yVOQA0_w.jpeg" /><figcaption>Style Image</figcaption></figure><p>Now without further ado, I will show you how to create this program and I am sure you will find it not difficult considering the enigma displayed by a lot of people toward AI or deep learning in particular.</p><p><a href="https://www.datadriveninvestor.com/2020/03/04/on-artificial-intelligence-and-surveillance-capitalism/">On Artificial Intelligence and Surveillance Capitalism | Data Driven Investor</a></p><h4>What will we use?</h4><p>For this application, we will use Keras for backend and deep learning model, PIL for image processing, scipy for an optimization algorithm and time for seeing how long our training process takes for each iteration.</p><p><strong>But I don’t know Keras. What do I do?</strong></p><p>Even if you are not familiar with Keras you should be able to understand this because of the ease of the syntax and I will try my best to explain the code in as simple words as possible.</p><h4>Where do we start?</h4><p>We will use a Jupyter notebook so let’s import some basic necessities and also the images that we want to work with into the environment.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a8d864ef113edf14b25dd1b3d9ce56b/href">https://medium.com/media/8a8d864ef113edf14b25dd1b3d9ce56b/href</a></iframe><p>We convert these images to numpy arrays. We will add an extra dimension to these numpy arrays so that we create a tensor with the content, style and the combination data for using it with the deep learning model.</p><p>Because we will be using the pre-trained VGG16 model we will need to preprocess our input images a little bit. We will subtract every RGB channel with the pre-calculated mean values with the image net dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee7669fd0613f4b6900c7f62c54066c2/href">https://medium.com/media/ee7669fd0613f4b6900c7f62c54066c2/href</a></iframe><p>Now reverse RGB to BGR to match the architecture VGG16 which was written in Caffe.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6754b76856d0d7812535e876af393a32/href">https://medium.com/media/6754b76856d0d7812535e876af393a32/href</a></iframe><p>We now convert each of our variables into tensors. We also create our combination variable to hold our combination image when created. As said before we concatenate all these tensors to create one input tensor to the deep learning model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd87947d48b372efc751dd4d4ef3ac61/href">https://medium.com/media/dd87947d48b372efc751dd4d4ef3ac61/href</a></iframe><h4>Deep Learning model</h4><p>Alright so after all our input preparation we finally come to the part where we import our deep learning model VGG16 and play with some layers.</p><p>The VGG16 model was created for a classification problem but we are not doing that so we don&#39;t need some layers called the fully connected layers which are responsible for this classification. We can exclude them by using the include_top parameter. Creating a dictionary as you see in the last line of the code snippet to access each of these layers by their layer name.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fe9e881bd1d9169b4d763038e362119/href">https://medium.com/media/5fe9e881bd1d9169b4d763038e362119/href</a></iframe><p>The plan with the VGG16 model is to make the model “understand” the features of images. We use this to our advantage to find the loss between the content image and the combination image and also between style image and combination image and calculate gradients to minimize the loss.</p><p>So let’s go ahead and code our loss functions.</p><h4>Loss Functions</h4><p>Considering what we have seen before about VGG16 models being able to encode the perceptual features of the images. We will use some of its layers to achieve this. You can read about the model layers in <a href="https://arxiv.org/abs/1508.06576">original paper from Gatys et al.</a>, But we will implement the layers from <a href="https://arxiv.org/abs/1603.08155">Johnson et al. (2016)</a></p><p><strong>Content Loss</strong></p><p>Loss between content image and the combination image is just the MSE between the two variables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9c40cbe23eaa3a7cc86b16bf1712260/href">https://medium.com/media/d9c40cbe23eaa3a7cc86b16bf1712260/href</a></iframe><p><strong>Style Loss</strong></p><p>Style loss is not exactly the way we calculate content loss. We want to capture the style of both these images. The way we do this is by calculating the gram matrix which is the dot product of the style image variable with its transpose.</p><p>This transformation brings the focus on the style than the content of the image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1a6732ea52c4b9e7849ea9508fb7195/href">https://medium.com/media/f1a6732ea52c4b9e7849ea9508fb7195/href</a></iframe><p><strong>Total Variation Loss</strong></p><p>Now we calculate the <a href="https://arxiv.org/abs/1412.0035">total variation loss</a> to increase or decrease the noise in the loss term which we will see how it does.</p><p>But before we do that we would want to give these three losses some weight so we can vary the influence of each of these losses on our total loss term.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d4dc2c01685a883527eab679d3aaa6f/href">https://medium.com/media/0d4dc2c01685a883527eab679d3aaa6f/href</a></iframe><p>Let’s create a loss variable and add all these losses up.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72a87b026ef7b022390a2ece7301bb59/href">https://medium.com/media/72a87b026ef7b022390a2ece7301bb59/href</a></iframe><h4>Calculating gradients</h4><p>We have everything we need in place. All we now need to do is call an optimizer to iterate and optimize the combination image. Let’s create our gradients for the loss with respect to the combination variable. In this particular code I am using TF1 because I like the gradients function but in TF2 <a href="https://github.com/tensorflow/tensorflow/issues/34235">gradients eager execution is not supported</a>(not sure if it is a bug or a feature) so I encourage you to try out the <a href="https://www.tensorflow.org/api_docs/python/tf/GradientTape">GradientTape</a> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02efce9ea1e0ed5a54a4d24e999a2658/href">https://medium.com/media/02efce9ea1e0ed5a54a4d24e999a2658/href</a></iframe><p>For a better understanding of backend.function take a look at this <a href="https://stackoverflow.com/questions/48142181/whats-the-purpose-of-keras-backend-function">stack overflow post</a>.</p><p>We will evaluate our loss and gradients in the function to make sure we have the right values.</p><p>To make our lives easier with the optimizer we will create a class and return the loss value and grad value which the optimizer will try to modify to bring out the most optimum result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b55cfc35ab139ac62228feaad8469d94/href">https://medium.com/media/b55cfc35ab139ac62228feaad8469d94/href</a></iframe><h4>Optimization</h4><p>So let’s code our optimization part. We will use the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_l_bfgs_b.html">fmin_l_bfgs_b</a> algorithm from scipy. We create a variable with random data and store the created image in this variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c40af2eee6a6008fa5a79dc091a00f78/href">https://medium.com/media/c40af2eee6a6008fa5a79dc091a00f78/href</a></iframe><h4>Reverse the preprocessing on the resulting image</h4><p>We now reverse what we have done before. Convert BGR to RGB values and we add the mean values to the image. We clip our values to be between 0 and 255 pixel values.</p><p>And now we see our resulting image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cb91fbb32d10ff2603f2d52a8bf4689/href">https://medium.com/media/1cb91fbb32d10ff2603f2d52a8bf4689/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*gOA0h-XeYCdGD9oUGoIOeQ.png" /><figcaption>Resultant image</figcaption></figure><h4>Sources and credits</h4><ol><li><a href="https://harishnarayanan.org/writing/artistic-style-transfer/">https://harishnarayanan.org/writing/artistic-style-transfer/</a> one of the best blogs on style transfer. Thanks to Harish Narayan for such a wonderful explanation. It helped me with practicing style transfer.</li><li><a href="https://keras.io/examples/neural_style_transfer/">https://keras.io/examples/neural_style_transfer/</a> Keras documentation and Keras code for NST is just amazing.</li></ol><p><a href="https://github.com/anand0427/style-transfer-with-keras"><strong>Github repo for this notebook</strong></a><strong> or take a look at the notebook from </strong><a href="https://anand0427.github.io/style-transfer-with-keras/"><strong>this page</strong></a><strong>.</strong></p><p><strong>I would like to know your thoughts and views on my blog. Constructive criticism is much appreciated. If you like this blog and you can buy me a coffee by clicking the button below.</strong></p><figure><a href="https://www.buymeacoffee.com/anand0427"><img alt="" src="https://cdn-images-1.medium.com/max/170/1*Dpw8-hNGI2fDmosV4E8DVQ.png" /></a></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34392aeaeb39" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/neural-style-transfer-ai-in-art-with-keras-and-tf2-34392aeaeb39">Neural Style Transfer (AI in art) with Keras and TF2</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why domain knowledge is important in Data Science?]]></title>
            <link>https://medium.com/@anand0427/why-domain-knowledge-is-important-in-data-science-anand0427-3002c659c0a5?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/3002c659c0a5</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[economics]]></category>
            <category><![CDATA[gdp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[regression]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Mon, 18 Mar 2019 16:26:52 GMT</pubDate>
            <atom:updated>2019-03-31T10:30:08.324Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why domain knowledge is important in Data Science</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DgwXUWDAd3V5X4YR" /><figcaption>Photo by <a href="https://unsplash.com/@romankraft?utm_source=medium&amp;utm_medium=referral">Roman Kraft</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>What is data science?</h4><p>Before we answer why, we have to understand what data science actually is. According to Wikipedia “Data science is a multi-disciplinary field that uses scientific methods, processes, algorithms, and systems to extract knowledge and insights from data in various forms, both structured and unstructured, similar to data mining.”</p><p>Simply put data science is a field where data in its raw form is processed into information.</p><h4>What does domain knowledge mean?</h4><p>The term “Domain Knowledge” has been in play even before data science became popular. In software engineering, it means the knowledge about the environment in which the target (i.e. software agent) operates.</p><p>We can use the same definition in data science to say — “Domain knowledge is the knowledge about the environment in which the data is processed to reveal secrets of the data”. In other words, the knowledge of the field that the data belongs to is known as Domain Knowledge.</p><h4>How does domain knowledge influence data science?</h4><p>You may have studied data science and machine learning and used some machine learning algorithms like regression, classification to predict on some test data. But the true power of an algorithm and data can be harnessed only when we have some form of domain knowledge. Needless to say, the accuracy of the model also increases with the use of such knowledge of data.</p><p>For example, the knowledge of the automobile industry when working with the relevant data can be used like — Let’s say we have two features Horsepower and RPM from which we can create an additional feature like Torque from the formula</p><pre>TORQUE = HP x 5252 ÷ RPM</pre><p>This could potentially influence the output when we train a machine learning model and result in higher accuracy.</p><h4>Where is domain knowledge useful?</h4><p>You may have understood from the above example that domain knowledge is best useful in feature engineering. Feature engineering is creating features using the domain knowledge to optimize the machine learning algorithms.</p><p>Let’s see an example in the economics related data to support what we have seen so far. The combination of economics and mathematical concepts is called Econometrics and machine learning particularly regression is being used widely these days to create insights using the raw data. We see two models, one without feature engineering and one with feature engineering using domain knowledge of economics. To keep this blog simple and concise we will only fit the models and compare them.</p><p>For example, let’s take the Catalonia GDP data which you can download <a href="https://www.kaggle.com/xavier14/catalonia-gdp-by-demand-components-20002016">here</a>. Let’s see the head of the dataset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PrfMIi2Ldp0hcHa7ewHXVQ.png" /><figcaption>Head of Catalonia GDP dataset</figcaption></figure><p>We will then apply linear regression before and after applying domain knowledge.</p><p><strong>Without application of domain knowledge</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7377d20d2151400457b496af31a78b1a/href">https://medium.com/media/7377d20d2151400457b496af31a78b1a/href</a></iframe><p>Output</p><pre>0.9905101700533853<br>3325.856952652541</pre><p><strong>With the application of domain knowledge</strong></p><p>We apply domain knowledge in creating features like trade openness by combining two features total exports and total imports and domestic demand per GDP without construction by subtracting construction sector from domestic demand and dividing the result with GDP as shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85d733a7cc0cd50aeedfcc422aeaaa7f/href">https://medium.com/media/85d733a7cc0cd50aeedfcc422aeaaa7f/href</a></iframe><p>And finally, fit the model and check its scores.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24d662bbd64020a56ed0b3ecb6681f73/href">https://medium.com/media/24d662bbd64020a56ed0b3ecb6681f73/href</a></iframe><p>Output</p><pre>0.9961357892269006<br>2122.2901303188205</pre><h4>Conclusion</h4><p>In conclusion, we see that using feature engineering by applying domain knowledge gives better accuracy score and lesser RMSE than the model without. You can get the entire code <a href="https://www.kaggle.com/anand0427/catalonia-gdp-insights-and-regression-analysis">here</a>.</p><h4>References</h4><ol><li><a href="https://www.kaggle.com/xavier14/catalonia-gdp-insights-and-regression-analysis">Catalonia GDP kaggle kernel</a></li></ol><h4>Contact</h4><p>You can give me your feedback in the comments below or email me at saianand0427@gmail.com. I am on <a href="https://www.kaggle.com/anand0427">Kaggle</a> and <a href="https://github.com/anand0427">GitHub</a> as well!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3002c659c0a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Network Graph with AT&T data using Plotly]]></title>
            <link>https://medium.com/@anand0427/network-graph-with-at-t-data-using-plotly-a319f9898a02?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/a319f9898a02</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[att]]></category>
            <category><![CDATA[plot]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Mon, 11 Mar 2019 15:13:42 GMT</pubDate>
            <atom:updated>2019-03-11T15:23:36.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*wIWNMwY0PkQ51UouDocIbg.png" /></figure><p>I recently made a network graph using plotly on AT&amp;T data and it turned out to be beautiful so I thought why not share it with everyone.</p><p>This will be a detailed tutorial on how to make a network graph. In addition to plotly, we will also be using <a href="https://networkx.github.io/documentation/stable/">networkx</a> to construct the graph. You can download the dataset from <a href="https://www.kaggle.com/latentheat/att-network-data">kaggle</a>.</p><p>Network graph helps in visualizing connections between different nodes. This, in turn, would help us with network analysis. So without further ado lets discuss our data and see how we can plot it.</p><p>When we see the data there are two columns with source IP and destination IP which represent our edges. And each of these unique IP addresses is a node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*qz1v45orxGYzDXXWvamEtw.png" /><figcaption>Head of the dataset</figcaption></figure><p>We use networkx to build our graph and include our nodes and edges in the graph and then pass on the nodes and edges to plotly to plot.</p><pre>A = list(network_df[&quot;source_ip&quot;].unique())<br>B = list(network_df[&quot;destination_ip&quot;].unique())<br>node_list = list(set(A+B))<br>G = nx.Graph()<br>for i in node_list:<br>    G.add_node(i)</pre><p>In the above for loop, we add all the nodes into the graph using the add_node method. Now we add edges to the graph.</p><pre>for i,j in network_df.iterrows():<br>    G.add_edges_from([(j[&quot;source_ip&quot;],j[&quot;destination_ip&quot;])])</pre><p>We now assign some position to each node for plotting. We can do so using a very convenient method called spring_layout in networkx.</p><pre>pos = nx.spring_layout(G, k=0.5, iterations=50)<br>for n, p in pos.items():<br>    G.node[n][&#39;pos&#39;] = p</pre><p>Now that our graph is set, we are ready to plot using plotly.</p><pre>edge_trace = go.Scatter(<br>    x=[],<br>    y=[],<br>    line=dict(width=0.5,color=&#39;#888&#39;),<br>    hoverinfo=&#39;none&#39;,<br>    mode=&#39;lines&#39;)</pre><pre>for edge in G.edges():<br>    x0, y0 = G.node[edge[0]][&#39;pos&#39;]<br>    x1, y1 = G.node[edge[1]][&#39;pos&#39;]<br>    edge_trace[&#39;x&#39;] += tuple([x0, x1, None])<br>    edge_trace[&#39;y&#39;] += tuple([y0, y1, None])</pre><pre>node_trace = go.Scatter(<br>    x=[],<br>    y=[],<br>    text=[],<br>    mode=&#39;markers&#39;,<br>    hoverinfo=&#39;text&#39;,<br>    marker=dict(<br>        showscale=True,<br>        colorscale=&#39;RdBu&#39;,<br>        reversescale=True,<br>        color=[],<br>        size=15,<br>        colorbar=dict(<br>            thickness=10,<br>            title=&#39;Node Connections&#39;,<br>            xanchor=&#39;left&#39;,<br>            titleside=&#39;right&#39;<br>        ),<br>        line=dict(width=0)))</pre><pre>for node in G.nodes():<br>    x, y = G.node[node][&#39;pos&#39;]<br>    node_trace[&#39;x&#39;] += tuple([x])<br>    node_trace[&#39;y&#39;] += tuple([y])</pre><p>In the code above we create go objects of plotly and assign the data to the objects. Now we assign annotations to the nodes and edges.</p><pre>for node, adjacencies in enumerate(G.adjacency()):<br>    node_trace[&#39;marker&#39;][&#39;color&#39;]+=tuple([len(adjacencies[1])])<br>    node_info = adjacencies[0] +&#39; # of connections: &#39;+str(len(adjacencies[1]))<br>    node_trace[&#39;text&#39;]+=tuple([node_info])</pre><p>Now we plot go objects created above node_trace and edge_trace using Figure.</p><pre>fig = go.Figure(data=[edge_trace, node_trace],<br>             layout=go.Layout(<br>                title=&#39;&lt;br&gt;AT&amp;T network connections&#39;,<br>                titlefont=dict(size=16),<br>                showlegend=False,<br>                hovermode=&#39;closest&#39;,<br>                margin=dict(b=20,l=5,r=5,t=40),<br>                annotations=[ dict(<br>                    text=&quot;No. of connections&quot;,<br>                    showarrow=False,<br>                    xref=&quot;paper&quot;, yref=&quot;paper&quot;) ],<br>                xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),<br>                yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))<br>iplot(fig)</pre><p>The output is an interactive network graph which could be saved as a png, HTML and many other forms. For the sake of using the interactive nature, I saved it as an HTML and uploaded to plot.ly. Check out the below link which is the output of the above code.</p><p><a href="https://plot.ly/~anand0427/0.embed">AT&amp;T network connections | line chart made by Anand0427 | plotly</a></p><p>So that&#39;s it! We created a network graph. The code for it is available on my <a href="https://www.kaggle.com/anand0427/network-graph-with-at-t-data">Kaggle</a> and Github. Let me know what you think below. You can always hit me up on my mail ID saianand0427@gmail.com. Clap and share! See you in my next blog!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a319f9898a02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Bokeh]]></title>
            <link>https://medium.com/@anand0427/introduction-to-bokeh-e21ecab770e7?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/e21ecab770e7</guid>
            <category><![CDATA[plot]]></category>
            <category><![CDATA[bokeh]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Fri, 04 Jan 2019 04:30:32 GMT</pubDate>
            <atom:updated>2019-01-04T04:30:32.406Z</atom:updated>
            <content:encoded><![CDATA[<p>Bokeh is one of the data visualization libraries of a wide range available for data scientists. In this blog, I will explain the basics of Bokeh on how to use Bokeh.</p><p><a href="https://bokeh.pydata.org/en/latest/">Welcome to Bokeh - Bokeh 1.2.0 documentation</a></p><p>Bokeh is available for Python and JavaScript. In this tutorial, I am going to cover Bokeh for Python. Go to this <a href="https://bokeh.pydata.org/en/latest/docs/installation.html">link</a> on how to install Bokeh for python.</p><p>It should not really matter which IDE you use so feel free to use whatever IDE you like. Once you are done installing Bokeh in your computers try importing bokeh in your IDE.</p><pre>import bokeh</pre><p>In bokeh the points or makers on a graph are called glyphs. Read more about glyphs here.</p><p>Lets mark circle glyphs on a plot.</p><pre>from bokeh.io import output_file,show,output_notebook</pre><p>Bokeh.io is for the IO operations like export the file or display it in notebook etc. We will see how this works shortly. Below line is the actual code which is our figure.</p><pre>from bokeh.plotting import figure</pre><p>Lets go ahead and create a figure. For the sake of simplicity and to best show how bokeh works I chose the AirPassengers dataset. I did make some small additions to the dataset like sum and average of the number of passengers flying per month. I will link my Kaggle kernel at the end of this tutorial for some basic analysis on the data.</p><pre>fig = figure(x_axis_label = &quot;Year&quot;,y_axis_label = &quot;Average and Max of Air Passengers per Year&quot;)</pre><p>Now that we have our figure ready we plot our circle glyphs as follows.</p><pre>fig.circle(df[&quot;Year&quot;],df[&quot;Avg&quot;])</pre><p>Now our figure has circle glyph in it and we need to display it.</p><pre>output_notebook()<br>show(fig)</pre><p>Output_notebook is for specifying to display in our notebook. This will give us the following plot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*f7H9GJ5vaJw0ZMNzGZPLag.jpeg" /></figure><p>One of the special things about bokeh is existing plots can be drawn upon with other plots. Observe the following code and its output.</p><pre>fig.line(df[&quot;Year&quot;],df[&quot;Avg&quot;])<br>show(fig)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*mO7m_2Tf3fX0zDXUlYdj7A.jpeg" /><figcaption>Line on top of the circle glyphs</figcaption></figure><p>In the above plot we see the line glyph on top of the circle glyphs. This makes it easier for the developers to plot multiple plots easily without writing too many lines of code or too many subplots. Another example of the same below.</p><pre>fig.x(df[&quot;Year&quot;],df[&quot;Max&quot;],line_color=&quot;red&quot;,size=10)<br>fig.line(df[&quot;Year&quot;],df[&quot;Max&quot;],line_color=&quot;red&quot;)<br>show(fig)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*gY-pzupxREx3AcEcM0RmYQ.jpeg" /></figure><p>In this plot along with out previous one we plot the ‘x’ glyph and the line glyph together.</p><p>Also to be noted is I changed the column from “avg” to “Max” which is the reason we see a different line. But the label is still the same because our figure method is common to all the glyphs.</p><p>Thats all for now. Try and figure out if you can plot the below figure. You can look for the patches glyph in the bokeh docs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*aTiv4X2LjxCP1uPHSNIcuw.jpeg" /><figcaption>Patches Glyph</figcaption></figure><p>The dataset used for this tutorial is available <a href="https://www.kaggle.com/anand0427/airpassengers">here</a>. My Kaggle <a href="https://www.kaggle.com/anand0427/data-visualization-with-bokeh">kernel</a> for reference and the code as solution to the patches glyph.</p><p>Do give me your feedback and suggestions in the comments below. If you would like to see more of Bokeh let me know too. If you need help please feel free to ask anytime.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e21ecab770e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Here’s what happened at the TensorFlow roadshow in Bengaluru]]></title>
            <link>https://medium.com/@anand0427/heres-what-happened-at-the-tensorflow-roadshow-in-bengaluru-e849ddc0144f?source=rss-265cef965c48------2</link>
            <guid isPermaLink="false">https://medium.com/p/e849ddc0144f</guid>
            <category><![CDATA[roadshow]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[bengaluru]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anand]]></dc:creator>
            <pubDate>Wed, 17 Oct 2018 14:36:29 GMT</pubDate>
            <atom:updated>2018-10-17T14:42:23.200Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.tensorflow.org/">TensorFlow</a></p><p>To those of you who didn&#39;t get a chance to attend the roadshow here is a brief summary of the event at Hotel Conrad in Bengaluru.</p><p>First of all click <a href="https://events.withgoogle.com/tfr-blr/schedule-v1/">here</a> for the schedule and <a href="https://events.withgoogle.com/tfr-blr">here</a> for the awesome speakers list.</p><p>All of the speakers were from the TensorFlow team and spoke about some interesting topics which I will list out below.</p><p>1. TensorFlow with eager execution to train and package a saved model. <a href="https://www.tensorflow.org/guide/eager">Cool resource for it.</a></p><p>2. Autographing for writing complex models easily while also not giving up on the graph mode. More on this <a href="https://www.tensorflow.org/guide/autograph">here</a>.</p><p>3. Distribution strategies with <a href="https://www.tensorflow.org/api_docs/python/tf/contrib/distribute/DistributionStrategy">TensorFlow distribute API</a> for spreading across GPU or TPU.</p><p>4. Introduction and evolution to the <a href="https://www.tensorflow.org/performance/datasets_performance">Tensor Processing Unit</a> and performance improvement compared to the GPU.</p><p>5. End to end platform using Tensor flow extended. Still being developed but check out the <a href="https://github.com/tensorflow/model-analysis/tree/master/examples/chicago_taxi">examples</a>.</p><p>6. TensorFlow beyond Python so <a href="https://github.com/tensorflow/swift-tutorials">TensorFlow for Swift</a>.</p><p>7. Building models using <a href="http://js.tensorflow.org/">TensorFlow.js</a> which is basically same as the TensorFlow in Python but on the browser.</p><p>8. <a href="https://tensorflow.org/mobile/tflite">TensorFlow Lite</a>, lightweight TensorFlow for devices which have less power.</p><p>9. <a href="https://github.com/tensorflow/tensor2tensor">Tensor2Tensor</a> a library of deep learning models and datasets.</p><p>10. Lastly and my favorite of all. GANS. This talk was about how to enable the machine to learn the patterns in music and to generate new music with some input. Also spoke about text generation and autoencoders. No particular link for this but check out DCGANs.</p><p>Overall it was a good day and looking forward to the next one. Let me know what you think. Also If you were there and I missed any let me know in the comments below.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e849ddc0144f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>