<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aayush Sinha</title>
    <description>The latest articles on DEV Community by Aayush Sinha (@aayushs7ha).</description>
    <link>https://dev.to/aayushs7ha</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1087468%2Fb5253929-79e3-43a2-816a-2409887d9587.jpeg</url>
      <title>DEV Community: Aayush Sinha</title>
      <link>https://dev.to/aayushs7ha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aayushs7ha"/>
    <language>en</language>
    <item>
      <title>Simple &gt; Machine Learning Prediction</title>
      <dc:creator>Aayush Sinha</dc:creator>
      <pubDate>Tue, 13 Feb 2024 09:13:10 +0000</pubDate>
      <link>https://dev.to/aayushs7ha/simple-machine-learning-prediction-2lbj</link>
      <guid>https://dev.to/aayushs7ha/simple-machine-learning-prediction-2lbj</guid>
      <description>&lt;h2&gt;
  
  
  Selecting the prediction target
&lt;/h2&gt;

&lt;p&gt;You can pull out a target feature/variable with a df.&lt;br&gt;
This single column is stored as a series which boradly is a dataframe with one single column.&lt;br&gt;
for instance : &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;y = df.price&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Choosing features
&lt;/h2&gt;

&lt;p&gt;The features/columns that are inputted into a model (and later used to make predictions. The columns that will be used to predict the price. Sometimes, you will use all columns except the target as features. Other times you'll be better off with fewer features. By convention this is called 'X'. &lt;br&gt;
for instance: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;melbourne_features = ['Rooms', 'Bathroom', 'Landsize', 'Lattitude', 'Longtitude']&lt;br&gt;
X = melbourne_data[melbourne_features]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4c2npm5a8vkuv0kfh1zt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4c2npm5a8vkuv0kfh1zt.png" alt="Image description" width="745" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftf9472vc4tc96uvxq7wd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftf9472vc4tc96uvxq7wd.png" alt="Image description" width="504" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building your model
&lt;/h2&gt;

&lt;p&gt;You will use the scikit-learn library to create your models. When coding, this library is written as sklearn, as you will see in the sample code. Scikit-learn is easily the most popular library for modeling the types of data typically stored in DataFrames.&lt;/p&gt;

&lt;p&gt;The steps to building and using a model are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define: What type of model will it be? A decision tree? Some other type of model? Some other parameters of the model type are specified too.&lt;/li&gt;
&lt;li&gt;Fit: Capture patterns from provided data. This is the heart of modeling.&lt;/li&gt;
&lt;li&gt;Predict: Just what it sounds like&lt;/li&gt;
&lt;li&gt;Evaluate: Determine how accurate the model's predictions are.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jl4yoo4a3c4tc15x5s7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7jl4yoo4a3c4tc15x5s7.png" alt="Image description" width="800" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Many machine learning models allow some randomness in model training. Specifying a number for random_state ensures you get the same results in each run. This is considered a good practice. You use any number, and model quality won't depend meaningfully on exactly what value you choose.&lt;/p&gt;

&lt;p&gt;We now have a fitted model that we can use to make predictions.&lt;/p&gt;

&lt;p&gt;In practice, you'll want to make predictions for new houses coming on the market rather than the houses we already have prices for. But we'll make predictions for the first few rows of the training data to see how the predict function works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8mbzokuasepzqwrtawtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8mbzokuasepzqwrtawtg.png" alt="Image description" width="652" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Model Validation
&lt;/h2&gt;

&lt;p&gt;You'll want to evaluate almost every model you ever build. In most (though not all) applications, the relevant measure of model quality is __predictive accuracy. In other words, will the model's predictions be close to what happens.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Many people make a huge mistake when measuring predictive accuracy. They make predictions with their training data and compare those predictions to the target values in the training data. You'll see the problem with this approach and how to solve it in a moment, but let's think about how we'd do this first&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'd first need to summarize the model quality into an understandable way. If you compare predicted and actual home values for 10,000 houses, you'll likely find mix of good and bad predictions. Looking through a list of 10,000 predicted and actual values would be pointless. We need to summarize this into a single metric.&lt;/p&gt;

&lt;p&gt;There are many metrics for summarizing model quality, but we'll start with one called Mean Absolute Error (also called MAE). Let's break down this metric starting with the last word, error.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The prediction error for each house is:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;error=actual−predicted&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So, if a house costs $150,000 and you predicted it would cost $100,000 the error is $50,000.&lt;/p&gt;

&lt;p&gt;With the MAE metric, we take the &lt;em&gt;&lt;strong&gt;absolute value of each error&lt;/strong&gt;&lt;/em&gt;. This converts each error to a positive number. We then take the average of those absolute errors. This is our measure of model quality. In plain English, it can be said as&lt;/p&gt;

&lt;p&gt;On average, our predictions are off by about X.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0johlyltl0xftr05rkfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0johlyltl0xftr05rkfz.png" alt="Image description" width="800" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we have a model, here is how we calculate the mean absolute error:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftiqyrfst7cs94cg2yt7k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftiqyrfst7cs94cg2yt7k.png" alt="Image description" width="800" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with "In-Sample" Scores
&lt;/h2&gt;

&lt;p&gt;The measure we just computed can be called an "in-sample" score. We used a single "sample" of houses for both building the model and evaluating it. Here's why this is bad.&lt;/p&gt;

&lt;p&gt;Imagine that, in the large real estate market, door color is unrelated to home price.&lt;/p&gt;

&lt;p&gt;However, in the sample of data you used to build the model, all homes with green doors were very expensive. The model's job is to find patterns that predict home prices, so it will see this pattern, and it will always predict high prices for homes with green doors.&lt;/p&gt;

&lt;p&gt;Since this pattern was derived from the training data, the model will appear accurate in the training data.&lt;/p&gt;

&lt;p&gt;But if this pattern doesn't hold when the model sees new data, the model would be very inaccurate when used in practice.&lt;/p&gt;

&lt;p&gt;Since models' practical value comes from making predictions on new data, we measure performance on data that wasn't used to build the model. The most straightforward way to do this is to exclude some data from the model-building process, and then use those to test the model's accuracy on data it hasn't seen before. This data is called validation data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg2j8ecidbhy2nouupjw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg2j8ecidbhy2nouupjw.png" alt="Image description" width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wow!&lt;br&gt;
Your mean absolute error for the in-sample data was about 500 dollars. Out-of-sample it is more than 250,000 dollars.&lt;/p&gt;

&lt;p&gt;This is the difference between a model that is almost exactly right, and one that is unusable for most practical purposes. As a point of reference, the average home value in the validation data is 1.1 million dollars. So the error in new data is about a quarter of the average home value.&lt;/p&gt;

&lt;p&gt;There are many ways to improve this model, such as experimenting to find better features or different model types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Underfitting and Overfitting
&lt;/h2&gt;

&lt;p&gt;Fine-tune your model for better performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Experimenting With Different Models
&lt;/h3&gt;

&lt;p&gt;Now that you have a reliable way to measure model accuracy, you can experiment with alternative models and see which gives the best predictions. But what alternatives do you have for models?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fefrgwp1ws8nwe8g8qnd8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fefrgwp1ws8nwe8g8qnd8.png" alt="Image description" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In practice, it's not uncommon for a tree to have 10 splits between the top level (all houses) and a leaf.&lt;/p&gt;

&lt;p&gt;As the tree gets deeper, the dataset gets sliced up into leaves with fewer houses. If a tree only had 1 split, it divides the data into 2 groups.&lt;/p&gt;

&lt;p&gt;If each group is split again, we would get 4 groups of houses. Splitting each of those again would create 8 groups. If we keep doubling the number of groups by adding more splits at each level, we'll have  210 groups of houses by the time we get to the 10th level. That's 1024 leaves.&lt;/p&gt;

&lt;p&gt;When we divide the houses amongst many leaves, we also have fewer houses in each leaf. Leaves with very few houses will make predictions that are quite close to those homes' actual values, but they may make very unreliable predictions for new data (because each prediction is based on only a few houses).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is a phenomenon called &lt;strong&gt;overfitting&lt;/strong&gt;, where a model matches the training data almost perfectly, but does poorly in validation and other new data&lt;/em&gt;. On the flip side, if we make our tree very shallow, it doesn't divide up the houses into very distinct groups.&lt;/p&gt;

&lt;p&gt;At an extreme, if a tree divides houses into only 2 or 4, each group still has a wide variety of houses. Resulting predictions may be far off for most houses, even in the training data (and it will be bad in validation too for the same reason). &lt;em&gt;When a model fails to capture important distinctions and patterns in the data, so it performs poorly even in training data, that is called &lt;strong&gt;underfitting&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Since we care about accuracy on new data, which we estimate from our validation data, we want to find the sweet spot between underfitting and overfitting. Visually, we want the low point of the (red) validation curve in the figure below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnaz582qk2v24wt7jvdq0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnaz582qk2v24wt7jvdq0.png" alt="Image description" width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;There are a few alternatives for controlling the tree depth, and many allow for some routes through the tree to have greater depth than other routes. But the max_leaf_nodes argument provides a very sensible way to control overfitting vs underfitting. The more leaves we allow the model to make, the more we move from the underfitting area in the above graph to the overfitting area.&lt;/p&gt;

&lt;p&gt;We can use a utility function to help compare MAE scores from different values for max_leaf_nodes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facjk4jb5nrz0ga868hrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Facjk4jb5nrz0ga868hrj.png" alt="Image description" width="800" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can use a for-loop to compare the accuracy of models built with different values for max_leaf_nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8uu4use2pyt0fb5m4ss4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8uu4use2pyt0fb5m4ss4.png" alt="Image description" width="800" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of the options listed, 500 is the optimal number of leaves.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overfitting:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Overfitting happens when a model learns not only the underlying patterns in the data but also the noise or random fluctuations that exist in the dataset.&lt;/p&gt;

&lt;p&gt;Imagine you're trying to memorize a list of numbers, including some mistakes. Overfitting is like memorizing not just the real numbers but also the mistakes, which won't be useful for predicting new numbers accurately.&lt;/p&gt;

&lt;p&gt;When a model overfits, it performs very well on the training data (the data it was trained on) but doesn't generalize well to new, unseen data. In other words, it's too tailored to the training data and doesn't work well with new data.&lt;br&gt;
Underfitting:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Underfitting occurs when a model is too simple to capture the underlying patterns in the data.&lt;/p&gt;

&lt;p&gt;Going back to the memorization example, underfitting would be like trying to remember a complex list of numbers with just a few general ideas. You'll likely miss many important details.&lt;br&gt;
An underfit model doesn't perform well on either the training data or new data because it doesn't capture enough of the relevant patterns in the data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Validation Data:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Validation data is a separate set of data that the model hasn't seen during training. It's used to evaluate how well the model generalizes to new, unseen data.&lt;br&gt;
Just like taking a practice test before the real one, validation data helps us assess how well the model will perform in the real world.&lt;/p&gt;

&lt;p&gt;By trying out different models and evaluating their performance on the validation data, we can choose the one that performs the best and is most likely to make accurate predictions on new data.&lt;br&gt;
In simple terms, overfitting is like memorizing mistakes along with the right answers, while underfitting is like not studying enough to understand the material. &lt;/p&gt;

&lt;p&gt;Validation data helps us pick the model that performs the best on new problems we haven't seen before.&lt;/p&gt;

</description>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Correlation is not Causation!</title>
      <dc:creator>Aayush Sinha</dc:creator>
      <pubDate>Tue, 23 May 2023 10:09:20 +0000</pubDate>
      <link>https://dev.to/aayushs7ha/correlation-is-not-causation-4i8a</link>
      <guid>https://dev.to/aayushs7ha/correlation-is-not-causation-4i8a</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import matplotlib.pyplot as plt

# Simulating ice cream sales and sunglasses sales data
np.random.seed(0)
days = 100
temperature = np.random.normal(80, 10, days)  # Simulated temperature data
ice_cream_sales = temperature + np.random.normal(0, 5, days)  # Simulated ice cream sales data
sunglasses_sales = temperature + np.random.normal(0, 8, days)  # Simulated sunglasses sales data

# Calculating correlation coefficient
correlation_coefficient = np.corrcoef(ice_cream_sales, sunglasses_sales)[0, 1]

# Plotting the data
plt.scatter(ice_cream_sales, sunglasses_sales)
plt.xlabel('Ice Cream Sales')
plt.ylabel('Sunglasses Sales')
plt.title(f'Correlation: {correlation_coefficient:.2f}')
plt.show()



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/er997pzqrny6n9zhvqyz.JPG)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The phrase "correlation is not causation" is a fundamental principle in the field of statistics and scientific research. It reminds us that just because two variables are observed to be related or to occur together does not necessarily mean that one variable causes the other to happen.&lt;/p&gt;

&lt;p&gt;Correlation refers to a statistical relationship between two or more variables, indicating how they tend to change together. It measures the strength and direction of the relationship, ranging from -1 to 1. A correlation coefficient of 1 indicates a perfect positive correlation, -1 indicates a perfect negative correlation, and 0 indicates no correlation.&lt;/p&gt;

&lt;p&gt;Causation, on the other hand, refers to a cause-and-effect relationship between variables, where changes in one variable directly lead to changes in another variable. Establishing causation requires more than just observing a correlation. It involves rigorous experimentation, controlling for other factors, and demonstrating that changes in one variable lead to predictable and consistent changes in another variable.&lt;/p&gt;

&lt;p&gt;It's important to be cautious when interpreting correlations because there can be various reasons behind the observed relationship. Correlation does not provide evidence of causation because there might be underlying factors, often called confounding variables, that influence both variables simultaneously. Additionally, the correlation could be coincidental or the result of other factors that were not considered.&lt;/p&gt;

&lt;p&gt;To determine causation, researchers often use experimental designs, such as randomized controlled trials, where they manipulate one variable and observe the effect on another variable while controlling for confounding factors. Such experiments allow researchers to make stronger claims about causation.&lt;/p&gt;

&lt;p&gt;In summary, while correlations can be useful for identifying relationships between variables, it is crucial to remember that correlation alone does not establish causation. Additional evidence and rigorous research methods are necessary to determine causal relationships between variables.&lt;/p&gt;

&lt;p&gt;Let's consider a simple example to illustrate the difference between correlation and causation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example: Ice cream sales and sunglasses sales&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Suppose we observe a strong positive correlation between ice cream sales and sunglasses sales. That is, on hot sunny days, when ice cream sales increase, so do sunglasses sales. Based on this correlation, we might be tempted to conclude that increased ice cream sales cause increased sunglasses sales. However, this would be an example of mistakenly inferring causation from correlation.&lt;/p&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Correlation: The observed correlation suggests that there is a statistical relationship between ice cream sales and sunglasses sales. It indicates that the two variables tend to change together. On hot sunny days, people are more likely to buy both ice cream and sunglasses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Causation: However, correlation alone does not provide evidence of causation. In this example, ice cream sales and sunglasses sales might be correlated due to a common factor, such as weather. Hot sunny weather could be the driving factor behind both increased ice cream sales and increased sunglasses sales. People are more likely to buy ice cream to cool down and enjoy a refreshing treat, and they also need sunglasses to protect their eyes from the bright sunlight. Thus, weather is a confounding variable that influences both variables simultaneously, creating a correlation between them.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we were to mistakenly assume causation based on this correlation, we might conclude that selling more ice cream causes an increase in sunglasses sales. However, this conclusion ignores the underlying factor of hot sunny weather, which is the actual cause behind the observed correlation.&lt;/p&gt;

&lt;p&gt;To establish causation, we would need to conduct controlled experiments, such as manipulating ice cream sales while controlling for other factors like weather, and observing the effect on sunglasses sales. Only through such rigorous experimentation can we determine whether there is a causal relationship between the variables.&lt;/p&gt;

&lt;p&gt;Remembering that correlation does not imply causation is crucial for sound reasoning and accurate interpretation of statistical relationships.&lt;/p&gt;

</description>
      <category>correlation</category>
      <category>statistics</category>
      <category>causation</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
