Sunday, 19 July 2026

Principal Component Analysis with NumPy

 



Introduction

Many real‑world datasets have high dimensionality: lots of features, variables, measurements. This often leads to problems like redundancy, noise, and difficulty visualising or modelling effectively. That’s where dimensionality reduction comes in—techniques that simplify the data while retaining meaningful structure. One of the most widely‑used methods for that is **Principal Component Analysis (PCA).

This guided project offers a hands‑on implementation of PCA using Python and NumPy—from scratch (without high‑level ML libraries) so you understand the mechanics. It’s designed as a compact project (~1.5 to 2 hours) but packs in key workflow steps: exploratory data analysis, eigen‑decomposition or singular value decomposition (SVD), projection, and visualisation.


Why This Project Matters

  • Understanding the mechanics: Many courses tell you “use PCA” via a library call. This project takes you deeper—you implement key steps like computing eigenvectors and projecting the data. That builds stronger intuition.

  • Useful real‑world skill: PCA (and dimensionality reduction in general) shows up in many data‑science workflows—visualisation, pre‑processing, compression, noise reduction. Being comfortable with it is valuable for data scientists and ML engineers.

  • Builds confidence with NumPy: Implementing PCA requires working with linear algebra operations in NumPy (covariance matrices, eigen decomposition, SVD). That strengthens your technical toolkit.

  • Quick and focused: Because it’s short and project‑based, it’s a good “bite‑sized” learning activity you can complete in one session and then apply or extend further.


What You’ll Learn

Here’s a breakdown of the project steps and learning outcomes:

1. Load and Explore the Data
You start by importing libraries and a dataset (likely in a Jupyter notebook in the cloud workspace). You’ll perform basic exploratory data analysis (EDA): look at feature distributions, correlations, visualise structure.
This step teaches you how to prepare and visualise data before reduction.

2. Data Standardisation
Since PCA is sensitive to scale, you’ll standardise the features (e.g., subtract mean, divide by standard deviation).
You’ll reinforce understanding of why standardisation is important when features have different units or variances.

 3. Compute Eigenvectors and Eigenvalues or SVD
You implement the core step: compute the covariance matrix (or use singular value decomposition). Then compute eigenvectors and eigenvalues (or singular values) which define the principal components.
This is where you engage with linear algebra via NumPy, and learn how directions of highest variance are found.

4. Select Principal Components Using Explained Variance
You’ll inspect the eigenvalues (or singular values) to determine how many principal components to keep—typically by measuring “explained variance” (the proportion of total variance captured by components).
You’ll learn how to make choices about dimensionality reduction based on how much information you’re willing to lose.

5. Project the Data onto a Lower‑Dimensional Subspace
Finally you transform the original data into the principal‑component space (e.g., 2 dimensions) so you can visualise or model in lower dimensions.
You’ll see how the data looks in reduced form, and understand how much you’ve simplified it—and at what cost.

6. Visualise the Results
You’ll create visualisations (using Matplotlib/Seaborn) to show the projected data, maybe colour‑coded by categories (if available).
This step helps you see how PCA helps reveal structure (clusters, separation) in fewer dimensions.


Who Is This Project For?

This project is ideal for:

  • Python programmers with some basic data‑science or ML knowledge who want to strengthen their understanding of PCA.

  • Data analysts wanting to gain hands‑on experience with a key preprocessing technique.

  • Students or self‑learners who understand ML basics (features, models) and want to dive into unsupervised learning and dimension‑reduction workflows.

If you are brand new to programming or unfamiliar with linear algebra (matrices, eigenvectors), you may find parts of this project challenging—but still very valuable if you are willing to follow carefully.


How to Get the Most Out of It

  • Follow the code step‑by‑step: Since this is a guided project, watch (or type) each segment, then pause and modify.

  • Change the dataset: After you finish the guided part, try applying PCA on a dataset of your choice (maybe your personal data or a small open dataset) to reinforce learning.

  • Compare with library implementation: After you manually implement PCA, you might try the same via a library (e.g., scikit‑learn) and compare results—what’s similar, what differs?

  • Visualise multiple dimensions: If the principal components allow, try projecting into 3 dimensions and use 3D visualisations to explore structure.

  • Reflect on trade‑offs: Ask yourself: “How many components did I drop? What information might I lose? Is the reduced dataset still usable for modelling?”

  • Add this to your portfolio: Save the notebook, write a brief summary (what you did, what you learned, how PCA changed the data) and store it on your GitHub or portfolio.


What You’ll Walk Away With

After completing this project you will:

  • Understand how to implement PCA from first principles using NumPy.

  • Be comfortable with the steps: standardisation, covariance/SVD, eigenvectors/values, projection, explained variance.

  • Gain experience in visualising high‑dimensional data and interpreting dimensionality‑reduction results.

  • Have increased confidence with NumPy and Jupyter notebooks for data‑science workflows.

  • Possess a practical piece (your project notebook) to demonstrate your ability to work with unsupervised techniques and linear algebra‑based preprocessing.



Conclusion

This “Principal Component Analysis with NumPy” guided project is a high‑value, compact learning opportunity for anyone wanting to deepen their data‑science skillset. It gives you not just the “what” of PCA, but the “how” and “why” by implementing it manually rather than simply using a tool.



Introduction to Statistics by Standford University

 

In today’s digital world, data is everywhere—from social media analytics to financial forecasting and healthcare research. However, data alone is not useful unless we know how to interpret it. This is where statistics plays a critical role.

The Introduction to Statistics course offered by Stanford University on Coursera provides a strong foundation for understanding data, statistical thinking, and data-driven decision making. It is designed for beginners who want to learn how to analyze data and interpret statistical results effectively.


What Is the Course About?

The course focuses on teaching statistical thinking, which is essential for learning from data and communicating insights. By the end of the course, learners understand how to perform exploratory data analysis, apply sampling techniques, and interpret statistical tests.

Statistics is widely used in fields such as data science, economics, business analytics, healthcare, and machine learning. Learning the basics of statistics helps professionals make informed decisions based on evidence rather than assumptions.


Key Topics Covered in the Course

1. Descriptive Statistics

Descriptive statistics helps summarize and visualize data. In this section, learners explore methods for presenting data using charts, graphs, and numerical summaries.

Common concepts include:

  • Mean, median, and mode

  • Standard deviation and variance

  • Histograms and data visualization

These tools help analysts quickly understand patterns and trends in datasets.


2. Sampling and Experimental Design

In real-world research, it is often impossible to collect data from an entire population. Instead, statisticians use sampling techniques to study a smaller group that represents the population.

The course explains:

  • Random sampling

  • Experimental design

  • Randomized controlled experiments

Understanding these concepts helps ensure that statistical conclusions are reliable.


3. Probability Fundamentals

Probability is the mathematical framework used to measure uncertainty. In this module, learners explore the basic rules of probability and how they apply to real-life situations.

Topics include:

  • Probability rules

  • Random variables

  • Real-world probability examples

Probability forms the backbone of many advanced statistical techniques.


4. Probability Distributions

Statistical models often rely on probability distributions to describe patterns in data.

The course introduces distributions such as:

  • Binomial distribution

  • Normal distribution

  • Random variable analysis

These models help predict outcomes and analyze uncertainty in data-driven environments.


5. Sampling Distributions and the Central Limit Theorem

One of the most important ideas in statistics is the Central Limit Theorem (CLT).

This module explains:

  • Sampling distributions

  • Law of Large Numbers

  • The Central Limit Theorem

These concepts allow statisticians to make predictions about populations based on sample data.


6. Regression and Statistical Inference

Regression is one of the most widely used statistical methods for analyzing relationships between variables.

Students learn:

  • Linear regression models

  • Hypothesis testing

  • Confidence intervals

These tools are essential for drawing conclusions from data and making predictions.


Course Duration and Structure

The course is self-paced and beginner-friendly, typically taking around 14 hours to complete.

The learning format includes:

  • Video lectures

  • Quizzes and assignments

  • Practical statistical examples

This structure helps learners build both theoretical knowledge and practical understanding of statistics.


Skills You Will Gain

By completing this course, you will develop skills such as:

  • Statistical thinking

  • Data analysis and interpretation

  • Probability and distributions

  • Regression analysis

  • Hypothesis testing

  • Data visualization

These skills are fundamental for careers in data science, business analytics, research, and finance.


Who Should Take This Course?

This course is ideal for:

  • Students interested in data science

  • Beginners learning statistics

  • Professionals working with data analysis

  • Anyone curious about how data is interpreted

Since the course starts with fundamental concepts, it is suitable even for people with little or no background in statistics.


Why Learning Statistics Matters

Statistics helps transform raw data into meaningful insights. Organizations across industries rely on statistical methods to:

  • Predict future trends

  • Analyze customer behavior

  • Evaluate business performance

  • Support scientific research

Without statistics, data would simply be numbers without context.


Join Now: Introduction to Statistics

Final Thoughts

Stanford’s Introduction to Statistics course is an excellent starting point for anyone interested in understanding data and developing analytical thinking. It combines fundamental statistical concepts with practical examples, making it accessible to beginners.

If you want to begin your journey into data science, analytics, or research, learning statistics is one of the most important steps you can take.

Python Coding Challenge - Question with Answer (ID -190726)

 


Explanation:

Line 1: print(...)
print() is a built-in Python function.
It is used to display the output on the screen.
Whatever is inside the parentheses () is evaluated first, and then the result is printed.

Line 2: {1, 2, 3}
{1, 2, 3} is a set.
A set is an unordered collection of unique elements.

Elements in this set are:

1
2
3

Line 3: {2, 3, 4}
This is another set.

It contains:

2
3
4

Line 4: & (Intersection Operator)
The & operator is called the intersection operator for sets.
It returns only the elements that are common to both sets.
First Set
{1, 2, 3}
Second Set
{2, 3, 4}
Common Elements
2
3

So,

{1, 2, 3} & {2, 3, 4}

becomes

{2, 3}

Line 5: print({2, 3})
The print() function displays the result:
{2, 3}

Output
{2, 3}

Book: Python for GIS & Spatial Intelligence

Python Coding challenge - Day 1139| What is the output of the following Python Code?

 


Code Explanation:

๐Ÿ”น 1. Descriptor Class Definition
class Descriptor:
You define a class named Descriptor.
This will act as a descriptor because it implements special methods.

๐Ÿ”น 2. Defining __get__ Method
def __get__(self, obj, objtype):
    return 50
This makes the class a non-data descriptor (because only __get__ is defined).
Parameters:
self → descriptor instance
obj → instance of Test (i.e., obj)
objtype → class Test
Whenever the descriptor is accessed, it returns 50.

๐Ÿ”น 3. Test Class Definition
class Test:
A new class Test is defined.

๐Ÿ”น 4. Assigning Descriptor to Class Attribute
x = Descriptor()
x becomes a descriptor object.
It is stored in the class namespace (Test.__dict__).
This means x is controlled by descriptor behavior.

๐Ÿ”น 5. Object Creation
obj = Test()
Creates an instance of the Test class.

๐Ÿ”น 6. Setting Instance Attribute
obj.x = 100
This creates an instance attribute x inside obj.__dict__.
Important:
Since Descriptor is a non-data descriptor (no __set__),
instance attributes take priority over the descriptor.

๐Ÿ”น 7. Accessing obj.x
print(obj.x)

Let’s break the lookup process:

➤ Step-by-Step Attribute Lookup
Python checks:
Does class have a data descriptor (__get__ + __set__)?
❌ No → skip

Check instance dictionary:

obj.__dict__ → {'x': 100}

✔️ Found → returns 100

Descriptor is ignored because:
Non-data descriptors have lower priority than instance attributes

๐Ÿ”น 8. Final Output
100

Python Coding challenge - Day 1138| What is the output of the following Python Code?

 


Code Explanation:

๐Ÿ”น 1. Class Definition
class Test:
You are defining a class named Test.

๐Ÿ”น 2. Overriding __getattribute__
def __getattribute__(self, name):
This method is called for every attribute access on an object.
It runs before anything else, even before __getattr__.
➤ Inside __getattribute__
if name == "x":
    return 100
If someone tries to access obj.x, this condition becomes true.
It directly returns 100.
No further lookup happens.
return super().__getattribute__(name)
For any other attribute:
It calls the default attribute lookup mechanism using super().
If the attribute exists → returns it.
If it does NOT exist → raises AttributeError.

๐Ÿ”น 3. Overriding __getattr__
def __getattr__(self, name):
This method is called only when the attribute is NOT found normally.
It acts as a fallback handler.
➤ Inside __getattr__
return 200
If an attribute doesn’t exist (like y), this method returns 200.

๐Ÿ”น 4. Object Creation
obj = Test()
Creates an instance of the Test class.

๐Ÿ”น 5. Printing Values
print(obj.x, obj.y)

Let’s break this step carefully:

➤ Accessing obj.x
__getattribute__ is called with name = "x".
Condition name == "x" is True.
Returns 100.

✔️ So, obj.x = 100

➤ Accessing obj.y
__getattribute__ is called with name = "y".

Condition fails → goes to:

super().__getattribute__("y")
Python tries to find y → it does NOT exist → raises AttributeError.
Since error occurred → Python calls __getattr__.
__getattr__ returns 200.

✔️ So, obj.y = 200

๐Ÿ”น 6. Final Output
100 200

Python Coding challenge - Day 1137| What is the output of the following Python Code?

 




Code Explanation:

๐Ÿ”น 1. Class Definition

class Test:

Defines a class named Test.

This class will be used to create objects.

๐Ÿ”น 2. Special Method __bool__

def __bool__(self):

    return False

__bool__ is a special (magic) method in Python.

It controls how an object behaves in a Boolean context (like if, while, etc.).

Here, it always returns False.

That means any object of this class will be treated as False in conditions.

๐Ÿ”น 3. Creating an Object

obj = Test()

Creates an instance of the class Test.

Now obj is an object of class Test.

๐Ÿ”น 4. Using Object in Condition

if obj:

Python checks whether obj is True or False.


Since Test has __bool__, Python calls:


obj.__bool__()

This returns False.

๐Ÿ”น 5. If Block

print("YES")

This will run only if the condition is True.

But here the condition is False, so this line is skipped.

๐Ÿ”น 6. Else Block

print("NO")

Since the condition is False, this block executes.

So "NO" gets printed.

๐Ÿ”น Final Output

NO


Book:  700 Days Python Coding Challenges with Explanation

Python Coding challenge - Day 1145| What is the output of the following Python Code?

 

Code Explanation:

๐Ÿ”น 1. Generator Function Definition

def gen():
    for i in range(3):
        yield i
✅ Explanation:
gen() is a generator function because it uses yield.
It produces values one by one instead of returning all at once.
๐Ÿ” What it will generate:
0 → 1 → 2

๐Ÿ”น 2. Creating Generator Object
g = gen()
✅ Explanation:
Calling gen() does NOT run the function immediately.
It returns a generator object.
Execution starts only when iterated (next() or loop).

๐Ÿ”น 3. Iterating Using for Loop
for x in g:
    print(x)
๐Ÿ” What happens internally:
Python repeatedly calls:
next(g)
Step-by-step execution:
yield 0 → prints 0
yield 1 → prints 1
yield 2 → prints 2
Generator is exhausted → loop stops
✔️ Output so far:
0
1
2

๐Ÿ”น 4. Converting Generator to List
print(list(g))
๐Ÿšจ Important:
Generator g is already exhausted after the loop
No values left to produce
๐Ÿ” So:
list(g) → []

๐ŸŽฏ Final Output
0
1
2
[]

Python Coding challenge - Day 1144| What is the output of the following Python Code?

 


Code Explanation:

๐Ÿ”น 1. Creating Empty List
a = []
✅ Explanation:
An empty list a is created.
It will store inner lists.

๐Ÿ”น 2. Loop to Add Inner Lists
for i in range(3):
    a.append([i])
✅ Explanation:
Loop runs for: i = 0, 1, 2
Each time, a new list [i] is created and appended
๐Ÿ” After loop:
a → [[0], [1], [2]]

✔️ Important:

Each inner list is a separate object in memory

๐Ÿ”น 3. Shallow Copy
b = a.copy()
✅ Explanation:
Creates a shallow copy of list a
Only the outer list is copied
Inner lists are still shared
๐Ÿ” So:
b → [[0], [1], [2]]

But:

b[0] is a[0] → True

๐Ÿ‘‰ Both point to same inner list

๐Ÿ”น 4. Modifying Copied List
b[0][0] = 100
✅ Explanation:
Accesses:
b[0] → first inner list [0]
Then changes its first element → 100
๐Ÿ” Now:
b → [[100], [1], [2]]

๐Ÿ”น 5. Why a Also Changes

Since:

b[0] is a[0]

๐Ÿ‘‰ The same inner list is modified

So:

a → [[100], [1], [2]]

๐Ÿ”น 6. Printing Original List
print(a)
✅ Output:
[[100], [1], [2]]

๐ŸŽฏ Final Output
[[100], [1], [2]]

Python Coding challenge - Day 1136| What is the output of the following Python Code?

 


Code Explanation:

๐Ÿ”น 1. Class Definition
class Test:
This line defines a class named Test.
A class is a blueprint used to create objects.

๐Ÿ”น 2. Constructor Method (__init__)
def __init__(self):
    self.count = 0
__init__ is a constructor, automatically called when an object is created.
self refers to the current object instance.
self.count = 0 initializes a variable count and sets it to 0.

๐Ÿ”น 3. Callable Method (__call__)
def __call__(self):
__call__ makes the object behave like a function.
This means you can use obj() instead of calling a method explicitly.
Inside __call__
self.count += 1
Each time the object is called, count increases by 1.
return self.count
Returns the updated value of count.

๐Ÿ”น 4. Creating Object
obj = Test()
Creates an instance (object) of class Test.
The constructor runs, so count = 0.

๐Ÿ”น 5. Calling the Object
print(obj(), obj(), obj())
What happens step-by-step:
๐Ÿ‘‰ First obj()
Calls __call__
count = 0 → 1
Returns 1
๐Ÿ‘‰ Second obj()
count = 1 → 2
Returns 2
๐Ÿ‘‰ Third obj()
count = 2 → 3
Returns 3

๐Ÿ”น Final Output
1 2 3

Python Coding challenge - Day 1173| What is the output of the following Python Code?

 


 Code Explanation:

๐Ÿ”น Step 1: Import cached_property
from functools import cached_property

cached_property is a modern Python feature.

It works like:

@property

but with one important difference:

The value is calculated only once
and then stored (cached).

๐Ÿ”น Step 2: Create Class
class A:

A new class named A is created.

๐Ÿ”น Step 3: Define Cached Property
@cached_property
def x(self):
    return []

This creates a property named:

x

When accessed for the first time:

a.x

Python executes:

return []

and stores the result.

๐Ÿ”น Step 4: Create Object
a = A()

Object created:

a

At this moment:

x has NOT been executed yet

because cached properties are lazy.

๐Ÿ”น Step 5: Access a.x
a.x.append(1)

Before .append() can run, Python evaluates:

a.x

Since this is the first access:

Python executes:

def x(self):
    return []

Result:

[]

This list is now cached internally.

Memory:

a.x ──► []

๐Ÿ”น Step 6: Execute Append

Now Python runs:

[].append(1)

List becomes:

[1]

Since the cached object itself was modified:

Memory becomes:

a.x ──► [1]

๐Ÿ”น Step 7: Print a.x
print(a.x)

Python checks:

Has x already been computed?

✅ Yes

So it does NOT execute:

return []

again.

Instead it returns the cached object:

[1]

๐Ÿ”น Step 8: Print Result
print([1])

Output:

[1]

Python Coding challenge - Day 1199| What is the output of the following Python Code?

 

Code:

from abc import ABC, abstractmethod class Test(ABC): @abstractmethod def show(self): pass obj = Test()


 



Explanation:

๐Ÿ”น 1. Importing ABC and abstractmethod
from abc import ABC, abstractmethod
✅ Explanation
Python imports two special objects from the abc (Abstract Base Class) module.
ABC is used to create an Abstract Base Class.
@abstractmethod is used to declare methods that must be implemented by child classes.

Think of it like an architect's blueprint.

Architect Blueprint


Must have:

✔ Door
✔ Window
✔ Roof

You cannot live inside a blueprint.

Similarly,

ABC


Defines rules


Cannot be used directly

๐Ÿ”น 2. Creating an Abstract Class
class Test(ABC):
✅ Explanation

Here, Test inherits from ABC.

This tells Python:

"This is not a normal class.

This is an Abstract Class."

Visual:

ABC

 │

 ▼

Test

(Abstract Class)

Unlike a normal class, this class is meant to be inherited, not instantiated.


๐Ÿ”น 3. Using @abstractmethod
@abstractmethod
✅ Explanation

This decorator marks the next method as abstract.

Meaning:

Every child class

MUST

implement this method.

It is like creating a rule.

Example:

School Rule

Every student

must submit homework.

Similarly,

Every child class

must implement show()

๐Ÿ”น 4. Defining the Abstract Method
def show(self):
✅ Explanation

A method named show() is declared.

But notice...

It has no implementation.

It only defines:

Method name
Parameters

Actual logic will be written by child classes.

Visual:

show()


Only Declaration


No Code Yet

๐Ÿ”น 5. Using pass
pass
✅ Explanation

pass means:

"Do nothing."

Python requires every function to have a body.

Since the method is abstract, we leave it empty using pass.

Equivalent idea:

Coming Soon...

No implementation yet.

๐Ÿ”น 6. Current Class Structure

At this point, Python has created:

Test


└── show()

(Abstract Method)

Notice:

show()


No implementation

Therefore the class is incomplete.


๐Ÿ”น 7. Creating an Object
obj = Test()
✅ Explanation

Python now tries to create an object.

Internally:

Create Object


Check Class


Does it contain abstract methods?


YES

Python immediately stops.

๐Ÿ”น 8. Why Does Python Raise an Error?

Because Test still has an abstract method.

Python says:

You promised that

show()

would be implemented,

but it isn't.

So object creation is not allowed.

❌ Error Produced
TypeError:
Can't instantiate abstract class Test
with abstract method show

๐ŸŽฏ Final Output
TypeError:
Can't instantiate abstract class Test
with abstract method show

Python Coding challenge - Day 1198| What is the output of the following Python Code?

 


Code :

from operator import methodcaller text = "python" upper = methodcaller("upper") print(upper(text))





Explanation:

๐Ÿ”น 1. Importing methodcaller

from operator import methodcaller

✅ Explanation

methodcaller() is imported from Python's operator module.

It creates a function that calls a specific method on any object you pass to it.

Instead of calling a method directly, methodcaller stores the method name and calls it later.


Think of it like a remote control.


TV


        ▲

        │


Remote


        │


Press "Power"


        │


TV Turns ON


Here,


Remote → methodcaller

Power Button → "upper"

TV → "python"


๐Ÿ”น 2. Creating a String

text = "python"

✅ Explanation


A string variable named text is created.


Current memory:


text


 │


 ▼


"python"


๐Ÿ”น 3. Creating a Method Caller

upper = methodcaller("upper")

✅ Explanation


This line does not call the upper() method.


Instead, it creates a callable object that remembers:


Whenever someone gives me an object,


I'll call its upper() method.


Think of it like preparing a command.


Current memory:


upper


 │


 ▼


Call upper() later


Nothing has executed yet.


๐Ÿ”น 4. What is Stored Inside upper?


Internally Python creates something similar to:


def upper(obj):

    return obj.upper()


So,


upper = methodcaller("upper")


behaves almost like:


def upper(obj):

    return obj.upper()


It is waiting for an object.


๐Ÿ”น 5. Calling the Function

upper(text)

✅ Explanation


Now Python passes:


text


to the stored function.


Internally:


text.upper()


gets executed.


Current value:


"python"


๐Ÿ”น 6. Executing upper()


Python now performs:


"python".upper()


The upper() string method converts every lowercase letter into uppercase.


Before:


python


After:


PYTHON


Notice:


The original string is not changed because strings are immutable.


๐Ÿ”น 7. Printing the Result

print(upper(text))

✅ Explanation


Python prints the returned value.


Output:


PYTHON


๐ŸŽฏ Final Output

PYTHON

Python Coding challenge - Day 1197| What is the output of the following Python Code?

 


Code:

from itertools import dropwhile nums = [2, 4, 6, 7, 8] print( list(dropwhile(lambda x: x < 7, nums)) )





Explanation:

๐Ÿ”น 1. Importing dropwhile
from itertools import dropwhile
✅ Explanation
dropwhile() is imported from Python's itertools module.
It keeps removing elements from the beginning of the iterable as long as the given condition is True.
The moment the condition becomes False, it stops checking and returns that element and all remaining elements.

Think of it like a security gate.

People entering

2 → ❌ Skip

4 → ❌ Skip

6 → ❌ Skip

7 → ✅ Stop Skipping

After this,
everyone enters without checking.

7
8

๐Ÿ”น 2. Creating the List
nums = [2, 4, 6, 7, 8]
✅ Explanation

A list named nums is created.

Current list:

[2, 4, 6, 7, 8]

Memory:

nums
 │
 ▼
[2,4,6,7,8]

๐Ÿ”น 3. Calling dropwhile()
dropwhile(lambda x: x < 7, nums)
✅ Explanation

Syntax:

dropwhile(condition, iterable)

Here,

Condition → x < 7
Iterable → nums

Meaning:

Keep removing numbers
until you find
a number that is NOT less than 7.

๐Ÿ”น 4. Understanding the Lambda Function
lambda x: x < 7
✅ Explanation

This lambda checks:

Is the current number less than 7?

Equivalent function:

def check(x):
    return x < 7

๐Ÿ”น 5. First Iteration

Current element:

x = 2

Condition:

2 < 7

Result:

True ✅

Since the condition is True, dropwhile() drops (removes) 2.

Remaining list:

[4, 6, 7, 8]

Visual:

2 ❌ Removed

๐Ÿ”น 6. Second Iteration

Current element:

x = 4

Condition:

4 < 7

Result:

True ✅

Again, 4 is removed.

Remaining list:

[6, 7, 8]

Visual:

4 ❌ Removed

๐Ÿ”น 7. Third Iteration

Current element:

x = 6

Condition:

6 < 7

Result:

True ✅

6 is also removed.

Remaining list:

[7, 8]

Visual:

6 ❌ Removed

๐Ÿ”น 8. Fourth Iteration

Current element:

x = 7

Condition:

7 < 7

Result:

False ❌

This is the turning point.

As soon as the condition becomes False:

dropwhile() stops dropping elements.
It keeps the current element (7).
It does not check any remaining elements.

Visual:

7 ✅ Keep

Stop Checking

๐Ÿ”น 9. Remaining Elements

After 7, the remaining element is:

8
✅ Explanation

Even though:

8 < 7

is False,

Python doesn't check it anymore.

Once dropwhile() encounters the first False, it simply returns all remaining elements.

Final sequence:

7
8

๐Ÿ”น 10. Converting to a List
list(dropwhile(...))
✅ Explanation

dropwhile() returns an iterator.

list() converts it into a normal list.

Result:

[7, 8]

๐Ÿ”น 11. Printing the Result
print(list(...))
✅ Explanation

Python prints:

[7, 8]

๐ŸŽฏ Final Output
[7, 8]

Python Coding challenge - Day 1196| What is the output of the following Python Code?

 


Code:

from functools import reduce nums = [1, 2, 3, 4] result = reduce( lambda x, y: x * y, nums ) print(result)


Explanation:

๐Ÿ”น 1. Importing reduce
from functools import reduce
✅ Explanation
reduce() is imported from Python's functools module.
It is used to reduce an entire iterable (list, tuple, etc.) into a single value.
It repeatedly applies a function to two values until only one value remains.

Think of reduce() like a machine that combines many values into one final result.

1   2   3   4
│   │   │   │
└──► Combine ◄──┘
        │
        ▼
One Final Answer

๐Ÿ”น 2. Creating the List
nums = [1, 2, 3, 4]
✅ Explanation

A list named nums is created.

Current list:

[1, 2, 3, 4]

Memory:

nums
 │
 ▼
[1, 2, 3, 4]

๐Ÿ”น 3. Calling reduce()
result = reduce(
✅ Explanation

reduce() starts processing the list.

Syntax:

reduce(function, iterable)

Here,

Function → lambda x, y: x * y
Iterable → nums

Its goal is to multiply all numbers and return one final value.

๐Ÿ”น 4. Understanding the Lambda Function
lambda x, y: x * y
✅ Explanation

This anonymous function takes two values and returns their product.

Equivalent normal function:

def multiply(x, y):
    return x * y

Every time reduce() needs to combine two values, it calls this function.

๐Ÿ”น 5. First Iteration

Initially:

[1, 2, 3, 4]

Python picks the first two values.

x = 1
y = 2

Calculation:

1 * 2

Result:

2

Now Python replaces 1 and 2 with the result.

Remaining calculation becomes:

2, 3, 4

Visual:

1 × 2


2

New Sequence

[2,3,4]

๐Ÿ”น 6. Second Iteration

Current sequence:

[2,3,4]

Python picks:

x = 2
y = 3

Calculation:

2 * 3

Result:

6

Updated sequence:

[6,4]

Visual:

2 × 3


6

New Sequence

[6,4]

๐Ÿ”น 7. Third Iteration

Current sequence:

[6,4]

Python picks:

x = 6
y = 4

Calculation:

6 * 4

Result:

24

Only one value remains.

Final result:

24

Visual:

6 × 4


24

๐Ÿ”น 8. Storing the Result
result = 24

Current memory:

result


24

๐Ÿ”น 9. Printing the Result
print(result)
✅ Explanation

Python prints the final value stored in result.

Output:

24

๐ŸŽฏ Final Output
24




Python Coding challenge - Day 1191| What is the output of the following Python Code?

 


Code Explanation:

๐Ÿ”น 1. Defining a Generator Function
def gen():
✅ Explanation:
A function named gen is created.
Since it contains the yield keyword, it becomes a generator function.
A generator does not execute immediately when it is defined.

Current state:

Generator function created.

๐Ÿ”น 2. Starting the for Loop
for i in range(3):
✅ Explanation:

range(3) generates numbers from 0 to 2.

Values of i will be:

0
1
2

Visual:

Iteration 1 → i = 0

Iteration 2 → i = 1

Iteration 3 → i = 2

๐Ÿ”น 3. Using yield
yield i * 2
✅ Explanation:
yield returns a value and pauses the function.
Unlike return, the function does not end.
It remembers its current state and continues from the same place when next() is called again.

Formula:

Yield Value = i × 2

๐Ÿ”น 4. Creating the Generator Object
g = gen()
✅ Explanation:

Calling gen() does not execute the function.

Instead, it creates a generator object.

Current state:

g

<generator object>

The loop has not started yet.

๐Ÿ”น 5. First next() Call
print(next(g))
✅ Explanation:

next(g) starts executing the generator.

Current value:

i = 0

Calculation:

0 * 2

Result:

0

yield returns:

0

The generator pauses here.

Output:

0

๐Ÿ”น 6. Generator Pauses

After returning 0, the generator does not restart.

It pauses at:

yield i * 2

Current position:

Waiting for next() call

๐Ÿ”น 7. Second next() Call
print(next(g))
✅ Explanation:

The generator resumes from where it stopped.

Loop continues with:

i = 1

Calculation:

1 * 2

Result:

2

yield returns:

2

Generator pauses again.

Output:

2

๐Ÿ”น 8. Current Generator State

The generator has processed:

i = 0 ✅

i = 1 ✅

Still remaining:

i = 2

If we call:

print(next(g))

Output:

4

because:

2 * 2 = 4

๐ŸŽฏ Final Output
0
2

Saturday, 18 July 2026

50 ML Projects To Understand LLMs: Investigate transformer mechanisms through data analysis, visualization, and experimentation by Mike X Cohen

 

Book Review: 50 ML Projects to Understand LLMs — Learn Large Language Models by Building, Not Just Reading

Author: Mike X Cohen

Large Language Models (LLMs) have transformed artificial intelligence, but understanding how they actually work can be overwhelming. If you've ever wondered what happens inside transformers, attention mechanisms, embeddings, or tokenization, "50 ML Projects to Understand LLMs" by Mike X Cohen provides a refreshing, practical approach.

Instead of focusing on theory alone, this book teaches readers through 50 hands-on machine learning projects that encourage experimentation, visualization, and data-driven exploration. It's an excellent resource for developers, data scientists, AI enthusiasts, and students who want to move beyond simply using LLM APIs and start understanding the technology behind them.

Hard Copy: 50 ML Projects To Understand LLMs: Investigate transformer mechanisms through data analysis, visualization, and experimentation

Why This Book Stands Out

One of the biggest strengths of this book is its project-based learning style. Every concept is supported with practical experiments that allow readers to observe how transformer models behave rather than simply reading mathematical explanations.

The projects gradually build intuition about:

  • Transformer architecture

  • Attention mechanisms

  • Token embeddings

  • Positional encoding

  • Self-attention visualization

  • Model behavior analysis

  • Representation learning

  • Data preprocessing

  • Neural network experimentation

  • Performance evaluation

Rather than treating LLMs as "black boxes," the book encourages curiosity by letting readers investigate each component independently.

Learning Through Experimentation

Unlike traditional AI textbooks filled with equations, this book emphasizes learning by doing.

Readers are encouraged to:

  • Run experiments

  • Modify model parameters

  • Compare outputs

  • Visualize attention weights

  • Analyze embedding spaces

  • Observe how architectural changes affect predictions

This interactive style helps develop an intuitive understanding that is difficult to gain from theory alone.

Perfect for Intermediate Learners

The book assumes readers already have basic knowledge of:

  • Python programming

  • Machine Learning fundamentals

  • NumPy and data analysis

  • Neural networks

If you're already comfortable with these topics and want to understand modern AI models more deeply, this book serves as an excellent bridge into transformer-based architectures.

What You'll Learn

Throughout the projects, readers gain practical insights into:

  • How transformers process language

  • Why attention mechanisms are so powerful

  • How embeddings capture semantic meaning

  • Techniques for visualizing model internals

  • Experimental methods for understanding neural networks

  • Practical workflows used in modern AI research

Rather than memorizing concepts, you'll learn to investigate them yourself.

Strengths

✅ 50 practical, hands-on projects

✅ Excellent visual explanations

✅ Focus on experimentation instead of memorization

✅ Helps build intuition behind transformer models

✅ Suitable for researchers, developers, and AI enthusiasts

Things to Keep in Mind

This isn't a beginner's introduction to Python or machine learning. Readers completely new to AI may find some projects challenging without prior knowledge of linear algebra, neural networks, and machine learning basics.

However, for anyone already familiar with Python and ML fundamentals, the learning curve is rewarding.

Who Should Read This Book?

This book is ideal for:

  • Machine Learning Engineers

  • AI Researchers

  • Python Developers

  • Data Scientists

  • Graduate Students

  • Anyone curious about how Large Language Models actually work

If you're building applications with GPT-style models and want to understand what's happening behind the scenes, this book offers a practical path forward.

Final Verdict

⭐ Rating: 4.8/5

"50 ML Projects to Understand LLMs" succeeds because it transforms complex AI concepts into engaging experiments. Rather than overwhelming readers with abstract theory, Mike X Cohen provides a structured, hands-on journey into the mechanics of transformer models.

As Large Language Models continue to reshape software development and artificial intelligence, understanding their foundations has become increasingly valuable. This book is an excellent investment for readers who believe the best way to learn is by building, experimenting, and discovering.

Get the book here: 50 ML Projects To Understand LLMs: Investigate transformer mechanisms through data analysis, visualization, and experimentation by Mike X Cohen

Extending Excel with Python and R: Unlock the potential of analytics languages for advanced data manipulation and visualization

 


Extending Excel with Python and R: Unlock Advanced Data Analysis, Automation, and Visualization Beyond Traditional Spreadsheets

Introduction

Microsoft Excel has been the world's most widely used spreadsheet application for decades, helping professionals organize data, perform calculations, create reports, and build dashboards. However, as organizations generate larger datasets and demand more advanced analytics, Excel alone can struggle with statistical modeling, machine learning, automation, and sophisticated data visualization.

This is where Python and R become game changers. Python excels in automation, data engineering, artificial intelligence, and machine learning, while R is renowned for statistical computing, exploratory data analysis, and high-quality visualizations. By integrating these powerful programming languages with Excel, analysts can dramatically extend Excel's capabilities without abandoning the familiar spreadsheet environment. Recent advances in tools and workflows make combining Excel with Python and R increasingly practical for data professionals.

Extending Excel with Python and R: Unlock the Potential of Analytics Languages for Advanced Data Manipulation and Visualization, written by Steven Sanderson and David Kun, is a practical guide published by Packt in April 2024. Across 344 pages, the book teaches readers how to combine Excel with Python and R to automate repetitive tasks, perform advanced statistical analysis, create professional visualizations, integrate APIs, and build more efficient data workflows.


Get It Free: https://support.microsoft.com/en-US/Excel/python/introduction-to-python-in-excel

Why Extend Excel with Python and R?

Excel is excellent for many business tasks, but advanced analytics often require more powerful programming tools.

By integrating Python and R with Excel, you can:

  • Automate repetitive spreadsheet tasks

  • Perform advanced statistical analysis

  • Build machine learning models

  • Create publication-quality visualizations

  • Process large datasets more efficiently

  • Connect Excel to external APIs

  • Develop reproducible analytical workflows

This combination allows professionals to keep Excel as a familiar interface while leveraging the strengths of modern data science ecosystems.


Book Overview

The book focuses on practical integration rather than theory alone.

Readers learn how to:

  • Read and write Excel files

  • Automate spreadsheet workflows

  • Use Python and R for analytics

  • Generate advanced charts

  • Connect Excel with APIs

  • Perform statistical analysis

  • Execute VBA through Python and R

  • Build reusable automation scripts

Every chapter combines explanations with hands-on examples that can be applied to real business scenarios.


Reading and Writing Excel Files

The book begins with the fundamentals of working with spreadsheets programmatically.

Topics include:

  • Importing Excel workbooks

  • Reading multiple worksheets

  • Managing workbook structures

  • Writing processed data back to Excel

  • Handling large spreadsheets efficiently

Readers learn to use popular Python and R libraries for seamless spreadsheet interaction.


Data Manipulation with Python

Python provides powerful tools for transforming and analyzing spreadsheet data.

The book explores:

  • Pandas DataFrames

  • Data cleaning

  • Filtering

  • Aggregation

  • Data transformation

  • Merging datasets

  • Handling missing values

These techniques simplify tasks that would otherwise require complex Excel formulas or manual operations.


Statistical Analysis with R

R has long been one of the leading languages for statistics.

Readers learn how to perform:

  • Exploratory Data Analysis (EDA)

  • Statistical summaries

  • Hypothesis testing

  • Time series analysis

  • Data modeling

  • Predictive analytics

Integrating R with Excel enables analysts to apply sophisticated statistical methods while maintaining familiar spreadsheet workflows.


Advanced Data Visualization

One of the book's major strengths is its emphasis on professional visualization.

Readers create charts using:

  • ggplot2 in R

  • Matplotlib in Python

  • Customized plots

  • Interactive visualizations

  • Business reports

These libraries produce publication-quality graphics that extend far beyond Excel's native charting capabilities.


Automating Excel Workflows

Automation saves countless hours in repetitive reporting tasks.

The book demonstrates how to:

  • Automate report generation

  • Schedule spreadsheet processing

  • Execute repetitive calculations

  • Refresh data automatically

  • Build reusable automation scripts

Automation improves productivity while reducing manual errors.


Integrating VBA with Python and R

Many organizations still rely on Excel VBA.

Rather than replacing VBA completely, the book explains how to combine it with Python and R.

Topics include:

  • Calling Python from Excel

  • Calling R from Excel

  • Executing VBA macros

  • Hybrid automation workflows

  • Improving legacy Excel solutions

This approach helps organizations modernize existing spreadsheet systems without rebuilding them from scratch.


Exploratory Data Analysis (EDA)

Exploratory Data Analysis is essential before building predictive models.

The book introduces techniques such as:

  • Summary statistics

  • Distribution analysis

  • Correlation analysis

  • Pivot table exploration

  • Trend identification

  • Outlier detection

These methods help uncover hidden insights within business data.


Time Series Analysis

Many organizations work with chronological data.

Readers learn techniques for:

  • Forecasting

  • Trend analysis

  • Seasonal decomposition

  • Time-based visualization

  • Financial analysis

Time series capabilities make the book valuable for finance, operations, and business intelligence professionals.


API Integration

Modern analytics frequently require external data sources.

The book demonstrates how to:

  • Access web APIs

  • Import online datasets

  • Automate data retrieval

  • Combine external data with Excel

  • Build dynamic reporting systems

API integration enables Excel workbooks to stay current with real-time information.


Practical Business Applications

The techniques covered support many real-world use cases.

Financial Analysis

Automating financial reports and forecasting.

Sales Analytics

Analyzing customer and revenue trends.

Business Intelligence

Creating interactive dashboards.

Data Science

Preparing datasets for machine learning.

Research

Performing statistical analysis and visualization.

Operations

Automating recurring Excel-based workflows.


Skills You Will Develop

By reading this book, you will strengthen expertise in:

  • Microsoft Excel

  • Python Programming

  • R Programming

  • Data Analysis

  • Data Manipulation

  • Exploratory Data Analysis (EDA)

  • Statistical Computing

  • Data Visualization

  • Pandas

  • ggplot2

  • Matplotlib

  • Excel Automation

  • VBA Integration

  • API Integration

  • Time Series Analysis

  • Business Intelligence

  • Workflow Automation

  • Data Science

These skills are valuable for analysts, developers, and data professionals working with spreadsheet-based workflows.


Who Should Read This Book?

This book is ideal for:

Data Analysts

Expanding Excel with advanced analytics.

Business Analysts

Automating reporting and dashboards.

Financial Analysts

Performing statistical and forecasting analysis.

Data Scientists

Integrating programming workflows with Excel.

Excel Power Users

Learning Python and R without abandoning spreadsheets.

Students

Developing practical data analysis skills.

Readers should have a basic understanding of Excel, while introductory familiarity with Python or R is helpful but not essential.


Why This Book Stands Out

Several features make this book particularly valuable:

  • Practical, project-based approach

  • Covers both Python and R integration

  • Strong focus on Excel automation

  • Explains statistical analysis techniques

  • Includes modern visualization libraries

  • Demonstrates API connectivity

  • Suitable for beginners and intermediate learners

  • Bridges traditional spreadsheets with modern data science workflows


Career Benefits

The knowledge gained from this book supports careers such as:

  • Data Analyst

  • Business Intelligence Analyst

  • Financial Analyst

  • Data Scientist

  • Business Analyst

  • Reporting Analyst

  • Excel Developer

  • Automation Engineer

  • Analytics Consultant

  • Operations Analyst

As organizations increasingly combine spreadsheets with modern analytics platforms, professionals who can integrate Excel with Python and R have a significant competitive advantage.


Hard Copy: Extending Excel with Python and R: Unlock the potential of analytics languages for advanced data manipulation and visualization

Kindle: Extending Excel with Python and R: Unlock the potential of analytics languages for advanced data manipulation and visualization

Conclusion

Extending Excel with Python and R is an excellent resource for professionals who want to move beyond traditional spreadsheet capabilities and embrace modern data analytics. By combining Excel with the analytical power of Python and R, the book demonstrates how to automate workflows, perform sophisticated statistical analysis, create compelling visualizations, and build scalable reporting solutions.

By covering:

  • Excel Automation

  • Python Programming

  • R Programming

  • Data Manipulation

  • Exploratory Data Analysis

  • Statistical Computing

  • Data Visualization

  • Pandas

  • ggplot2

  • Matplotlib

  • VBA Integration

  • API Connectivity

  • Time Series Analysis

  • Business Intelligence

  • Workflow Automation

  • Advanced Spreadsheet Analytics

the book equips readers with practical skills that bridge the gap between traditional spreadsheet work and modern data science.

Whether you are a data analyst, financial professional, business analyst, Excel power user, or aspiring data scientist, Extending Excel with Python and R provides a practical roadmap for transforming Excel into a powerful analytics platform capable of handling today's increasingly complex data challenges.

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (311) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (31) Azure (12) BI (10) Books (283) Bootcamp (12) C (78) C# (12) C++ (83) cloud (1) Course (87) Coursera (300) Cybersecurity (32) data (9) Data Analysis (40) Data Analytics (28) data management (16) Data Science (397) Data Strucures (23) Deep Learning (200) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (24) Finance (11) flask (4) flutter (1) FPL (17) Generative AI (76) Git (12) Google (53) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (353) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (15) PHP (20) Projects (34) Python (1405) Python Coding Challenge (1202) Python Mathematics (5) Python Mistakes (51) Python Quiz (575) Python Tips (26) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (20) SQL (52) Udemy (18) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)