<?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 Nikhil Vyas on Medium]]></title>
        <description><![CDATA[Stories by Nikhil Vyas on Medium]]></description>
        <link>https://medium.com/@vyasnikhil30?source=rss-1c083ae2177b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*PWYjFFgmVVzUDmxFMBoYPQ.jpeg</url>
            <title>Stories by Nikhil Vyas on Medium</title>
            <link>https://medium.com/@vyasnikhil30?source=rss-1c083ae2177b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:46:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vyasnikhil30/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[The Data Engineer’s Guide to File Formats: Parquet vs ORC vs Avro]]></title>
            <link>https://medium.com/towards-data-engineering/the-data-engineers-guide-to-file-formats-parquet-vs-orc-vs-avro-470e1d7f7643?source=rss-1c083ae2177b------2</link>
            <guid isPermaLink="false">https://medium.com/p/470e1d7f7643</guid>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[parquet]]></category>
            <dc:creator><![CDATA[Nikhil Vyas]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 16:38:11 GMT</pubDate>
            <atom:updated>2025-10-13T07:33:24.850Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Stop wasting compute. Your choice of file format — row-based or columnar — is the biggest lever you have for optimizing speed and cost in your Big Data pipelines.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6toewfK9Q6yv3PS1F1Fclg.png" /></figure><p>When you start architecting a Big Data system with tools like <strong>Apache Spark</strong>, <strong>Hive</strong>, or <strong>Presto</strong>, you face one of the most critical design questions: <strong><em>Which file format should I use?</em></strong></p><p>This single decision isn’t just a technical detail. It can <strong>drastically impact</strong> your:</p><ul><li>Query performance (i.e., how fast your dashboards load).</li><li>Storage cost (i.e., your cloud bill).</li><li>Pipeline efficiency (i.e., how long your ETL jobs run).</li></ul><p>In this article, let’s cut through the noise and deeply understand the three titans of the Big Data world — <strong>Parquet</strong>, <strong>ORC</strong>, and <strong>Avro</strong> — and provide a clear, actionable guide on when to use which one.</p><h3>💾 Why File Formats are Your Cost-Saving Lever</h3><p>Big Data systems deal with massive, ever-growing volumes of data. The fundamental way this data is organized, stored, and read directly determines the speed and cost of your entire infrastructure.</p><p>Imagine your job processes 1 TB of transaction logs every single day. If your format forces you to read <strong>100% of the data</strong> when your query only needs <strong>10%</strong>, you’re wasting:</p><ol><li><strong>I/O:</strong> Time spent transferring data from disk/S3.</li><li><strong>Compute:</strong> CPU cycles spent decompressing and deserializing the unnecessary data.</li><li><strong>Money:</strong> Higher cloud costs for storage and compute.</li></ol><p>That’s why choosing the right file format is arguably the most foundational design decision a data engineer makes.</p><h3>🧩 The Core Difference: Row-Based vs. Columnar Storage</h3><p>Before we compare the formats themselves, you must internalize the difference between the two storage types.</p><p>Type Description Best For<strong> Row-based </strong>Stores <strong>complete rows</strong> together on disk.Transactional data, frequent <em>writes</em>, data transfer/serialization.<strong>Columnar </strong>Stores each <strong>column separately</strong> on disk.Analytical queries, <em>aggregations</em>, filtering, OLAP workloads.</p><p>Export to Sheets</p><h3>An Illustrative Example</h3><p>Consider a simple user table:</p><p><strong>NameAgeCountry</strong>A25IndiaB30USAC35UK</p><p>Export to Sheets</p><h4>1. Row-based (like Avro)</h4><p>The data is stored sequentially, row by row:</p><pre>A,25,India<br>B,30,USA<br>C,35,UK</pre><p><strong>Pros:</strong> Fast to write/append. If you need all the fields for a single record, this is efficient.</p><p><strong>Cons:</strong> Slow for analytical queries. To calculate the average age, you must read the <strong>Name</strong> and <strong>Country</strong> data, which you don’t need.</p><h4>2. Columnar (like Parquet, ORC)</h4><p>The data is stored sequentially, column by column:</p><pre>Name: A,B,C<br>Age: 25,30,35<br>Country: India,USA,UK</pre><p><strong>Pros:</strong> <strong>Faster for analytical queries.</strong> If you only need the average age, you only read the <em>Age</em> column.</p><p><strong>Cons:</strong> Slower to write/update a single row, as the data must be fragmented across column blocks.</p><p><strong>The takeaway? Analytical queries (OLAP) love columnar formats.</strong></p><h3>🔍 The Big Three: Parquet, ORC, and Avro Deep Dive</h3><p>Let’s explore their core functionalities, compression, and specific strengths, including the subtle but important differences between the two columnar titans.</p><h3>Apache Parquet: The Analytics King</h3><p><strong>Parquet</strong> is the most popular <strong>columnar</strong> format, particularly favored by <strong>Apache Spark</strong> and cloud data platforms (like AWS Athena, Google BigQuery, and Snowflake).</p><p>It achieves its efficiency through <strong>Columnar Storage</strong> and <strong>Predicate Pushdown</strong>. It stores min/max statistics for data within each column chunk. When you run a query like SELECT * FROM sales WHERE amount &gt; 100, the Parquet reader checks the statistics and can <strong>completely skip reading entire blocks</strong> that only contain values less than or equal to 100.</p><ul><li><strong>Best For:</strong> Data lakes, batch analytics, and general ETL pipelines. It is the default standard for modern analytical workloads.</li><li><strong>Example Use Case:</strong> A 500-column IoT log dataset. Your nightly job only needs the device_id and the temperature reading. <strong>Parquet</strong> only reads those two columns, ignoring the other 498.</li></ul><p>Python</p><pre># Spark Example: Perfect for analytical queries<br>df.write.mode(&quot;overwrite&quot;).parquet(&quot;/data/output/parquet/&quot;)</pre><blockquote><em>If your queries only touch a handful of columns out of hundreds, </em><strong><em>Parquet drastically reduces I/O</em></strong><em> and compute, saving you significant money.</em></blockquote><h3>Apache ORC (Optimized Row Columnar): The Hive Specialist</h3><p><strong>ORC</strong> is the other leading <strong>columnar</strong> format, but its heritage is crucial: it was developed by Hortonworks (now part of Cloudera) to serve as the native, high-performance format for the <strong>Apache Hive</strong> ecosystem. If Parquet is the general-purpose columnar tool for Spark and data lakes, <strong>ORC is the specialized workhorse for transactional data warehouses built on Hive.</strong></p><h4>ORC’s Performance Edge over Parquet</h4><p>While both formats are columnar, ORC includes more sophisticated internal features, giving it an edge in specific scenarios:</p><ul><li><strong>Advanced Indexing:</strong> ORC goes beyond Parquet’s standard min/max statistics by incorporating <strong>Lightweight Indexes</strong> (tracking data range per stripe) and <strong>Bloom Filters</strong>.</li><li><strong>Bloom Filters</strong> are a probabilistic data structure that can tell the query engine if a specific value (like a user_id in a WHERE clause) is <strong>definitely not</strong> in a block. This is extremely efficient for highly selective queries, potentially eliminating I/O faster than Parquet.</li><li><strong>ACID Compliance:</strong> ORC is natively structured to support <strong>ACID transactions</strong> (Atomicity, Consistency, Isolation, Durability) within Hive 3.0+. Its file layout is optimized to manage <strong>delta files</strong> (transactional updates/deletes) and perform background compaction, which is necessary for row-level modification operations. Parquet requires an external system (like Delta Lake or Iceberg) to achieve ACID; ORC supports Hive’s <em>internal</em> approach.</li><li><strong>Best For:</strong> Enterprise data warehouses built on Hive/Tez/Impala, analytical workloads requiring true ACID guarantees, and scenarios demanding the highest compression ratios.</li><li><strong>Example Use Case:</strong> A financial data warehouse where users frequently run complex aggregations on large tables <em>and</em> need to perform row-level updates (e.g., correcting a specific transaction). <strong>ORC</strong> is the superior choice here due to its <strong>native ACID integration.</strong></li></ul><p>Python</p><pre># Spark Example: Optimized for Hive ecosystems<br>df.write.mode(&quot;overwrite&quot;).orc(&quot;/data/output/orc/&quot;)</pre><blockquote><em>If your infrastructure relies heavily on </em><strong><em>Hive/Tez/Impala</em></strong><em> and needs </em><strong><em>ACID</em></strong><em> functionality, </em><strong><em>ORC</em></strong><em> is the mandatory and faster choice due to its specific indexing and metadata design.</em></blockquote><h3>Apache Avro: The Serialization Workhorse</h3><p><strong>Avro</strong> is the essential outlier among the big three, as it is a <strong>row-based</strong> format. Its design priorities are <strong>portability, serialization speed, and resilience to schema changes</strong>, not maximizing analytical query performance. This makes it ideal for data <em>in motion</em> and interchange between services.</p><h4>The Power of Decoupling</h4><p>Avro’s core strength lies in its approach to the schema:</p><p><strong>Self-Describing Data:</strong> Avro files store the <strong>schema directly with the data</strong>. This means the data is entirely self-contained, simplifying cross-platform transfer and making it easy for any application, regardless of language, to read the file.</p><p><strong>Robust Schema Evolution:</strong> This is Avro’s killer feature. It defines clear rules for resolving differences between the <strong>writer’s schema</strong> (the schema used to create the data) and the <strong>reader’s schema</strong> (the schema the consuming application expects).</p><ul><li>If a field is <strong>added</strong> in the writer’s schema, older readers using the old schema can safely ignore it.</li><li>If a field is <strong>removed</strong> in the writer’s schema, readers can use a defined default value.</li><li>This <strong>decouples</strong> producers from consumers, allowing streaming teams to add fields without immediately breaking downstream pipelines.</li></ul><p>Because its binary format is compact and it avoids the overhead of columnar organization during the write process, Avro provides <strong>very high write performance</strong>, making it perfect for rapid data ingestion.</p><ul><li><strong>Best For:</strong> Data ingestion, Kafka topics, inter-service data transfer, and microservices integration where schema flexibility is paramount.</li><li><strong>Example Use Case:</strong> Ingesting event data from a <strong>Kafka</strong> topic. You need to write the data to S3 as quickly as possible, and you anticipate the event structure will change frequently. <strong>Avro</strong> guarantees the fastest write speed and ensures pipeline stability even when new fields are added by the source team.</li></ul><p>Python</p><pre># Spark Example: Ideal for raw ingestion and data transport<br>df.write.format(&quot;avro&quot;).save(&quot;/data/output/avro/&quot;)</pre><blockquote><strong><em>💡 Pro Tip:</em></strong><em> Think of Avro as the </em><strong><em>perfect envelope</em></strong><em> for data when it first arrives. Use it to guarantee successful transfer and schema stability before transforming the data into a columnar format like Parquet for analytical processing.</em></blockquote><h3>📊 Real-world Perspective: When to Choose What</h3><p>The choice isn’t just theoretical — it saves real money and time.</p><blockquote><em>In one production pipeline, switching a large fact table from </em><strong><em>Avro (Row-based)</em></strong><em> to </em><strong><em>Parquet (Columnar)</em></strong><em> reduced the runtime of our aggregation jobs by </em><strong><em>nearly 60%</em></strong><em>. This was a direct result of Parquet’s ability to skip reading the majority of the data.</em></blockquote><p>Scenario Recommended Format Why?</p><p><strong>Batch Analytics (Spark, Presto) — Parquet </strong>Columnar storage and superior predicate pushdown for general analysis.</p><p><strong>Hive Warehouse / ACID Tables — ORC </strong>Optimized indexing (Bloom Filters) and robust ACID transaction support.</p><p><strong>Streaming Data (Kafka, Flink) — Avro F</strong>ast write speed and robust, flexible schema evolution.</p><p><strong>Data Lake Storage (Final Layer) — Parquet </strong>The best balance of compression and query speed for modern engines.</p><h3>🧠 Summary: Choose Your Format Wisely</h3><p>Each file format serves a distinct purpose in your architecture. There is no single “best” choice, only the <em>right</em> choice for the <em>job</em>.</p><ul><li><strong>🟩 Parquet:</strong> Your <strong>analytics workhorse</strong>. Use it for data lakes, Spark jobs, and OLAP.</li><li><strong>🟨 ORC:</strong> Your <strong>Hive powerhouse</strong>. Use it when you need robust ACID guarantees within the Hive ecosystem.</li><li><strong>🟦 Avro:</strong> Your <strong>serialization specialist</strong>. Use it for data transfer, Kafka topics, and schema evolution flexibility.</li></ul><p>As a Data Engineer, mastering these file formats is non-negotiable. It’s the low-level technical detail that directly translates into high-level business savings and performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470e1d7f7643" width="1" height="1" alt=""><hr><p><a href="https://medium.com/towards-data-engineering/the-data-engineers-guide-to-file-formats-parquet-vs-orc-vs-avro-470e1d7f7643">The Data Engineer’s Guide to File Formats: Parquet vs ORC vs Avro</a> was originally published in <a href="https://medium.com/towards-data-engineering">Towards Data Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Partitioning vs Bucketing in Spark]]></title>
            <link>https://medium.com/towards-data-engineering/partitioning-vs-bucketing-in-spark-a66e2fca5fe3?source=rss-1c083ae2177b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a66e2fca5fe3</guid>
            <category><![CDATA[data-processing]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-engineer]]></category>
            <dc:creator><![CDATA[Nikhil Vyas]]></dc:creator>
            <pubDate>Sun, 28 Sep 2025 15:57:30 GMT</pubDate>
            <atom:updated>2025-10-11T11:55:26.598Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many ways to write the data on disk, but have you ever thought about what can be the most efficient way to store your data, so that you can optimize your processing effort and cost?</p><p>In my 4+ years of experience as a Data Engineer, I have seen many data enthusiasts make this common mistake of simply saving the dataframe and reading it back for use later, but what if we can optimize it somehow and save the cost of future processing? Partitioning and Bucketing are the Answer to this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHaezg-csSiqESJVFsaP2w.png" /><figcaption>Discovering which technique to use ,WHEN</figcaption></figure><h3><strong><em>What is Partitioning?</em></strong></h3><p>Imagine your school asks you to maintain a list of <strong>all students from the past 10 years</strong> — including their name, phone number, address, and job details. Now, whenever someone wants the full details of a student, they’ll provide you with their <strong>year of graduation</strong>, <strong>stream</strong>, and <strong>name</strong>.</p><p>One way to handle this is to keep <strong>all the data in a single text file</strong> and <strong>scan through the entire file</strong> every time you need to find a record. But that’s obviously <strong>slow, inefficient, and time-consuming</strong> — especially as the data grows.</p><p><strong><em>Partitioning is the solution.</em></strong></p><p>Instead of storing everything together, you organize the data in a <strong>structured and segregated way</strong>:</p><p>First, you create separate <strong>folders for each graduation year</strong>. Now, when you search for a student from 2020, you only need to look inside the 2020 folder — no need to scan all 10 years of data.</p><p>Next, inside each year folder, you create <strong>subfolders for each stream</strong> — Science, Commerce , and Arts. This reduces the search space even more, so you’re only scanning a fraction of the data.</p><p>This is exactly how partitioning works in big data systems like Spark:<br> You write and store data in a way that makes it much faster and cheaper to retrieve later — especially when dealing with millions or even billions of records.</p><p>By pruning out unnecessary data early, partitioning helps queries run significantly faster and reduces compute costs dramatically.</p><pre>df.write.partitionBy(&quot;graduation_year&quot;, &quot;stream&quot;).parquet(&quot;students_partitioned&quot;)</pre><p>This will create a folder structure like:</p><pre>students_partitioned/graduation_year=2020/stream=Science/<br>students_partitioned/graduation_year=2020/stream=Commerce/<br>students_partitioned/graduation_year=2021/stream=Arts/<br>...</pre><p><strong><em>Key takeaway:</em></strong> Partitioning is about organizing your data smartly so that future queries don’t waste time and resources scanning data they don’t need.</p><h3>What is Bucketing?</h3><p>Now, let’s switch gears to a Flights dataset example.</p><p>Suppose analysts often join the Flights dataset with the Passengers dataset on the column flight_id.</p><p>Even if the flight data is partitioned by date_of_departure or destination_city, Spark may still need to perform a shuffle during the join, which is expensive.</p><p><strong><em>Bucketing is the solution.</em></strong></p><p>When saving the Flights dataset, we can tell Spark to bucket the data by flight_id into, say, 8 buckets:</p><pre>df.write.bucketBy(8, &quot;flight_id&quot;).saveAsTable(&quot;flights_bucketed&quot;)</pre><p>In the background it is calculating a simple Hash function for all the values in the column flight_id, which returns the result between 0 and 7 ( 8 buckets) , and basis the results, it puts the record in that bucket.</p><p>For Example — if Flight ID was 1001, it does something like — 1001 % 8 = 1, So this record goes to the bucket number 1.</p><p>Similarly, the Passengers dataset is bucketed the same way.</p><p>Now, Spark knows that all records with the same flight_id will always be in the same bucket file. So when joining, Spark can simply match:</p><ul><li>bucket_00000 from Flights with bucket_00000 from Passengers</li><li>bucket_00001 with bucket_00001</li><li>… and so on</li></ul><p>This avoids the need to reshuffle data across the cluster.</p><p><strong><em>Key takeaway:</em></strong> Bucketing is about storing your data in such a way that Spark can save multiple Shuffle efforts while joining the data with other datasets.</p><p>Partitioning VS Bucketing -</p><p>In Spark, Partitioning and Bucketing are two powerful techniques for optimizing how data is stored and accessed:</p><ul><li>Partitioning organizes data into folders based on frequently filtered columns (like graduation_year in the school example). This allows queries to skip irrelevant data, making filters much faster.</li><li>Bucketing divides data into a fixed number of buckets based on a hash of a column (like flight_id). This is especially useful for joins and aggregations, as it avoids expensive data shuffles.</li></ul><p>Together, these strategies help you:</p><ul><li>Reduce query times</li><li>Save compute resources</li><li>Handle millions (or billions) of records efficiently</li></ul><p><strong>Practical tip:</strong> Use <strong>partitioning</strong> when queries frequently filter on certain columns, and <strong>bucketing</strong> when queries often join on high-cardinality columns.</p><p>If you found this useful and want <strong>hands-on guidance with Spark, SQL, or Python</strong>, I also offer <strong>1:1 sessions</strong> where I help with career roadmap, resume review, and mock interviews for Data Engineering. You can check them out here: <a href="https://topmate.io/nikhil_vyas11">TopMate — Nikhil Vyas</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a66e2fca5fe3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/towards-data-engineering/partitioning-vs-bucketing-in-spark-a66e2fca5fe3">Partitioning vs Bucketing in Spark</a> was originally published in <a href="https://medium.com/towards-data-engineering">Towards Data Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding a Single Neuron’s role in Neural Network.]]></title>
            <link>https://medium.com/analytics-vidhya/understanding-a-single-neurons-role-in-neural-network-77bb3251e9db?source=rss-1c083ae2177b------2</link>
            <guid isPermaLink="false">https://medium.com/p/77bb3251e9db</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neurons]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Nikhil Vyas]]></dc:creator>
            <pubDate>Sun, 10 May 2020 05:19:36 GMT</pubDate>
            <atom:updated>2020-05-11T16:28:23.509Z</atom:updated>
            <content:encoded><![CDATA[<p>Most of you might have heard the term Neural network(if you didn’t, it’s okay) and tried to apply it to some standard problems, but you might have noticed, when it comes to implementing them, you need to take the support of many libraries, which on one hand makes its implementation easy but at the same time it takes away that practical intuition, “feeling”, of the neuron we need to have in order to be comfortable in applying it on any new problem. So in this article, we will walk through a simple intuition of how a neuron functions in python(without using many libraries).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1cJ5EWOejoS-gInig2_gw.jpeg" /><figcaption>Src: Sikich</figcaption></figure><p>So, before we move further, let’s see the abstract definition of the neural network which is used for practical purposes-</p><p>A Neural Network is a collection of neurons(which are analogous to the human brain), which are connected to every other neuron on the next layer(outgoing) and to the layer just before it(inputs). These connections have a value associated with them which is known as ‘<em>weights</em>’ and every neuron has a<em> bias</em> which helps in giving the right direction. Now after processing them, we apply an activation function that produces an output that predicts the most desired(according to input)result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQd98NncOH5Kko-uJTsHcA.png" /><figcaption>Source: Otexts</figcaption></figure><p>Now, let us get the start by one single neuron by considering its input scenario,i.e. what a single neuron’s input processing code might look like… We know that a single neuron will take input from all the neurons from the previous layer, multiply them by their weights and add a bias, so let’s pick up one of the ‘<em>blue colored neuron</em>’ and write about that.</p><blockquote>NOTE: here we are not considering the whole network or the whole layer. We are just looking at what a single neuron is doing.</blockquote><pre>inputs=[1,2,3,4]          #from the green neurons<br>bias=2<br>weights=[0.2,0.5,0.9,0.1] #Corresponding to the four arrows(edges)</pre><pre>output=inputs[0]*weights[0]+inputs[1]*weights[1]+ inputs[2]*weights[2]+ inputs[3]*weights[3]+ bias</pre><pre>print(output)</pre><p>This is same as the dot product as shown(if you don’t know what dot product is you can find an intuitive explanation here):</p><p><a href="https://www.mathsisfun.com/algebra/vectors-dot-product.html">Dot Product</a></p><pre>import numpy as np</pre><pre>inputs=[1,2,3,4]  #from the green neurons<br>bias=2<br>weights=[0.2,0.5,0.9,0.1] #Corresponding to the four arrows(edges)</pre><pre>output=np.dot(inputs,weights)+bias<br>print( output)</pre><p>The output is: 6.300000000000001</p><p>This is a pretty simple code about how a single neuron processes its input. Now after it processes its input values, we have to apply an ‘Activation function’ to the obtained value to get the final output of the neuron.</p><h3>What is Activation Function &amp; Why we use it??</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT8qB2tWl0dA9qMaXe%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxT8qB2tWl0dA9qMaXe%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FxT8qB2tWl0dA9qMaXe%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="363" frameborder="0" scrolling="no"><a href="https://medium.com/media/1492c4c6144b1d2d043ce04c7fdfda41/href">https://medium.com/media/1492c4c6144b1d2d043ce04c7fdfda41/href</a></iframe><p>Before discussing various kinds of activation function, let us look into why we need an activation function-</p><p>So in simple terms, the basic task of the activation function is to provide a way to decide to activate(produce a significant value as output) a neuron based on its weights and bias.</p><p>Also, it helps in introducing non-linearity to the neural network’s output, and without it will be able to perform only linear mapping between x(inputs) and y(outputs).</p><p>Without an activation function, the output will be just the dot product of the input vector and the weights matrix, which is added with bias, since all the terms in the calculations are linear the output will also be a linear line.</p><p>Usually, the more complex the data is, from which we are trying to learn(make predictions), the more non-linear the mapping from the features to the ground truth label.</p><h3>Types of activation functions</h3><p>Now that we know why we need an activation function, it is the right step to look for some of the activation functions. There are a variety of activation functions available, let us look at the popular ones-</p><p><strong><em>Sigmoid Activation</em></strong>-it’s a mathematical function that maps any value within the range of 0 to 1, as you can notice in the image the value never reaches exactly 1or 0 it just tends to be 1 or 0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*YuabQiGBA-W-5PWsojwN5A.png" /><figcaption>Source: <a href="https://www.researchgate.net/figure/An-illustration-of-the-signal-processing-in-a-sigmoid-function_fig2_239269767">https://www.researchgate.net/figure/An-illustration-of-the-signal-processing-in-a-sigmoid-function_fig2_239269767</a></figcaption></figure><p><strong><em>TanH Activation</em></strong>- it’s a mathematical function, which is also called the Hyperbolic Tangent function, which maps the values between -1 and +1. Same as sigmoid it also never reaches the exact value of 1 or -1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*IcQ-P-cKAyt6N4vkwgCrdg.png" /><figcaption>Source: <a href="https://www.experfy.com/blog/activation-functions-within-neural-networks">https://www.experfy.com/blog/activation-functions-within-neural-networks</a></figcaption></figure><p><strong><em>ReLU Activation</em></strong>-it stands for Rectified Linear Unit, it is the most common and popular activation function.it maps negative values to 0 and positive values to themselves, the image will make it more clear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*UWlySS1IjVLAzcvcS__s7g.png" /><figcaption>Source: <a href="https://kraj3.com.np/blog/2019/11/non-linear-activation-functions/">https://kraj3.com.np/blog/2019/11/non-linear-activation-functions/</a></figcaption></figure><p><strong><em>SoftMax Activation</em></strong>- this activation function is used only in the output layer of the neural network, only when we need probability scores during classification problems. In this function, the output value not only depends on its input but also on the input of the other neurons of the same layer, as this function gives the probability of that particular(particular to neuron) output. <strong><em>The sum of the output of all the neurons is always 1, as it gives the probability.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRlP3JC2XChNOwrFPngACw.png" /><figcaption>Source: <a href="https://stackoverflow.com/questions/58999818/constrain-activation-on-keras-neural-net-output-layer">https://stackoverflow.com/questions/58999818/constrain-activation-on-keras-neural-net-output-layer</a></figcaption></figure><p>Now that we know of various activation functions, let us apply the activation function using python on our sample data used above. Since the sigmoid function is the common one so let us apply it here.</p><pre>import numpy as np <br>import math</pre><pre>inputs=[1,2,3,4]  #from the green neurons<br>bias=2<br>weights=[0.2,0.5,0.9,0.1] #Corresponding to the four arrows(edges)</pre><pre>output=np.dot(inputs,weights)+bias</pre><pre>result= 1/(1 + np.exp(-output))</pre><pre>print( result)</pre><p>The output is:0.9981670610575072</p><p>Similarly, you can apply other activation functions too.</p><h3>Error</h3><p>Now let us talk about the error in the output which tells us how much our current output deviates from the true output.</p><p>In our sample case let our true output be 1(we are considering only 1 neuron in our case, which has produced the above output.). So to calculate the error we do the summation of the squared difference of the obtained and the true value. This is also known as the loss function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j0jcfZkZBjdzG2o9Ot9-OQ.png" /><figcaption>Error is denoted by J. y and y^ are the obtained and true value respectively.</figcaption></figure><p>So using this formula, the error in our case is calculated as</p><pre>import numpy as np <br>import math</pre><pre>inputs=[1,2,3,4]  #from the green neurons<br>bias=2<br>weights=[0.2,0.5,0.9,0.1] #Corresponding to the four arrows(edges)</pre><pre>output=np.dot(inputs,weights)+bias<br>print(output)</pre><pre>result= 1/(1 + np.exp(-output))</pre><pre>print( result)</pre><pre>error=1/2*((result-1)**2)</pre><pre>print(error)</pre><p>The error comes out to be: 1.6798325834533343e-06</p><p>As we know that no one can predict the right amount of weights needed to get the error-free output. We usually initialize the weights with random values and then look at the error value at the output layer, which is generally large initially but we need a way to converge to the optimal weight value to get the model ready for prediction.</p><p>Now we should do something to reduce this error, to do this, we apply an algorithm called Backpropagation.</p><h3>Backpropagation</h3><p>It is an algorithm that looks for minimizing the error, in the weight space using a technique called gradient descent. If you do not know what gradient descent is, here is an informative explanation you can refer to</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIHZwWFHWa-w%3Fstart%3D1%26feature%3Doembed%26start%3D1&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIHZwWFHWa-w&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIHZwWFHWa-w%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/12c2a05415b0767f43711a6d22e5f641/href">https://medium.com/media/12c2a05415b0767f43711a6d22e5f641/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*dEQwi19I68NS_OGnBRl1XA.png" /><figcaption>Backpropagation- the weights are updated based on the rate of change of error w.r.t. rate of change of weight.</figcaption></figure><p>The weights are updated by adding/subtracting the derivative(error w.r.t. weight) times(multiplied) the learning rate referred to as “<em>ETA</em>”. So using this we always make a move towards the more optimized weights vector, we stop when we get the error below a certain value(which is very small).</p><p>If you want to know about the calculus involved in Backpropagation, then Check out its explanation from the below site.</p><p><a href="https://www.edureka.co/blog/backpropagation/">What Is Backpropagation? | Training A Neural Network | Edureka</a></p><p>I hope you found this article beneficial and now have a clearer view of what a neuron does. If you have any suggestions or questions, feel free to contact me by leaving a message.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77bb3251e9db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/understanding-a-single-neurons-role-in-neural-network-77bb3251e9db">Understanding a Single Neuron’s role in Neural Network.</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[An efficient approach to Handle Missing Data.]]></title>
            <link>https://medium.com/analytics-vidhya/an-efficient-approach-to-handle-missing-data-1ff73d5cfe3d?source=rss-1c083ae2177b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ff73d5cfe3d</guid>
            <category><![CDATA[data-pre-processing]]></category>
            <category><![CDATA[data-preparation]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[missing-data]]></category>
            <dc:creator><![CDATA[Nikhil Vyas]]></dc:creator>
            <pubDate>Fri, 20 Mar 2020 13:37:57 GMT</pubDate>
            <atom:updated>2020-05-12T06:27:52.275Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*65h7hXbqJoG5PbAN3sAdsg.jpeg" /></figure><p>Most of the Real-World datasets available have missing entries in them. So in order to apply Machine learning algorithms on such datasets, we need to handle the missing values in them.</p><p>For many projects concerned with data science, the engineers spend plenty of time to preprocess the data and handling missing values is a crucial step to prepare the data for the algorithm.</p><p>This situation mostly occurs as a result of manual data entry procedures, equipment errors, and incorrect measurements.</p><p>First, let us know more about these missing values. There are three kinds of missing values, namely -</p><ul><li><strong><em>MISSING COMPLETELY AT RANDOM (MCAR)</em></strong> -Values in a data set can miss completely at random (MCAR) if the events that lead to any particular data-item missing are independent both of observable variables and unobservable parameters of interest, and occur entirely at random. It occurs when someone just forgets to enter the data in a particular cell, or someone is just lazy to fill it, nothing serious here.MCAR means there is no relationship between the missingness of the data and any values, observed or missing.</li><li><strong><em>MISSING AT RANDOM (MAR)</em></strong>- Occurs when the missing-ness is related to a particular variable, but it is not related to the value of the variable that has missing data. An example of this is accidentally omitting an answer on a questionnaire. What it means, is that the missingness of data can be predicted by other features in the dataset</li><li><strong><em>MISSING NOT AT RANDOM (MNAR)</em></strong>-<strong><em> </em></strong>This is data that is missing for a specific reason (i.e. the value of the variable that is missing is related to the reason it is missing). An example of this is if a certain question on a questionnaire tends to be skipped deliberately by participants with certain characteristics. The fact that the data is missing is related to the unobserved data, i.e. the data that we don’t have, the missingness is related to factors that we didn’t account for.</li></ul><p>Now let us discuss the most common ways in which we handle the missing values and what are the problems associated with them.</p><ul><li><strong>Do Nothing</strong> — It is the simplest way, there are some algorithms (like XGboost.) which handle the missing values themselves. While many algorithms throw errors if there is missing data. So if you are using an algorithm that takes care of the missing values by itself, then go on.</li><li><strong>Replacing the missing values by taking the mean</strong> of the column, in which the missing value exists.</li><li><strong>Replacing the missing values by taking the median</strong> of the column, in which the missing value exists</li><li><strong>Replacing the missing values by taking the mode</strong> of the column, in which the missing value exists</li><li><strong>By imputing zero or a constant value</strong> in place of the missing values.</li></ul><p>These methods seem easy to use but they are not probably the best choice for an accurate prediction.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F3b6B8XQSmoH82SE3o8%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F3b6B8XQSmoH82SE3o8%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F3b6B8XQSmoH82SE3o8%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="217" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed78386baf9e54d10e1c76668e1fafb1/href">https://medium.com/media/ed78386baf9e54d10e1c76668e1fafb1/href</a></iframe><p>While all these methods are easy to implement and work well with a small dataset, there are some repercussions if the dataset is large.</p><ul><li>They do not consider the correlation between features in the dataset and work only at the column level.</li><li>It can make data bias(through zero and constant value).</li><li>Do not give an accurate result.</li><li>May not represent the correct data form(eg. the columns of integers can have a float value if imputed using the mean)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*kaWKrnEQEAI6fiBkFx1zmw.png" /></figure><p>Now let us discuss what is needed to be done to get a relatively more accurate result if there are missing values in the dataset. To show this we consider the following dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*u6ArQl_JDtMczYuG_JZDGg.png" /></figure><p>First, let us import the libraries and the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y37ii4itxRF5BjMz99Z1nQ.png" /></figure><p>Now let’s divide the dataset as follows</p><p>‘X’ — contains all the data entries which had no missing values.</p><p>‘Y’ — contains the columns which have the missing(nan) values.</p><p>‘X_missing_rows’ — contains the data entries(rows) which contain the ‘nan’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OqBnylWDgLctY6P9adV-kg.png" /></figure><p>Now in this example, we are applying random forest regression as it gives pretty good results, but you can try it with any other algorithm you like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FK8d6FUiFvy36M6ifcXeww.png" /></figure><p>The missing values in our case are -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*qhct6WiLVp1LBoYiwC2-xg.png" /></figure><p><strong>References —</strong></p><p><a href="https://www.slideshare.net/akanniazeezolamide/missing-data-and-causes">https://www.slideshare.net/akanniazeezolamide/missing-data-and-causes</a></p><p><a href="https://medium.com/@danberdov/types-of-missing-data-902120fa4248">https://medium.com/@danberdov/types-of-missing-data-902120fa4248</a></p><p>I hope that you find this article useful and now know what are the problems faced in handling missing data and how to resolve them efficiently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ff73d5cfe3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/an-efficient-approach-to-handle-missing-data-1ff73d5cfe3d">An efficient approach to Handle Missing Data.</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[Data Hiding using Images]]></title>
            <link>https://medium.com/@vyasnikhil30/data-hiding-using-images-ce2c02b2163a?source=rss-1c083ae2177b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce2c02b2163a</guid>
            <dc:creator><![CDATA[Nikhil Vyas]]></dc:creator>
            <pubDate>Sat, 14 Mar 2020 17:31:48 GMT</pubDate>
            <atom:updated>2020-03-14T17:31:48.312Z</atom:updated>
            <content:encoded><![CDATA[<p>Think if you can hide /store all your confidential information in a way in which no common person could think of it!! You could keep your passwords, secret messages, and important phone numbers and even share them without having the risk of anyone else having a peek at your screen.</p><p>All this is possible if we use IMAGES to hide/store your private data. And only those persons who have the proper code and know the length of the message, can decipher the message.</p><p>For understanding your article, you need to have-</p><p>· Basic knowledge of pixels of an image, and</p><p>· MATLAB (only if you want to understand/change the code)</p><p>Now for hiding the data, It is better if we use noisy images as after encrypting the message, the image becomes noisy(very little amount), so it will act as good camouflage.</p><p>Here we will use the satellite grayscale image of an area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*J32wfxVUqdmHZ_lLFHdwRw.jpeg" /><figcaption>Original Image</figcaption></figure><p>Now using the encryption code</p><pre>clc;</pre><pre>clear all;</pre><pre>cd=imread(&#39;input.png&#39;);</pre><pre>[rows,cols,planes]=size(cd);</pre><pre>if planes &gt;1                           %Handeling RGB Images</pre><pre>    cd=rgb2gray(cd);</pre><pre>end</pre><pre>Hidden_img = cd;</pre><pre>message=input(&#39;Please enter the message you want to hide: &#39;,&#39;s&#39;);</pre><pre>len=strlength(message);</pre><pre>bit_total=len*8;</pre><pre>message=uint8(message);               %message to bit integers</pre><pre>message=dec2bin(message,8);           <br>%converting those integers to binary</pre><pre>message_str=&#39;&#39;;</pre><pre>for i=1:len</pre><pre>    message_str=append(message_str,message(i,:));   <br>    %creating a unified string</pre><pre>end<br>curr_index=1 ;   %index in message string</pre><pre>for x=1:rows</pre><pre>    for y=1:cols</pre><pre>        if curr_index &lt;= bit_total</pre><pre>        val=str2double(message_str(curr_index));</pre><pre>        if bitget(cd(x,y),1)~=val</pre><pre>            c2=bitget(cd(x,y),2);</pre><pre>            c3=bitget(cd(x,y),3);</pre><pre>            c4=bitget(cd(x,y),4);</pre><pre>            c5=bitget(cd(x,y),5);</pre><pre>            c6=bitget(cd(x,y),6);</pre><pre>            c7=bitget(cd(x,y),7);</pre><pre>            c8=bitget(cd(x,y),8);</pre><pre>   Hidden_img(x,y)=(128*c8+64*c7+32*c6+16*c5+8*c4+4*c3+2*c2+val);</pre><pre>        curr_index=curr_index+1;</pre><pre>         else<br>           Hidden_img(x,y)=cd(x,y);</pre><pre>         end</pre><pre>   end</pre><pre> end</pre><pre>end</pre><pre>imshow(Hidden_img);title(&#39;output_image&#39;);<br>imwrite(Hidden_img,&#39;output.png&#39;);</pre><p>What this encryption code does is that it creates an output image which is very much similar to the input image.</p><p>To convert the textual input to the binary stream in the above code we first use ‘uint8&#39; to convert the texts to integers. After that, we use ‘dec2binary’ to convert those integers to binary form and then append them to a message_str.</p><p>The bit plane 1 of the input image changes, such that, if the value at that position(bit plane 1) is not what we require then we change its value, but since our input stream(which is converted to binary form from textual input), is only of bits there is roughly 50% chance that we would be changing the bit plane for this pixel. Thus, the images will be very hard to distinguish.</p><p>Now that we have an output image in which our coded message is embedded its time to decrypt the message.</p><p>We use the decryption code which is -</p><pre>clc;<br>clear variables;</pre><pre>len=str2double(input(&#39;Enter the length (character count) of the message you are looking for: &#39;,&#39;s&#39;));</pre><pre>len = len*8;</pre><pre>image_hide = imread(&#39;output.png&#39;);</pre><pre>[rows,columns,channels] = size(image_hide);</pre><pre>if channels &gt; 1</pre><pre>    image_hide = rgb2gray(image_hide);</pre><pre>end</pre><pre>count=1;</pre><pre>bitseq=&#39;&#39;;</pre><pre>for i=1:rows</pre><pre>  for j=1:columns</pre><pre>    %For all the characters in the message</pre><pre>    if count&lt;=len</pre><pre>    %Retrieve the LSB of the intensity level of the pixel</pre><pre>     LSB=mod(image_hide(i,j),2);</pre><pre>    bitseq(count,1) = LSB;</pre><pre>  count=count+1;</pre><pre>  end</pre><pre> end</pre><pre>end</pre><pre>%Converting the bit sequence into the original message</pre><pre> weights = [ 128 64 32 16 8 4 2 1 ];</pre><pre>% elements are taken column wise from bitseq, each char has 8 bits <br>% so 8 rows</pre><pre>message_matrix = reshape(bitseq,8,len/8);</pre><pre>original_message = char(weights*message_matrix);</pre><pre>disp([&#39;The original message is: &#39;,original_message]);</pre><p>The decryption code takes the “encrypted image” as input and prompts the user to tell how many characters are there in the message. after that, it makes a string of all the bits in the bit plane-1 of the image till the total-bit-count of the message is reached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JMZF3yHQDshfX0o1MMsqzA.png" /><figcaption>Encrypting the message ‘Nikhil Vyas’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPL9g2dznq2-8b-wb0-wEg.png" /><figcaption>Decrypting the message</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce2c02b2163a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>