<?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 Rohit Jindal on Medium]]></title>
        <description><![CDATA[Stories by Rohit Jindal on Medium]]></description>
        <link>https://medium.com/@jindal.rohit540?source=rss-a460d0861c79------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*772K7w33iKKOLqn3xG8W0Q.jpeg</url>
            <title>Stories by Rohit Jindal on Medium</title>
            <link>https://medium.com/@jindal.rohit540?source=rss-a460d0861c79------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:05:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jindal.rohit540/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[Unlocking the Power of Python: Mastering Advanced Modules for Efficient Programming]]></title>
            <link>https://medium.com/@jindal.rohit540/unlocking-the-power-of-python-mastering-advanced-modules-for-efficient-programming-dc62da5f4342?source=rss-a460d0861c79------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc62da5f4342</guid>
            <dc:creator><![CDATA[Rohit Jindal]]></dc:creator>
            <pubDate>Sat, 16 Sep 2023 09:12:46 GMT</pubDate>
            <atom:updated>2023-09-16T09:12:46.528Z</atom:updated>
            <content:encoded><![CDATA[<p>Python is a versatile programming language that offers a wide range of modules to simplify complex tasks. In this article, we will explore three advanced Python modules: Collections, DateTime, and OS.</p><ol><li>Collections Module: The Collections module provides specialized data structures that are beyond the built-in data types like lists, tuples, and dictionaries. It offers additional container types such as named tuples, default dictionaries, and counters.</li></ol><p>a. Named Tuples: Named tuples are similar to regular tuples, but with named fields. They provide a convenient way to define lightweight data structures. Let’s see an example:</p><pre>from collections import namedtuple<br><br># Define a named tuple<br>Person = namedtuple(&#39;Person&#39;, [&#39;name&#39;, &#39;age&#39;, &#39;city&#39;])<br><br># Create an instance of the named tuple<br>person1 = Person(&#39;John&#39;, 25, &#39;New York&#39;)<br><br># Accessing named tuple fields<br>print(person1.name)  # Output: John<br>print(person1.age)   # Output: 25<br>print(person1.city)  # Output: New York</pre><p>b. Default Dictionaries: Default dictionaries are dictionaries with a default value assigned to keys that do not exist. This eliminates the need for explicit key checking. Here’s an example:</p><pre>from collections import defaultdict<br><br># Create a default dictionary with a default value of 0<br>fruit_counts = defaultdict(int)<br><br># Increment the count of each fruit<br>fruit_counts[&#39;apple&#39;] += 1<br>fruit_counts[&#39;banana&#39;] += 1<br>fruit_counts[&#39;apple&#39;] += 1<br><br>print(fruit_counts)  # Output: defaultdict(&lt;class &#39;int&#39;&gt;, {&#39;apple&#39;: 2, &#39;banana&#39;: 1})</pre><p>c. Counters: Counters are used to count the occurrences of elements in a collection. They are a subclass of dictionaries. Let’s see an example:</p><pre>from collections import Counter<br><br># Create a counter<br>fruits = [&#39;apple&#39;, &#39;banana&#39;, &#39;apple&#39;, &#39;orange&#39;, &#39;banana&#39;, &#39;apple&#39;]<br>fruit_counter = Counter(fruits)<br><br># Count the occurrences of each fruit<br>print(fruit_counter)  # Output: Counter({&#39;apple&#39;: 3, &#39;banana&#39;: 2, &#39;orange&#39;: 1})</pre><p>2. DateTime Module: The DateTime module provides classes for working with dates, times, and time intervals. It offers various functionalities like creating, manipulating, and formatting dates and times.</p><p>Here’s a simple example that demonstrates the usage of the DateTime module:</p><pre>from datetime import datetime<br><br># Get the current date and time<br>current_datetime = datetime.now()<br><br># Format the date and time<br>formatted_datetime = current_datetime.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)<br><br>print(formatted_datetime)  # Output: 2023-09-16 15:30:00<br><br>-------------------------------------------------------------------<br># Lets look at real life examples<br><br><br># Get the user&#39;s birthdate as input<br>birthdate = input(&quot;Enter your birthdate (YYYY-MM-DD): &quot;)<br><br># Convert the input string to a datetime object<br>birthdate = datetime.strptime(birthdate, &quot;%Y-%m-%d&quot;)<br><br># Calculate the age<br>current_date = datetime.now()<br>age = current_date.year - birthdate.year<br><br># Output the age<br>print(&quot;Your age is:&quot;, age)<br><br>---------------------------------------------------------------------<br><br>## Event Countdown<br><br>from datetime import datetime<br><br># Get the event date as input<br>event_date = input(&quot;Enter the event date (YYYY-MM-DD): &quot;)<br><br># Convert the input string to a datetime object<br>event_date = datetime.strptime(event_date, &quot;%Y-%m-%d&quot;)<br><br># Calculate the remaining days until the event<br>current_date = datetime.now()<br>remaining_days = (event_date - current_date).days<br><br># Output the countdown<br>print(&quot;Days until the event:&quot;, remaining_days)<br><br>-----------------------------------------------------------------------<br><br>from datetime import datetime<br><br># Get the date as input<br>date_string = input(&quot;Enter a date (YYYY-MM-DD): &quot;)<br><br># Convert the input string to a datetime object<br>date = datetime.strptime(date_string, &quot;%Y-%m-%d&quot;)<br><br># Format the date as &quot;Month Day, Year&quot;<br>formatted_date = date.strftime(&quot;%B %d, %Y&quot;)<br><br># Output the formatted date<br>print(&quot;Formatted date:&quot;, formatted_date)</pre><ol><li>OS Module: The OS module provides a way to interact with the operating system. It allows you to perform various operations like file and directory manipulation, process management, and environment variables handling.</li></ol><p>Let’s see an example that showcases the OS module’s capabilities:</p><pre>import os<br><br># Get the current working directory<br>current_directory = os.getcwd()<br><br># List all files and directories in the current directory<br>files_and_directories = os.listdir(current_directory)<br><br>print(files_and_directories)  # Output: [&#39;file1.txt&#39;, &#39;file2.py&#39;, &#39;directory1&#39;, &#39;directory2&#39;]</pre><p>📢 Exciting News! 📢</p><p>Are you hungry for more captivating articles and valuable insights? Look no further!</p><p>Follow me on</p><blockquote><a href="https://www.instagram.com/jindalrohit540/">Instagram</a></blockquote><p>— — — — — — — — — — — — —</p><blockquote><a href="https://www.linkedin.com/in/jindal-rohit540/">LinkedIn</a></blockquote><p>to stay connected and be the first to know about my latest thought-provoking Medium articles. 🚀🔥</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc62da5f4342" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplified : Packages & Modules & __init__ file in Python]]></title>
            <link>https://medium.com/@jindal.rohit540/simplified-packages-modules-init-file-in-python-6f8b5edebd53?source=rss-a460d0861c79------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f8b5edebd53</guid>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rohit Jindal]]></dc:creator>
            <pubDate>Sat, 16 Sep 2023 07:03:26 GMT</pubDate>
            <atom:updated>2023-09-16T07:03:26.358Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Simplified : Packages &amp; Modules &amp; __init__ file in Python</strong></h3><ol><li>Packages: Packages are folders that contain multiple modules and sub-packages. They provide a way to organize and group related modules together. Packages help in organizing larger projects by creating a hierarchical structure. A package must have an __init__.py file to be recognized as a package.</li><li>Modules: Modules are individual Python files that contain code. They can include functions, classes, and variables. Modules are used to organize and reuse code within a single file. You can think of a module as a container for related code</li></ol><p>In summary, modules are individual Python files that contain code, while packages are folders that contain multiple modules and sub-packages. They help in organizing and reusing code, making it easier to manage and maintain larger projects.</p><h4><strong>LET US LOOK AT EXAMPLES</strong></h4><ol><li><strong>PACKAGE EXAMPLE</strong></li></ol><p>Below, <em>mypackage </em>is a package that contains two modules (module1.py and module2.py) and a sub-package called subpackage.</p><p>The subpackage contains a module called module3.py. The __init__.py files indicate that both the package and sub-package are recognized as such. There has to be an __init__.py file in a package</p><pre>mypackage/<br> ├── __init__.py<br> ├── module1.py<br> ├── module2.py<br> └── subpackage/<br> ├── __init__.py<br> └── module3.py</pre><p>2. <strong>MODULE EXAMPLE</strong></p><ul><li>Module Name: <em>math_operations.py</em> — which can be one of the modules in any package, may looks like this.</li><li>Module is a code — which has functions that do the task, and returns a value.</li></ul><p>In this example, math_operations.py is a module that contains functions for basic mathematical operations. It can be used in other Python scripts by importing the module and calling its function</p><pre>     def add(a, b):<br>         return a + b<br><br>     def subtract(a, b):<br>         return a - b<br><br>     def multiply(a, b):<br>         return a * b<br><br>     def divide(a, b):<br>         return a / b</pre><h4><strong>The __init__.py file in a package</strong></h4><ol><li>Package Indicator: The presence of an __init__.py file in a folder indicates that the folder is a package. Without this file, Python would not recognize the folder as a package and you wouldn’t be able to import modules or sub-packages from it.</li><li>Initialization Code: The __init__.py file can contain initialization code that is executed when the package is imported. This code can set up any necessary configurations or perform any required tasks before the package is ready to be used. For example, it can define variables, import modules, or execute specific functions.</li><li>Namespace Definition: The __init__.py file can define what symbols (functions, classes, variables) are available when the package is imported. This allows you to control what gets exposed to the outside world when the package is used. By explicitly listing the symbols in the __init__.py file, you can provide a clean and organized interface for users of your package.</li></ol><p>Overall, the __init__.py file is essential for packages in Python. It marks the folder as a package, allows for initialization code, and defines the package’s namespace. It helps in organizing and structuring code within packages and provides a way to control the behavior and visibility of the package’s contents.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f8b5edebd53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meta (Facebook) Machine Learning Interview Question: Illegal Items Detection]]></title>
            <link>https://medium.com/@jindal.rohit540/meta-facebook-machine-learning-interview-question-illegal-items-detection-1088fae7417?source=rss-a460d0861c79------2</link>
            <guid isPermaLink="false">https://medium.com/p/1088fae7417</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[metaverse]]></category>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Rohit Jindal]]></dc:creator>
            <pubDate>Fri, 24 Mar 2023 18:14:17 GMT</pubDate>
            <atom:updated>2023-03-24T20:08:05.844Z</atom:updated>
            <content:encoded><![CDATA[<h3>Meta (Facebook) ML Interview Question Case Study: Illegal Items Detection</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EczWjAG-mQCgilNr" /><figcaption>Photo by <a href="https://unsplash.com/@ahskeed?utm_source=medium&amp;utm_medium=referral">Deeksha Pahariya</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><blockquote>This is like in a real interview setting :-<br>Also, Read till the end for the concise take home summary and game changing points.</blockquote><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><h4>Question :Facebook has a marketplace already. The website’s Terms of Service restrict the sale of guns (not to mention the laws of your country).</h4><h4>To achieve this, you should develop a system that can quickly determine whether a listing on a marketplace is offering to sell a firearm.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g1UZzQU4Ghj_6dE1" /></figure><p>How would you approach completing this?</p><h4>What exactly is the interviewer seeking?</h4><p>Here, the interviewer is searching for a few things</p><ol><li>Can you accurately define the project’s size?</li><li>Can machine learning be used to achieve a business objective?</li><li>Are you capable of creating a machine-learning system from the bottom up?</li></ol><p>Asking Clarifying Questions</p><p><strong>Clarifying the first query Here</strong>,</p><p>I have a few questions.</p><p>I’m curious about a few things here. One thing I’m wondering about is, <strong>how is this working in production.</strong> The task is to automatically identify the listings. What happens with those identifications? <strong>Do they go to a human who checks it or it immediately changes the website?</strong></p><p>Interviewer’s Reply</p><p>Let’s assume that the current system relies entirely on crowdsourcing. If a user sees that a listing contains a gun, they can flag it, and that information is sent to customer service, who can subsequently take the listing down. If they find a gun, that is the only action that can be taken at this time.</p><p><strong>Question 2 </strong>: How would this fit in? Is customer service always going to be at the other end of the line?</p><p>Interviewer’s Reply</p><p>I can ask the same question of you in a new way.</p><p>If this system is now in place, do you believe that the objective should be to disable it (the marketplace post) while they are posting, or do you believe that we should be detecting it later and then forwarding it to customer support?</p><p>Interviewee — ( How the metric of False Positive is so important , depending on the problem statement)</p><p>I was asking that question because if customer service is going to review it later — which would probably be the preferable place to start — then I need to be very adept at finding all the potential listings for firearms.</p><p>It’s horrible if I overlook something that’s a gun because customer service won’t check it. Giving false positives — listings that aren’t guns — might incur some expense, but it’ll probably be okay if I do so and let customer support handle the situation. But if you miss the listing, you can be in violation of your terms of service or the laws of your nation, which makes this pipeline very expensive.</p><p>We want the customer service to receive all relevant information so they can make a decision. However, if prices are an issue, false positives might be a concern.</p><h4>Interviewer’s</h4><p>Let’s consider a presumption of what is acceptable. It’s probably a good thing if someone uploads a gun, it’s added to the marketplace, and it’s taken off within an hour. In such case, there probably wouldn’t be much time for someone to go after the seller and attempt to buy the pistol.</p><p>The worst-case scenario is that we become inundated with a tonne of other products being offered for sale that are not firearms, at which point users receive the standard notification “your posting was reported until it’s reviewed by customer support.” Sellers’ perceptions of this market have suddenly changed. Even listing my plants here is impossible because they will be blocked. What is the best course of action when considering the several possibilities here? What would you want to accomplish if you were Facebook in this situation?</p><h4>Interviewee</h4><p>Depends on what happens with the model at the end. There are different scenarios we’ve laid out. One scenario is that you don’t want to miss anything, in that case, false negatives are important. In other cases which is if it ends up being a sticker, that’s posted because the model identifies it, but it’s not there and then it can lead to a lot of issues. If we’re concerned with both those scenarios, then we want to minimize both false positives and false negatives. We can use <strong>metrics like the F1 score to minimize that</strong>.<strong> F1 score is a combination of precision and recall,</strong> and precision is where you’re concerned.</p><p>You make a bunch of predictions and how many of them are right? The recall is the case where you make a bunch of predictions. How many of the real case scenarios do you get? How much stuff do you miss? And that seems pertinent here because the number of guns is probably going to be very small, I’m assuming the actual number of gun posts is maybe even less than 1% in a Facebook marketplace.</p><h4>Interviewee</h4><p>Measures like recall and precision ignore things that are obvious and predominate in favour of focusing only on the positive outcomes of listing with guns. The models we select will also take the imbalance issue into account. What kind of scale, scope, and data we may have is the second issue.</p><p>At the very least when it is deployed, the model doesn’t need to be that quick. We would then have access to other postings where items have been highlighted by customer service based on the historical data. We have access to a sizable data set that enables us to identify postings and determine whether or not they involve firearms.</p><h4>Interviewer</h4><p>Yes. I believe we can determine whether there were firearms since there is usually a process where the item’s actual value is flagged, and then there is likely also a categorization of why it was flagged. In this case, customer service is probably labelling the items as firearms in that category.</p><h4>Interviewee</h4><p>We also don’t have many worries regarding model training time because it’s crucial to have an accurate model for detecting these insignificant instances of gun posts. With that in mind, as well as the fact that we already have this enormous data set, accuracy is something we’re worried about. We might want to add something to the data in terms of data gathering, characteristics, and the model.</p><p>I have flags that users could have left. I have information about the specific individual who uploaded it, including demographics, geography, and whether or not more guns are sold in some areas of the nation.</p><p>The crucial component in this situation appears to be the language contained in the data and the ability to use that data to identify keywords or word patterns. These functionalities are available, along with user data flags, context, information, and text. Let’s concentrate on the text itself and how we may use it as our model. Starting with a simpler model is preferable, and that model might resemble a bag of words.</p><h4>Interviewer</h4><p>Let’s say that we have access to all of Facebook’s data.</p><h4>Interviewee</h4><p>We can utilize this other baseline where we apply the most basic text analysis method because we have some baseline data on how their current process functions. Theoretically, we could utilize more intricate models like context-sensitive attention-based transformers. But for now, I’ll just concentrate on the more straightforward model and go through it. If we already have the text data, we may extract the bag of words, which gives us each text body. We receive a list of the text’s unique words along with their word counts.</p><p>The TFIDF method is another option, in which each word’s value is scaled according on how frequently it appears in other postings. This is useful because you might anticipate seeing posts about guns. Before even running the model, we often use specific words that are not present in other postings. For instance, I may be assisting my model by choosing words that are specific to particular listings. This will give more weight to those words because the bag of words can contain millions and millions of words. Hence, it is a very large sparse matrix. You might want to make further cuts occasionally. If you want to decrease that to 500 dimensions, you could use a PCA.</p><p>This entire procedure serves the purpose of embedding the text in some space. The concept is to plot places in space that have comparable meanings. We can always use more advanced alternatives in its place. The imbalance sample is the one we want to use to develop the model. A tree-based model, especially a gradient boosted tree, would be a good place to start for our prototype because each tree in these models is capable of making a prediction.</p><p>In this instance, it uses all of our features to determine whether or not a gun posting is there. Next it scales the data points with the greatest amount of inaccuracy. These incorrect data points are therefore given higher weights for the following tree. It will increase the weight of the minority sample points, which are the few listings for weapons. If these listings continue to cause errors in the model, their weight will increase and they will become more crucial to the prediction. A gradient-boosted tree would therefore be a suitable place to start. The gradient-boosted trees might not be the best choice for online training, but we could test other models.</p><h4>Interviewer</h4><p>I believe the main distinction between online and offline training is that the former occurs as the model is being used and undergoes continuous development.</p><h4>Interviewee</h4><p>Yes, however, in this instance, we probably want to update the model frequently. The gradient-boosted trees in this scenario offer predictions quickly after being trained. We could simply retrain the entire model, but depending on the package you pick, this tree-based technique won’t be particularly effective if, for some reason, customer support requests that you update the model frequently. You might want to employ different strategies, such as a neural network, to enable this online training.</p><p>There aren’t many gun posts around. One thing I should have stated earlier is that balancing the sample is one approach to cope with that. We could have also balanced the two samples if we had more data. We could have simply obtained a matched sample of the equivalent other samples using the number of gun postings we now have, but let’s imagine there aren’t enough postings to make that match. The accuracy won’t be very high then. Hence, as I mentioned, we may combine precision and recall to create the F1 score, which only has a range of 0 to 1.</p><p>This can reveal how accurate the model is at forecasting such gun purchases. We most likely would train the model using our historical data as it is being created. In due time, we would be collecting some data samples. It is our training sample, and the test set is something from later in time. This would likely reflect how things work in real-world settings, where our model is trained on a piece of data from a specific point in time and is used to forecast data from the future. We should think about how often we want to create this model and how long this forecast will hold true because, as with everything on the internet, people are getting better and better at doing these things. To deal with these creative folks, we might want to adapt the model.</p><h4>Interviewer</h4><p>Yeah. The traditional NLP task of detecting bullets or guns for sale turns into code names, so we still have to reuse that for manual tagging. That’s a good question because I believe that as people become aware that their posts are being flagged and that they are dealing with very malicious actors who are active in their campaign to sell guns on the internet, one of the aspects is that they start creatively disguising their posts. Let’s assume that we wish to learn more about computer vision. How would you evaluate the potential need for using photos in your analysis as opposed to just text alone and the fact that images are probably more difficult to train? Having knowledge and graphics is certainly much more challenging than just words, which is much easier to use with Python’s fantastic packages. How would you respond in the circumstance? How would you decide whether using the basic model is preferable to performing the image analysis into the features?</p><h4>Interviewee</h4><p>Yeah. Hence, I suppose the question is: What added value do the photographs provide, and is it worthwhile to convey all that?</p><p>Yes. I believe it’s a very straightforward strategy you could employ; all the features are present, and the prediction follows. What is the forecast precision of the complete model? Say, for example, that 90% of the model is complete. The accuracy is then reduced to 60% after you remove the text data from the model and see that when the photos are removed, the accuracy increases to 85%. You can therefore know that, yeah. The graphics do take away from the text, which is really significant. Hence, you’re thinking, “Well, well, you informed me now that accuracy does reduce when you drop the photos, but is it a meaningful drop?”</p><p>Because we have enough data, I believe one thing you could do is just simulate it by randomly picking the data. As a result, you might take a random sample from the data, retrain the model each time, and observe the accuracy reduction that occurs when the images are removed. So, I may claim that 95% of the time, the accuracy decrease is more than zero. It’s a negative drop, so I may then say, “Well, images are crucial” since practically every time I’ve tested it, there has been a loss in accuracy when simulating across numerous samples.</p><h4>Interviewer</h4><p>Yeah. That is reasonable. The last question is more about the question itself, sort of. What are your thoughts on this query? How do you feel your response would fit into a larger Facebook interview, such as how well do you think it evaluates a candidate’s performance just generally?</p><h4>Interviewee</h4><p>I’m unsure of the scope of the Facebook interview, but this question sounds quite typical, it’s highly machine learning, and it tests your familiarity with minorities. When you are predicting a relatively small number of events, you must sort of build the model from beginning to end. Something like this, where you have to identify something from a specific listing or post, seems like a reasonably typical issue you might have.</p><h4>Interviewer</h4><p>Indeed, I appreciated your response and the way you organized things. The majority of machine learning-related questions, in my opinion, have a very clear beginning, middle, and end in terms of the location of the data, the method for developing the model, and the method for deploying and assessing it. I believe concentrating on those methods is essential. As a result, I believe you did a terrific job.</p><h3>Take Home Summary from this Case Study</h3><blockquote>The interviewer is seeking to evaluate the interviewee’s ability to define the project’s scope, develop a machine learning system from scratch, and identify whether machine learning can be used to achieve a business objective.</blockquote><blockquote>The interviewee suggests a four-step framework to approach the problem, starting with clarifying the machine learning problem assumptions and making the scope. They discuss the importance of accuracy and avoiding false negatives, but also mention the concern of incurring costs if there are too many false positives.</blockquote><blockquote>The interviewer sets some assumptions for the machine learning model, including the acceptable timeframe for removing gun listings and the potential issues of blocking non-gun listings. They also mention using historical data and customer service labelling to train the model.</blockquote><blockquote>Overall, the interviewee demonstrates knowledge of machine learning principles and approaches the problem thoughtfully, considering various scenarios and possible solutions.</blockquote><h3><strong><em>By Rohit Jindal , Sr Data Scientist at Target</em></strong></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1088fae7417" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The p value paradox in Linear Regression. Why we need F Statistic in Multiple Linear Regression]]></title>
            <link>https://medium.com/@jindal.rohit540/the-p-value-paradox-in-linear-regression-why-we-need-f-statistic-in-multiple-linear-regression-e8d2ef7781f7?source=rss-a460d0861c79------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8d2ef7781f7</guid>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Rohit Jindal]]></dc:creator>
            <pubDate>Thu, 23 Mar 2023 13:07:25 GMT</pubDate>
            <atom:updated>2023-03-23T13:07:25.807Z</atom:updated>
            <content:encoded><![CDATA[<p>When running a multiple linear regression model:</p><p>Y = β0 + β1X1 + β2X2 + β3X3 + β4X4 + … + ε</p><p><strong><em>The F-statistic provides us with a way for globally testing if ANY of the independent variables X1, X2, X3, X4… is related to the outcome Y.</em></strong></p><p>For a significance level of 0.05:</p><ul><li><strong>If the p-value associated with the F-statistic is ≥ 0.05:</strong> Then there is no relationship between ANY of the independent variables and Y</li><li><strong>If the p-value associated with the F-statistic &lt; 0.05:</strong> Then, AT LEAST 1 independent variable is related to Y</li></ul><h4>Let us see two special cases :</h4><h3>Why do we even need the F-test?</h3><p>Why do we need a global test? Why not look at the p-values associated with each coefficient β1, β2, β3, β4… to determine if any of the predictors is related to Y?</p><p>Before we answer this question, let’s first look at an example:</p><p>In the image below we see the output of a linear regression in R.</p><p>Notice that the coefficient of X3 has a p-value &lt; 0.05 which means that X3 is a statistically significant predictor of Y:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/0*a_zQAYchUDLUnI2m.png" /></figure><p>However, the last line shows that the F-statistic is 1.381 and has a p-value of 0.2464 (&gt; 0.05) which suggests that NONE of the independent variables in the model is significantly related to Y!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/0*g4gghiUi1QnOzBki.png" /></figure><p>So is there something wrong with our model? If not, then which p-value should we trust: that of the coefficient of X3 or that of the F-statistic?</p><p>The answer is that we cannot decide on the global significance of the linear regression model based on the p-values of the β coefficients.</p><p>This is because each coefficient’s p-value comes from a separate statistical test that has a 5% chance of being a false positive result (assuming a significance level of 0.05).</p><p>For instance, if we take the example above, we have 4 independent variables (X1 through X4) and each of them has a 5% risk of yielding a p-value &lt; 0.05 just by chance (when in reality they’re not related to Y).</p><p>The more variables we have in our model, the more likely it will be to have a p-value &lt; 0.05 just by chance.</p><p>Here’s a plot that shows the probability of having AT LEAST 1 variable with p-value &lt; 0.05 when in reality none has a true effect on Y:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZK_wGBUHOXWeeM8i.png" /></figure><p>In the plot we see that a model with 4 independent variables has a 18.5% chance of having at least 1 β with p-value &lt; 0.05.</p><p>The plot also shows that a model with more than 80 variables will almost certainly have 1 p-value &lt; 0.05.</p><p>Therefore it is obvious that we need another way to determine if our linear regression model is useful or not (i.e. if at least one of the Xi variables was important in predicting Y).</p><p>Here’s where the F-statistic comes into play.</p><p>One important characteristic of the F-statistic is that it adjusts for the number of independent variables in the model. So it will not be biased when we have more than 1 variable in the model.</p><p>Returning to our example above, the p-value associated with the F-statistic is ≥ 0.05, which provides evidence that the model containing X1, X2, X3, X4 is not more useful than a model containing only the intercept β0.</p><p>BOTTOM LINE:</p><p>In this example, according to the F-statistic, none of the independent variables were useful in predicting the outcome Y, even though the p-value for X3 was &lt; 0.05.</p><h3>What if the F-statistic has a statistically significant p-value but none of the coefficients does?</h3><p>Here’s the output of another example of a linear regression model where none of the independent variables is statistically significant but the overall model is (i.e. at least one of the variables is related to the outcome Y) according to the p-value associated with the F-statistic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/0*wvJQyJx6ImQfXYD3.png" /></figure><p>But how is that even possible?</p><p>Well, in this particular example I deliberately chose to include in the model 2 correlated variables: X1 and X2 (with correlation coefficient of 0.5).</p><p>Because this correlation is present, the effect of each of them was diluted and therefore their p-values were ≥ 0.05, when in reality they both are related to the outcome Y.</p><p>CONCLUSION:</p><p>When it comes to the overall significance of the linear regression model, always trust the statistical significance of the F-statistic over that of each independent variable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8d2ef7781f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[80 % of all applied SQL + Technical Interview’s favorite Topics in one article]]></title>
            <link>https://medium.com/@jindal.rohit540/80-of-all-applied-sql-technical-interviews-favorite-topics-in-one-article-4bf80ddba0a7?source=rss-a460d0861c79------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bf80ddba0a7</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[aı]]></category>
            <category><![CDATA[job-interview]]></category>
            <dc:creator><![CDATA[Rohit Jindal]]></dc:creator>
            <pubDate>Thu, 23 Mar 2023 09:00:46 GMT</pubDate>
            <atom:updated>2023-03-23T09:01:45.260Z</atom:updated>
            <content:encoded><![CDATA[<h3>80 % of all applied SQL + SQL technical interview’s favorite topics in one article</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BaTUk9yvDZg-Dopx" /><figcaption>Photo by <a href="https://unsplash.com/@sunder_2k25?utm_source=medium&amp;utm_medium=referral">Sunder Muthukumaran</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Q. WHAT IS WINDOW FUNCTION ?</h3><p>A <em>window function</em> performs a calculation across a set of table rows that are somehow related to the current row. This is comparable to the type of calculation that can be done with an aggregate function. But unlike regular aggregate functions, use of a window function does not cause rows to become grouped into a single output row — the rows retain their separate identities. Behind the scenes, the window function is able to access more than just the current row of the query result.</p><pre>SELECT duration_seconds,<br>       SUM(duration_seconds) OVER (ORDER BY start_time) AS running_total<br>  FROM tutorial.dc_bikeshare_q1_2012</pre><p>You can see that the above query creates an aggregation (running_total) without using GROUP BY. Let&#39;s break down the syntax and see how it works.</p><h3>Basic windowing syntax</h3><p>The first part of the above aggregation, <em>SUM(duration_seconds)</em>, looks a lot like any other aggregation. Adding <em>OVER</em> designates it as a window function. You could read the above aggregation as &quot;take the sum of duration_seconds <em>over</em> the entire result set, in order by start_time.&quot;</p><p>If you’d like to narrow the window from the entire dataset to individual groups within the dataset, you can use <strong><em>PARTITION BY</em></strong> to do so:</p><pre>SELECT start_terminal,<br>       duration_seconds,<br>       SUM(duration_seconds) OVER<br>         (PARTITION BY start_terminal ORDER BY start_time)<br>         AS running_total<br>  FROM tutorial.dc_bikeshare_q1_2012<br> WHERE start_time &lt; &#39;2012-01-08&#39;</pre><p>The above query groups and orders the query by start_terminal. Within each value of start_terminal, it is ordered by start_time, and the running total sums across the current row and all previous rows of duration_seconds. Scroll down until the start_terminal value changes and you will notice that running_total starts over. That&#39;s what happens when you group using PARTITION BY. In case you&#39;re still stumped by ORDER BY, it simply orders by the designated column(s) the same way the ORDER BY clause would, except that it treats every partition as separate. It also creates the running total—without ORDER BY, each value will simply be a sum of all the duration_seconds values in its respective start_terminal. Try running the above query without ORDER BY to get an idea:</p><pre>SELECT start_terminal,<br>       duration_seconds,<br>       SUM(duration_seconds) OVER<br>         (PARTITION BY start_terminal) AS start_terminal_total<br>  FROM tutorial.dc_bikeshare_q1_2012<br> WHERE start_time &lt; &#39;2012-01-08&#39;</pre><p>The ORDER and PARTITION define what is referred to as the &quot;window&quot;—the ordered subset of data over which calculations are made.</p><p>Note: You can’t use window functions and standard aggregations in the same query. More specifically, you can’t include window functions in a GROUP BY clause.</p><h3># The Most common windows function used in real life</h3><h3>RANK() and DENSE_RANK()</h3><p>RANK() is slightly different from ROW_NUMBER(). If you order by start_time, for example, it might be the case that some terminals have rides with two identical start times. In this case, they are given the same rank, whereas ROW_NUMBER() gives them different numbers. In the following query, you notice the 4th and 5th observations for start_terminal 31000—they are both given a rank of 4, and the following result receives a rank of 6:</p><pre>SELECT start_terminal,<br>       duration_seconds,<br>       RANK() OVER (PARTITION BY start_terminal<br>                    ORDER BY start_time)<br>              AS rank<br>  FROM tutorial.dc_bikeshare_q1_2012<br> WHERE start_time &lt; &#39;2012-01-08&#39;<br></pre><p>You can also use DENSE_RANK() instead of RANK() depending on your application. Imagine a situation in which three entries have the same value. Using either command, they will all get the same rank. For the sake of this example, let&#39;s say it&#39;s &quot;2.&quot; Here&#39;s how the two commands would evaluate the next results differently:</p><ul><li>RANK() would give the identical rows a rank of 2, then skip ranks 3 and 4, so the next result would be 5</li><li>DENSE_RANK() would still give all the identical rows a rank of 2, but the following row would be 3—no ranks would be skipped.</li></ul><h3>LAG and LEAD</h3><p>It can often be useful to compare rows to preceding or following rows, especially if you’ve got the data in an order that makes sense. You can use LAG or LEAD to create columns that pull values from other rows—all you need to do is enter which column to pull from and how many rows away you&#39;d like to do the pull. LAG pulls from previous rows and LEAD pulls from following rows:</p><pre>SELECT start_terminal,<br>       duration_seconds,<br>       LAG(duration_seconds, 1) OVER<br>         (PARTITION BY start_terminal ORDER BY duration_seconds) AS lag,<br>       LEAD(duration_seconds, 1) OVER<br>         (PARTITION BY start_terminal ORDER BY duration_seconds) AS lead<br>  FROM tutorial.dc_bikeshare_q1_2012<br> WHERE start_time &lt; &#39;2012-01-08&#39;<br> ORDER BY start_terminal, duration_seconds</pre><p>This is especially useful if you want to calculate differences between rows:</p><pre>SELECT start_terminal,<br>       duration_seconds,<br>       duration_seconds -LAG(duration_seconds, 1) OVER<br>         (PARTITION BY start_terminal ORDER BY duration_seconds)<br>         AS difference<br>  FROM tutorial.dc_bikeshare_q1_2012<br> WHERE start_time &lt; &#39;2012-01-08&#39;<br> ORDER BY start_terminal, duration_seconds</pre><p>The first row of the difference column is null because there is no previous row from which to pull. Similarly, using LEAD will create nulls at the end of the dataset. If you&#39;d like to make the results a bit cleaner, you can wrap it in an outer query to remove nulls:</p><pre>SELECT *<br>  FROM (<br>    SELECT start_terminal,<br>           duration_seconds,<br>           duration_seconds -LAG(duration_seconds, 1) OVER<br>             (PARTITION BY start_terminal ORDER BY duration_seconds)<br>             AS difference<br>      FROM tutorial.dc_bikeshare_q1_2012<br>     WHERE start_time &lt; &#39;2012-01-08&#39;<br>     ORDER BY start_terminal, duration_seconds<br>       ) sub<br> WHERE sub.difference IS NOT NULL</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bf80ddba0a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>