0% found this document useful (0 votes)
12 views

Assignment 1 AI (Ashraf)

The document outlines the evolution of Artificial Intelligence (AI) from its inception in the 1950s to its current applications across various industries. Key milestones include the introduction of the Turing Test, the development of expert systems, and advancements in machine learning and deep learning techniques. Real-world applications of AI are highlighted in healthcare, education, and transportation, demonstrating its impact on efficiency and innovation.

Uploaded by

saad aslam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Assignment 1 AI (Ashraf)

The document outlines the evolution of Artificial Intelligence (AI) from its inception in the 1950s to its current applications across various industries. Key milestones include the introduction of the Turing Test, the development of expert systems, and advancements in machine learning and deep learning techniques. Real-world applications of AI are highlighted in healthcare, education, and transportation, demonstrating its impact on efficiency and innovation.

Uploaded by

saad aslam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Q1: Artificial Intelligence has evolved significantly over the years.

Discuss the key


milestones in its development and provide examples of how these milestones have
shaped real-world applications.

Key Milestones in the Evolution of AI:

1. 1950s - Birth of AI:


o Alan Turing and the Turing Test (1950): Alan Turing proposed the idea of machine
intelligence, introducing a test to evaluate if a machine could imitate human-like
responses. This concept laid the foundation for AI research and its focus on reasoning and
problem-solving.
o John McCarthy's coining of "Artificial Intelligence" (1956): AI was formally
established as a discipline at the Dartmouth Conference. McCarthy’s vision emphasized
creating machines that could think and learn, steering research into intelligent systems.
2. 1960s - Early Research and Expert Systems:
o ELIZA (1966): This NLP program simulated human conversation, demonstrating the
potential of computers to interact with humans in natural language.
o DENDRAL and MYCIN (1960s): Early expert systems used AI to mimic human
expertise in domains like medical diagnosis and chemical analysis, influencing fields like
diagnostics and drug discovery.
3. 1980s - Neural Networks and Backpropagation:
o Re-emergence of Neural Networks (1986): Geoffrey Hinton's work on backpropagation
algorithms enabled neural networks to learn more efficiently, revolutionizing tasks like
pattern recognition.
4. 1990s - Machine Learning and Computational Power:
o IBM's Deep Blue vs. Garry Kasparov (1997): Deep Blue’s victory over the world chess
champion highlighted the potential of AI in strategy and decision-making, inspiring
advancements in computational AI.
o Support Vector Machines (SVMs): These algorithms became powerful tools for
classification tasks, supporting applications like image and text recognition.
5. 2000s to Present - Deep Learning and AI Applications:
o Deep Learning and Convolutional Neural Networks (CNNs): Techniques like CNNs
revolutionized computer vision, with landmark models such as AlexNet achieving
groundbreaking success in object recognition tasks.
o Generative AI: Models like OpenAI's GPT and DALL-E enabled new forms of creativity,
from text generation to art creation.

Real-World Impact:

 Healthcare: AI systems, such as IBM Watson, assist doctors in diagnosing diseases and
suggesting treatments.
 Autonomous Vehicles: Self-driving technologies (e.g., Tesla) use AI for decision-making,
reducing human errors on roads.
 E-commerce: AI enables personalized recommendations on platforms like Amazon and Netflix,
enhancing user experience and boosting revenue.
Q2: AI is transforming industries like healthcare, education, and transportation.
Discuss with examples how AI is improving efficiency and innovation in these sectors.

1. Healthcare:
o Disease Diagnosis: Systems like DeepMind’s AI for eye disease detection improve
diagnostic accuracy and speed.
o Personalized Medicine: AI models analyze genetic and medical data to recommend
tailored treatment plans, enhancing patient outcomes.
o Surgical Assistance: AI-powered robots, such as Intuitive Surgical's da Vinci system,
enable minimally invasive surgeries with enhanced precision.
2. Education:
o Personalized Learning: Platforms like Khan Academy adapt content to student progress,
fostering better understanding and retention.
o Automated Grading: Tools like Gradescope save time for educators by grading
assignments consistently and fairly.
o AI Tutors: Systems like Squirrel AI simulate one-on-one tutoring, offering students
interactive and accessible learning experiences.
3. Transportation:
o Autonomous Vehicles: AI in Tesla and Waymo enables vehicles to navigate using real-
time sensor data.
o Traffic Optimization: Smart city AI systems reduce congestion by predicting traffic
patterns and optimizing signals.
o Route Planning: Tools like Google Maps use AI to provide real-time traffic updates,
improving logistics efficiency.

Additional Perspective:
While AI enhances efficiency, ethical concerns like data privacy in healthcare and cost barriers in
education require careful management.

Q3: Supervised and unsupervised learning are two primary types of machine learning.
Compare their methodologies and discuss how each is applied in solving real-world
problems like spam detection and customer segmentation.

1. Supervised Learning:
o Methodology: Trains models on labeled data, where the input-output relationship is
explicitly defined. It predicts outcomes for new data.
o Applications:
 Spam Detection: Models like Naive Bayes classify emails as spam or not based
on labeled training data.
 Fraud Detection: Historical transaction data labeled as "fraudulent" or
"legitimate" helps predict future fraud.
2. Unsupervised Learning:
o Methodology: Identifies patterns in unlabeled data by clustering or associating similar
elements.
o Applications:
 Customer Segmentation: Algorithms like K-means group customers by behavior
to enable targeted marketing.
 Anomaly Detection: Models identify unusual network activity that may indicate
security breaches.

Key Differences:

 Supervised Learning: Focused on prediction, requiring labeled data.


 Unsupervised Learning: Focused on exploration, working with unlabeled data.

Emerging Approach: Semi-supervised learning bridges the gap by using a mix of labeled and unlabeled
data, combining the strengths of both.

Q4: Explain the concept of training and testing datasets in machine learning. Why is it
important to split data appropriately? Support your answer with a real-world use case.

1. Training Dataset:
o Used to train the model, helping it learn patterns and relationships from the data.
2. Testing Dataset:
o Separate data used to evaluate the model's performance, ensuring it generalizes well to
new, unseen data.
3. Importance of Splitting Data:
o Prevents Overfitting: Models trained on the same data they’re evaluated on might
memorize rather than generalize, reducing real-world effectiveness.
o Ensures Robust Evaluation: Separate test data provides an unbiased assessment of
model performance.

Real-World Use Case:

 Predicting Housing Prices:


In housing price prediction, data is split into training (e.g., 80%) and testing (e.g., 20%) sets. The
training set builds the model, while the test set evaluates its ability to predict prices for unseen
homes. Techniques like cross-validation further enhance reliability.

Q5: Define knowledge representation and explain its importance in Artificial


Intelligence. Differentiate between the types of knowledge, and describe knowledge
representation techniques such as Semantic Nets, Frames, and Rules.

1. Knowledge Representation (KR):


o Encodes information about the world in a structured form that machines can interpret to
perform reasoning and decision-making.
2. Importance of KR in AI:
o Enables Reasoning: Supports tasks like decision-making and problem-solving.
o Facilitates Learning: Structures knowledge for easier application to new scenarios.
3. Types of Knowledge:
o Declarative: Facts (e.g., "Water boils at 100°C").
o Procedural: Skills and processes (e.g., "How to drive a car").
o
Meta-Knowledge: Knowledge about knowledge (e.g., reliability of sources).
4. Knowledge Representation Techniques:
o Semantic Nets: Nodes represent concepts; edges define relationships (e.g., "Dog is a type
of Animal").
o Frames: Organize information into slots (e.g., a "Car" frame with slots for "color,"
"make").
o Rules: Use if-then logic for decision-making (e.g., "If it’s raining, carry an umbrella").

Example Application:

 A semantic net for animals can represent hierarchy and relationships, a frame for a house
organizes its attributes, and rules control a smart home system’s responses to user preferences.

Q6: Procedural knowledge involves knowing "how" to perform tasks. Discuss its role in
AI and provide an example of a procedural knowledge system, such as a cooking
assistant or robotic arm.

1. Definition of Procedural Knowledge:


Procedural knowledge refers to "knowing how" to perform tasks or processes, encompassing steps
required to complete them. Unlike declarative knowledge, which represents facts, procedural knowledge
is action-oriented and sequential.

2. Role in AI:

 Automation of Processes: Enables AI to execute tasks in defined sequences, automating


repetitive or complex processes.
 Dynamic Adjustments: Allows AI to adapt actions based on changing inputs or environments.
 Interactive Systems: Underpins systems like virtual assistants, enabling real-time, responsive
interactions.

3. Example - Robotic Arm for Manufacturing:

 Application: A robotic arm in an assembly line performs tasks such as welding, assembling, or
quality checking.
 Process:
o Input: Sensors detect object positions and environmental conditions.
o Procedure: The arm calculates optimal paths for movement and executes precise actions.
o Output: Tasks like assembling components are completed efficiently.
 Benefits: Reduces human error, enhances speed and consistency, and supports continuous
operation.

4. Example - AI Cooking Assistant:

 Scenario: A cooking assistant guides users through recipes step-by-step.


 Features:
o Adjusts instructions dynamically based on user input (e.g., substituting ingredients for
dietary needs).
oSuggests optimal cooking times and temperatures for specific conditions.
 Outcome: Personalizes and simplifies meal preparation.

Q7: Explain the role of meta-knowledge in AI systems. Discuss its application in expert
systems, using an example like medical diagnosis or legal advice.

1. Definition of Meta-Knowledge:
Meta-knowledge is "knowledge about knowledge." It involves evaluating the reliability, importance, and
applicability of information within a system to enhance decision-making.

2. Role in AI Systems:

 Efficient Reasoning: Helps systems prioritize crucial information during problem-solving.


 Self-Improvement: Enables AI to refine decision-making strategies by analyzing what works
best in various contexts.
 Conflict Resolution: Resolves inconsistencies by assessing the credibility of conflicting data or
rules.

3. Application in Expert Systems:

 Medical Diagnosis Example:


o Role: Systems like MYCIN use meta-knowledge to prioritize diagnostic information
based on reliability (e.g., lab test accuracy vs. patient-reported symptoms).
o Functionality: When conflicting test results occur, the system weighs the most reliable
sources to suggest diagnoses.
o Outcome: Enhanced diagnostic precision and confidence in recommendations.
 Legal Advice Example:
o Scenario: A legal AI system evaluates precedents based on relevance and reliability.
o Benefit: Produces accurate, context-sensitive recommendations tailored to specific legal
cases.

Q8: Dijkstra’s Algorithm is fundamental for solving shortest-path problems. Discuss its
working with a step-by-step explanation and provide an example from transportation or
network routing systems.

1. Overview of Dijkstra's Algorithm:


Dijkstra’s Algorithm finds the shortest path from a source node to all other nodes in a weighted graph. It
is widely used in transportation and communication networks.

2. Working of the Algorithm (Step-by-Step):

1. Initialization:
o Assign an initial distance of 0 to the source node and infinity to all others.
o Mark all nodes as unvisited.
2. Visit the Nearest Node:
o Select the unvisited node with the smallest tentative distance and mark it as visited.
3. Update Neighboring Nodes:
o For each unvisited neighbor, calculate the distance from the source. Update it if the
calculated distance is smaller than the current value.
4. Repeat:
o Continue until all nodes are visited, or the shortest path to the destination is confirmed.

3. Example - Transportation (City Navigation):

 Scenario: Cities are represented as nodes, and road distances as edge weights.
 Objective: Find the shortest route from City A to City E.
 Result: Dijkstra’s Algorithm identifies the optimal path (e.g., A → B → E) and calculates the
total distance.

4. Benefits in Transportation:

 Provides efficient route planning, reducing travel time.


 Adapts to real-time data like traffic conditions.

Q9: Many real-world systems use variations of Dijkstra’s Algorithm. Discuss its role in
GPS navigation, highlighting how it handles weighted graphs to find optimal routes.

1. Dijkstra's Algorithm in GPS Navigation:

 Graph Representation:
o Nodes: Represent intersections or locations.
o Edges: Represent roads, with weights indicating travel time, distance, or congestion.
 Functionality: Computes the shortest or fastest route based on dynamic inputs.

2. Handling Weighted Graphs:

 Dynamic Weights: Edge weights are updated in real-time based on factors such as traffic density,
road closures, or weather.
 Real-Time Optimization: The system recalculates routes dynamically to ensure users follow the
most efficient path.

3. Application Example:

 Scenario: A driver traveling from Point A to Point D.


o Input: Traffic updates increase the weight of congested routes.
o Output: The GPS suggests an alternative path (e.g., A → B → D instead of A → C → D).

4. Advantages in Real-World Systems:

 Reduces delays by adapting to current conditions.


 Improves user experience with reliable, accurate navigation.
Q10: State-space representation is central to problem-solving in AI. Using a practical
example, such as a puzzle or maze, explain how states and actions are defined and
explored.

1. Definition of State-Space Representation:


A state-space is a mathematical model representing all possible configurations of a system. Each state
corresponds to a unique condition, and actions define transitions between states.

2. Components:

 Initial State: Starting configuration (e.g., maze entry).


 Goal State: Desired configuration (e.g., maze exit).
 State Transition: Action leading from one state to another (e.g., moving up, down, left, right).

3. Example - Solving a Maze:

 States: Points in the maze (e.g., intersections, dead ends).


 Actions: Movements between points.
 Solution Process:
o Start at the initial state and use a search strategy (e.g., Breadth-First Search) to explore
states systematically.
o Reach the goal state by finding the shortest or optimal path.

4. Benefits of State-Space Representation:

 Simplifies complex problems by organizing them into manageable states.


 Facilitates systematic exploration using algorithms like BFS or DFS.

5. Real-World Application - Robotic Navigation:

 Scenario: A warehouse robot defines states as locations and actions as movements.


 Outcome: Ensures efficient navigation to retrieve and deliver items accurately.

Q11: Breadth-First Search (BFS) and Depth-First Search (DFS) are fundamental search
techniques. Compare their efficiency and applicability with examples like social
network analysis or pathfinding.

1. Overview of BFS and DFS:

 Breadth-First Search (BFS):


o Explores all neighbors of a node before moving to the next level.
o Uses a queue to manage nodes.
o Ideal for finding the shortest path in unweighted graphs.
 Depth-First Search (DFS):
o Explores as deep as possible along each branch before backtracking.
o Uses a stack (or recursion) for node management.
o Suited for exploring all possible solutions or detecting cycles.

2. Key Differences:

Feature BFS DFS


Order of Traversal Level-by-level traversal Depth-first exploration
Data Structure Queue Stack or recursion
Time Complexity O(V+E)O(V + E) O(V+E)O(V + E)
Space Complexity O(V)O(V) O(V)O(V) (recursion depth)
Use Case Shortest path problems Exploring all solutions, detecting cycles

3. Applications with Examples:

 Social Network Analysis:


o BFS: Finds shortest paths (e.g., degrees of separation on Facebook).
Example: Identifying mutual friends or shortest connections in LinkedIn.
o DFS: Detects strongly connected components in networks.
Example: Analyzing influencer networks or cliques in social media.
 Pathfinding in Graphs:
o BFS: Efficient for finding shortest paths in unweighted graphs.
Example: Solving mazes or navigation in grid-like maps.
o DFS: Explores all possible paths in problems requiring backtracking.
Example: Finding all routes in a labyrinth or solving Sudoku puzzles.

4. Comparative Efficiency:

 BFS: Optimal for shortest path and level-based exploration but uses more memory.
 DFS: Efficient for exhaustive exploration but can fail in infinite loops without proper checks.

5. Conclusion:

 Use BFS for shortest path problems and breadth exploration.


 Use DFS for exhaustive search tasks or when memory optimization is necessary.

Q12: Neural networks are inspired by the human brain. Discuss how their structure
(neurons, layers, weights) mimics biological systems. Provide an example of how this
analogy applies to pattern recognition.

1. Structure of Neural Networks:

 Neurons:
o Analogous to biological neurons, they process inputs and produce outputs.
o Inputs are weighted and passed through an activation function to determine the output.
 Layers:
o Input Layer: Receives raw data (e.g., pixel values).
o Hidden Layers: Extract and transform features through complex computations.
o Output Layer: Produces predictions or classifications (e.g., recognizing digits).
 Weights:
o Represent the importance of connections, similar to synaptic strengths in the brain.

2. Biological Inspiration:

 Biological Neuron: Receives signals (via dendrites), processes them (in the soma), and sends
output (via axons).
 Artificial Neuron: Simulates this process mathematically using weighted sums and activation
functions.

3. Example - Pattern Recognition:

 Scenario: Recognizing handwritten digits.


o Input Layer: Pixel intensities of a digit image.
o Hidden Layers: Detect edges, curves, and shapes (features).
o Output Layer: Classifies the digit (e.g., '7').
 Neural Network Used: Convolutional Neural Networks (CNNs) mimic biological vision systems
to achieve high accuracy in image recognition.

Q13: Explain the backpropagation algorithm used in training neural networks. Discuss
how gradient descent is applied and why it is critical for minimizing error.

1. Backpropagation Algorithm:

 Definition: A supervised learning algorithm that minimizes error by adjusting weights and biases
based on the gradient of the error function.
 Steps:
1. Forward Pass: Input data is passed through the network to compute predictions. The
error is calculated as the difference between predictions and true labels.
2. Backward Pass: The error is propagated backward to compute gradients for each weight.
3. Weight Update: Weights are updated using gradient descent to minimize the error.

2. Gradient Descent:

 Definition: An optimization technique to minimize the cost function (error).


 Process:
o Gradients (partial derivatives) of the error with respect to weights are computed.
o Weights are updated in the direction opposite to the gradient.
o The learning rate determines the step size of updates.

3. Importance:

 Error Minimization: Ensures the network iteratively learns to make better predictions.
 Efficient Learning: Distributes error across layers, enabling deep networks to train effectively.
Q14: Activation functions (ReLU, Sigmoid, Tanh) play a key role in neural networks.
Compare these functions and discuss how the choice of activation impacts real-world
applications like image classification.

1. Role of Activation Functions:

 Introduce non-linearity to enable neural networks to learn complex patterns.


 Decide whether a neuron "fires" (produces output) based on the weighted sum of its inputs.

2. Comparison of Activation Functions:

Function Formula Range Characteristics Applications


Sigmoid σ(x)=11+e−x\sigma(x) = \frac{1}{1 + (0, 1) Smooth curve; prone Binary
e^{-x}} to vanishing classification.
gradients.
Tanh tanh⁡(x)=ex−e−xex+e−x\tanh(x) = (-1, 1) Zero-centered; better RNNs,
\frac{e^x - e^{-x}}{e^x + e^{-x}} gradient flow. sentiment
analysis.
ReLU f(x)=max⁡(0,x)f(x) = \max(0, x) [0, ∞) Simple; avoids Image
vanishing gradients classification,
for positive inputs. CNNs.

3. Real-World Impact:

 Image Classification:
o ReLU: Dominates CNNs due to its simplicity and ability to handle high-dimensional data.
o Sigmoid/Tanh: Used in earlier architectures or specific tasks like sequence modeling.

4. Choosing an Activation Function:


Depends on the network’s architecture and task requirements.

 ReLU: Preferred for deep networks.


 Sigmoid/Tanh: Suitable for binary or sequential tasks.

Q15: Discuss the role of Python libraries like NumPy, Pandas, and Matplotlib in AI and
machine learning. Provide use cases for each.

1. Role of Python Libraries in AI and ML:


These libraries streamline data manipulation, computation, and visualization, forming the foundation for
AI workflows.

2. Overview of Libraries and Use Cases:

 NumPy:
o Role: Handles multi-dimensional arrays and efficient mathematical operations.
o Use Cases:
 Matrix computations for recommendation systems.
 Tensor manipulation for neural networks.
 Example: Computing eigenvalues in PCA.
 Pandas:
o Role: Simplifies data preprocessing with data structures like DataFrames.
o Use Cases:
 Cleaning datasets for ML.
 Analyzing customer behavior in e-commerce.
 Example: Merging and cleaning sales data for forecasting.
 Matplotlib:
o Role: Creates customizable data visualizations.
o Use Cases:
 Plotting training loss in neural networks.
 Visualizing relationships in exploratory data analysis.
 Example: Scatter plot of housing prices vs. square footage.

3. Combined Use Case:


Predicting housing prices using NumPy (data scaling), Pandas (cleaning), and Matplotlib (visualization).

4. Conclusion:
These libraries are indispensable for building, analyzing, and visualizing AI models efficiently.

Q16: Explain the importance of Python's data structures (lists, dictionaries, tuples) in
handling complex data for AI algorithms. Provide scenarios where each data structure
is most appropriate.

1. Importance of Python Data Structures in AI:


Python's built-in data structures simplify organizing and managing data essential for AI algorithms,
aiding in tasks like feature storage, mapping relationships, and efficient data processing.

2. Overview and Use Cases:

 Lists:
o Definition: Ordered, mutable sequences.
o Use Case: Storing sequential data such as activation values in neural network layers.
o Example: [height, weight, age] for individuals in a dataset.
 Dictionaries:
o Definition: Key-value pairs for quick data retrieval.
o Use Case: Mapping feature names to their values or storing hyper parameters.
o Example: {‘height’: 175, ‘weight’: 70, ‘age’: 30}.
 Tuples:
o Definition: Ordered, immutable sequences.
o Use Case: Representing constant data like geographic coordinates or RGB values.
o Example: (255, 0, 0) for red in image processing.
3. Comparative Scenarios:

 Lists: Dynamic data during iterative tasks (e.g., tracking loss values).
 Dictionaries: Creating labeled datasets for AI models.
 Tuples: Immutable parameters like fixed labels or coordinates.

Conclusion: These data structures enhance flexibility and efficiency in AI tasks, catering to diverse data
management needs.

Q17: Write a Python program to implement the Breadth-First Search (BFS) algorithm.
Apply it to a graph and explain the output.

Python Code:

Python Code:

python

from collections import deque

def bfs(graph, start_node):


visited = set()
queue = deque([start_node])
bfs_order = []

while queue:
node = queue.popleft()
if node not in visited:
visited.add(node)
bfs_order.append(node)
queue.extend(graph[node])

return bfs_order

# Graph as an adjacency list


graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [],
'E': ['F'],
'F': []
}

# BFS Traversal
result = bfs(graph, 'A')
print("BFS Traversal Order:", result)

Output Explanation:

 Graph Structure: Nodes represent entities, and edges represent their connections.
 Output: BFS starts at 'A' and explores all neighbors before moving deeper:
BFS Traversal Order: ['A', 'B', 'C', 'D', 'E', 'F'].
This demonstrates level-by-level traversal.
Q18: Write a Python program to demonstrate the use of control structures (if-else,
loops) in solving real-world problems, such as calculating tax brackets.

Python Code:

Python

def calculate_tax(income):
if income <= 10000:
tax = 0
elif income <= 20000:
tax = 0.1 * (income - 10000)
elif income <= 50000:
tax = 0.1 * 10000 + 0.2 * (income - 20000)
else:
tax = 0.1 * 10000 + 0.2 * 30000 + 0.3 * (income - 50000)
return tax

# Test incomes
incomes = [5000, 15000, 30000, 80000]
for income in incomes:
print(f"Income: {income}, Tax: {calculate_tax(income):.2f}")

Output Explanation:

 Scenario: Calculates tax based on income brackets.


 Example Outputs:
o Income = 15,000 → Tax = 500.00
o Income = 80,000 → Tax = 13,000.00
 Control Structures:
o If-else: Determines the tax rate.
o Loop: Processes multiple incomes.

Q19: Discuss the role of NumPy in handling multidimensional arrays and mathematical
operations. Provide examples of operations like slicing, broadcasting, and matrix
computations.

1. Role of NumPy:
NumPy handles multidimensional arrays efficiently and supports fast mathematical computations,
making it vital for AI tasks like tensor operations and matrix algebra.

2. Examples:

 Slicing: Extracts subsets of arrays.

python

import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(arr[:, 1]) # Output: [2, 5, 8]
 Broadcasting: Matches shapes of arrays for element-wise operations.

Python

a = np.array([1, 2, 3])
print(a * 2) # Output: [2, 4, 6]

 Matrix Computations:

python

matrix1 = np.array([[1, 2], [3, 4]])


matrix2 = np.array([[5, 6], [7, 8]])
print(np.dot(matrix1, matrix2)) # Output: [[19, 22], [43, 50]]

Conclusion: NumPy simplifies data manipulation and computations in AI workflows, improving speed
and accuracy.

Q20: Explain how Pandas simplifies data analysis tasks. Write a program to load a
dataset, clean missing values, and calculate basic statistics.

Python Code:

Python

import pandas as pd

# Sample dataset
data = {
'Name': ['Alice', 'Bob', 'Charlie', 'David'],
'Age': [25, None, 35, 29],
'Salary': [50000, 60000, None, 45000]
}
df = pd.DataFrame(data)

# Clean missing values


df['Age'].fillna(df['Age'].mean(), inplace=True)
df['Salary'].fillna(df['Salary'].mean(), inplace=True)

# Calculate statistics
print("Mean Age:", df['Age'].mean())
print("Mean Salary:", df['Salary'].mean())
print("Summary:\n", df.describe())

Output Explanation:

 Dataset Cleaning: Missing values in Age and Salary are replaced with column means.
 Statistics: Calculates mean and summary statistics for numeric columns.
o Example Output:
 Mean Age = 29.67
 Mean Salary = 51,666.67
Conclusion: Pandas streamlines data cleaning and analysis, making it indispensable for AI and data
science tasks.

You might also like