Josep Ferrer Profile picture
Dec 21 โ€ข 9 tweets โ€ข 3 min read โ€ข Read on X
Struggling with Machine Learning algorithms? ๐Ÿค–

Then you better stay with me! ๐Ÿค“

Today we'll focus on the Simple Linear Regression Cost Function! ๐Ÿ‘‡๐Ÿป Image
0๏ธโƒฃ ๐—ฅ๐—˜๐—–๐—”๐—ฃ
In Simple Linear Regression, we use one independent variable to predict a dependent one.

It takes advantage of a line to calculate the slope (A) and intercept (B)

We need:
- A dependent and an independent variable.
- A linear dependency between them. Image
1๏ธโƒฃ ๐—ช๐—›๐—”๐—ง ๐—œ๐—ฆ ๐—” ๐—–๐—ข๐—ฆ๐—ง ๐—™๐—จ๐—ก๐—–๐—ง๐—œ๐—ข๐—ก?
A cost function helps us work out the optimal values for A and B.

Understand it as a way to find the optimal values for our predictor.
2๏ธโƒฃ ๐—›๐—ข๐—ช ๐——๐—ข ๐—ช๐—˜ ๐—ข๐—•๐—ง๐—”๐—œ๐—ก ๐—œ๐—ง ๐— ๐—”๐—ง๐—›๐—˜๐— ๐—”๐—ง๐—œ๐—–๐—”๐—Ÿ๐—Ÿ๐—ฌ?
In linear regression, this cost function is Mean Squared Errors (MSE).

It is the average of the squared errors. Image
โœš ๐—•๐—ข๐—ก๐—จ๐—ฆ
To find our optimal solutions, we use the gradient descent.

It is one of the optimization algorithms that optimizes the cost function.

To obtain the optimal solution, we need to reduce MSE for all data points.

Iteratively we get closer to the optimal solution. Image
3๏ธโƒฃ ๐—˜๐—ฉ๐—”๐—Ÿ๐—จ๐—”๐—ง๐—œ๐—ข๐—ก
The most used metrics are:
- Coefficient of Determination or R-Squared (R2)
- Root Mean Squared Error (RMSE) Image
4๏ธโƒฃ ๐—”๐—ฆ๐—ฆ๐—จ๐— ๐—ฃ๐—ง๐—œ๐—ข๐—ก๐—ฆ ๐—ง๐—ข ๐—”๐—ฃ๐—ฃ๐—Ÿ๐—ฌ ๐—œ๐—ง
Linear Regression isn't just about drawing lines.

It assumes certain conditions like linearity, independence, and normal distribution of residuals.

Ensuring these make our model more reliable. Image
And this is all for now... I'll be posting the whole theory part next Sunday, so stay tuned! ๐Ÿค“

Linear Regression is more than just a statistical method.

It's the simplest tool that helps us predict and understand our world better.
And that's all for now

If you liked this thread, I am sharing Data Science and AI content.
So don't forget to follow me to get more content like this! (@rfeers)

RT the tweet below to help me share the word! :D

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Josep Ferrer

Josep Ferrer Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @rfeers

Dec 22
Struggling to craft effective charts? ๐Ÿค”๐Ÿ“Š

Then, you better understand the ๐—š๐—ฒ๐˜€๐˜๐—ฎ๐—น๐˜ ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ๐˜€ in Data Visualization.

Today, I'm unveiling why some charts are intuitive while others are confusing ๐Ÿ’ฅ Image
Think of DataViz as your GPS in the world of numbers.

It turns complex data into clear, actionable insights.

But... why do some charts enlighten us while others don't?

The Gestalt Theory explains how our brains perceive patterns and how to take advantage of them. Image
1๏ธโƒฃ ๐—ฆ๐—ถ๐—บ๐—ถ๐—น๐—ฎ๐—ฟ๐—ถ๐˜๐˜†
Gestalt similarity means our brain groups things that look alike.

This can be because of their position, shape, color, or size.

๐ŸŽฏ This is extensively used in heat maps or scatter plots. Image
Read 8 tweets
Dec 20
Ever felt confused by SQL's execution flow? ๐Ÿค”

Then you better stay with me!

Today let's learn SQL's execution order and its importance ๐Ÿ‘‡๐Ÿป Image
1๏ธโƒฃ ๐—ฆ๐—ค๐—Ÿ ๐—”๐—ฆ ๐—” ๐——๐—˜๐—–๐—Ÿ๐—”๐—ฅ๐—”๐—ง๐—œ๐—ฉ๐—˜ ๐—Ÿ๐—”๐—ก๐—š๐—จ๐—”๐—š๐—˜
๐˜ ๐˜ฐ๐˜ถ ๐˜ต๐˜ฆ๐˜ญ๐˜ญ ๐˜ช๐˜ต ๐˜ธ๐˜ฉ๐˜ข๐˜ต ๐˜บ๐˜ฐ๐˜ถ ๐˜ธ๐˜ข๐˜ฏ๐˜ต, ๐˜ฏ๐˜ฐ๐˜ต ๐˜ฉ๐˜ฐ๐˜ธ ๐˜ต๐˜ฐ ๐˜ฅ๐˜ฐ ๐˜ช๐˜ต.

So SQL expects statements to be written in a specific orderโ€Š...

but their evaluation sequence differs. Image
2๏ธโƒฃ ๐—ฆ๐—ค๐—Ÿ ๐—ค๐—จ๐—˜๐—ฅ๐—ฌ ๐—ฆ๐—ง๐—ฅ๐—จ๐—–๐—ง๐—จ๐—ฅ๐—˜
The most common SQL query structure looks just like follows Image
Read 9 tweets
Dec 16
Do you usually use Pandas in your daily work?

๐˜๐˜ง ๐˜บ๐˜ฐ๐˜ถ ๐˜ธ๐˜ฐ๐˜ณ๐˜ฌ ๐˜ธ๐˜ช๐˜ต๐˜ฉ ๐˜ฅ๐˜ข๐˜ต๐˜ข, ๐˜ ๐˜ฃ๐˜ฆ๐˜ต ๐˜บ๐˜ฐ๐˜ถ ๐˜ฅ๐˜ฐ!

Let's discover together how to get a quick grasp of any DataFrame with 4 simple commands๐Ÿ‘‡๐Ÿป Image
1๏ธโƒฃ .๐—พ๐˜‚๐—ฒ๐—ฟ๐˜†()
Need to filter data based on certain conditions?

.query() is here to rescue!

This function selects rows using a SQL-like query string, helping you dive deep into specific data aspects. Image
2๏ธโƒฃ.๐˜€๐—ผ๐—ฟ๐˜_๐˜ƒ๐—ฎ๐—น๐˜‚๐—ฒ๐˜€()
Keep your data tidy and organized with sort_values().

Sort your DataFrame by one or multiple columns.

Itโ€™s like putting your data on a neat shelf! Image
Read 7 tweets
Dec 9
Struggling with long and complex SQL queries?

Then you can easily take advantage of CTEs.

Today I want to show you how to create readable and reusable queries using a modular approach!๐Ÿ‘‡๐Ÿป Image
What is a CTE, you ask?๐Ÿค”

๐—–๐—ง๐—˜ ๐˜€๐˜๐—ฎ๐—ป๐—ฑ๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—บ๐—ผ๐—ป ๐—ง๐—ฎ๐—ฏ๐—น๐—ฒ ๐—˜๐˜…๐—ฝ๐—ฟ๐—ฒ๐˜€๐˜€๐—ถ๐—ผ๐—ป.

They are temporal tables that can be referenced many times within a single query. Image
To generate CTEs we define the "๐—ช๐—œ๐—ง๐—›" command at the beginning of our query.

It allows to chain of different temporal tables (CTEs) with aliases. Image
Read 7 tweets
Nov 25
Is SQL not enough for your analysis? ๐Ÿ’ฅ

Then you can easily switch to Python.

Today I am bringing 4 more simple examples to move from SQL queries to Python Pandas DataFrames๐Ÿ‘‡๐Ÿป Image
1๏ธโƒฃ ๐—–๐—ข๐—จ๐—ก๐—ง ๐——๐—œ๐—ฆ๐—ง๐—œ๐—ก๐—–๐—ง ๐—ฉ๐—”๐—Ÿ๐—จ๐—˜๐—ฆ
Ever wondered about the variety in your dataset? ๐Ÿค”

SQL's COUNT DISTINCT comes in handy for unique entries.

In Pandas? Just a simple nunique() does the trick.

Both methods are your go-to for uncovering data diversity in a snap! ๐ŸŒŸ Image
2๏ธโƒฃ ๐—–๐—ข๐—จ๐—ก๐—ง ๐—ฉ๐—”๐—Ÿ๐—จ๐—˜๐—ฆ
Need the total count in a column?

COUNT(*) is your SQL friend.

But in the Pandas world? len(df) gets the job done effortlessly.

Both approaches let you quickly grasp the scale of your dataset. ๐Ÿ“ˆ Image
Read 6 tweets
Nov 18
Do you usually use Pandas in your daily work?

๐˜๐˜ง ๐˜บ๐˜ฐ๐˜ถ ๐˜ธ๐˜ฐ๐˜ณ๐˜ฌ ๐˜ธ๐˜ช๐˜ต๐˜ฉ ๐˜ฅ๐˜ข๐˜ต๐˜ข, ๐˜ ๐˜ฃ๐˜ฆ๐˜ต ๐˜บ๐˜ฐ๐˜ถ ๐˜ฅ๐˜ฐ!

Let's discover together how to get a quick grasp of any DataFrame with 4 simple commands๐Ÿ‘‡๐Ÿป Image
1๏ธโƒฃ .๐—พ๐˜‚๐—ฒ๐—ฟ๐˜†()
Need to filter data based on certain conditions?

.query() is here to rescue!

This function selects rows using a SQL-like query string, helping you dive deep into specific data aspects. Image
2๏ธโƒฃ.๐˜€๐—ผ๐—ฟ๐˜_๐˜ƒ๐—ฎ๐—น๐˜‚๐—ฒ๐˜€()
Keep your data tidy and organized with sort_values().

Sort your DataFrame by one or multiple columns.

Itโ€™s like putting your data on a neat shelf! Image
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(