Data Science
Complete Study Notes
Lab Test • Theory Paper • Viva Voce
Topics: Intro to DS | Data Collection | EDA | Intro to ML | Supervised Learning | Unsupervised
Learning
Badge Meaning
[Lab] Code to write/run in lab test
[Theory] Concepts for written theory paper
[Viva] Things you will be asked to explain verbally
Topic 1: Introduction to Data Science
[Theory] [Viva]
What is Data Science?
Data science is the process of extracting useful knowledge and insights from data using math, statistics,
programming, and domain knowledge.
Key Components
• Data — raw facts and numbers
• Statistics — making sense of numbers
• Programming — Python, R, SQL
• Machine Learning — teaching computers to find patterns
• Visualization — showing data in graphs/charts
Data Science vs Related Fields
[Viva]
• Data Science — broad field, combines everything below
• Data Analytics — focuses on analyzing past data
• Machine Learning — subset of AI, learns from data
• AI — making machines intelligent
• Statistics — the math behind data
Data Science Lifecycle
[Theory]
• 1. Define the Problem
• 2. Collect Data
• 3. Clean & Process Data
• 4. Explore Data (EDA)
• 5. Build Model
• 6. Evaluate Model
• 7. Deploy & Monitor
Tip: The lifecycle is a cycle — you often go back to earlier steps!
Tools & Libraries
[Lab]
• Python — most popular language for Data Science
• NumPy — numerical computing, arrays
• Pandas — data manipulation (DataFrames)
• Matplotlib / Seaborn — plotting and visualization
• Scikit-learn — machine learning algorithms
• Jupyter Notebook — interactive coding environment
Topic 2: Data Collection and Processing
[Theory] [Lab] [Viva]
Types of Data
By Structure:
• Structured — tables, rows and columns (like Excel, SQL)
• Unstructured — text, images, audio, video
• Semi-structured — JSON, XML
By Type (very important for exams!):
• Numerical / Quantitative — numbers (age, salary)
• Categorical / Qualitative — categories (color, gender)
• Ordinal — ordered categories (low, medium, high)
• Nominal — no order (city names, blood type)
Data Collection Methods
[Theory]
• Surveys / Questionnaires — ask people directly
• Web Scraping — collect data from websites using code
• APIs — get data from online services (Twitter API, etc.)
• Sensors / IoT — real-time device data
• Databases — SQL, NoSQL stores
• CSV / Excel files — most common in lab tests
Data Cleaning
[Lab] [Viva]
Real-world data is messy. Cleaning means fixing problems before analysis.
Common issues and fixes:
• Missing values — drop rows, or fill with mean/median/mode
• Duplicates — remove duplicate rows
• Wrong data types — convert string to number, etc.
• Outliers — values too far from the normal range
• Inconsistent format — 'Male' vs 'male' vs 'M'
[Link]().sum() # check missing values
[Link]([Link]()) # fill missing with mean
[Link]() # drop rows with missing values
df.drop_duplicates() # remove duplicate rows
[Link] # check data types
df['col'].astype(int) # convert column type
Data Preprocessing
[Lab]
• Normalization — scale data between 0 and 1 (MinMaxScaler)
• Standardization — mean=0, std=1 (StandardScaler)
• Encoding — convert categories to numbers (Label Encoding, One-Hot Encoding)
• Train-Test Split — split data for training and testing
from [Link] import MinMaxScaler, LabelEncoder
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42)
Topic 3: Exploratory Data Analysis (EDA)
[Theory] [Lab] [Viva]
What is EDA?
EDA is the process of visually and statistically exploring data to understand its main characteristics
before building models.
Goal: Understand patterns, spot anomalies, check assumptions, find relationships between variables.
Descriptive Statistics
[Theory] [Lab]
Statistic Meaning
Mean Average of all values
Median Middle value when sorted
Mode Most frequently occurring value
Std Deviation How spread out the data is
Variance Std Deviation squared
Range Max value minus Min value
[Link]() # all stats at once
df['col'].mean()
df['col'].median()
df['col'].std()
Common EDA Plots
[Lab] [Viva]
Plot Type Use Case
Histogram Distribution of one variable
Box Plot Shows median, quartiles, and outliers
Scatter Plot Relationship between 2 variables
Bar Chart Compare categories
Heatmap Correlation between multiple variables
Pair Plot Scatter plots for all variable pairs
import [Link] as plt
import seaborn as sns
df['col'].hist() # histogram
[Link](x=df['col']) # box plot
[Link](x='a', y='b', data=df) # scatter plot
[Link]([Link](), annot=True) # heatmap
[Link](df) # pair plot
Correlation
[Theory] [Viva]
Measures how strongly two variables are related. Value ranges from -1 to +1.
• +1 — perfect positive correlation (both increase together)
• 0 — no correlation
• -1 — perfect negative correlation (one increases, other decreases)
Tip: Correlation does NOT mean causation!
Topic 4: Introduction to Machine Learning
[Theory] [Viva]
What is Machine Learning?
Machine Learning (ML) is teaching a computer to learn from data and make decisions without being
explicitly programmed for every single step.
Types of Machine Learning
[Theory] [Viva]
• Supervised Learning — learns from labeled data (input + correct output given)
• Unsupervised Learning — finds patterns in unlabeled data
• Reinforcement Learning — learns by trial and error using rewards
• Semi-supervised — mix of labeled and unlabeled data
Key Terminology
[Viva] [Theory]
Term Meaning
Feature (X) Input variable used for prediction
Label / Target (y) Output variable we want to predict
Model The algorithm that learns from data
Training Teaching the model on data
Testing Checking model on unseen data
Overfitting Model learns training data too well, fails on new data
Underfitting Model is too simple, poor performance everywhere
Bias Error from wrong assumptions in the model
Variance Error from being too sensitive to training data
Model Evaluation Metrics
[Lab] [Theory]
For Classification:
• Accuracy — percentage of correct predictions
• Precision — of predicted positives, how many are actually positive
• Recall — of actual positives, how many did we catch
• F1 Score — balance of precision and recall
• Confusion Matrix — table of TP, TN, FP, FN
For Regression:
• MAE — Mean Absolute Error
• MSE — Mean Squared Error
• RMSE — Root MSE (same units as y, easier to interpret)
• R² Score — how well model explains variance (0 to 1, higher is better)
from [Link] import accuracy_score, confusion_matrix
from [Link] import mean_squared_error, r2_score
accuracy_score(y_test, y_pred)
confusion_matrix(y_test, y_pred)
r2_score(y_test, y_pred)
Topic 5: Supervised Learning
[Theory] [Lab] [Viva]
You give the model inputs (X) and correct answers (y). It learns the mapping X → y.
Two main tasks:
• Regression — predict a continuous number (e.g. house price, temperature)
• Classification — predict a category (e.g. spam or not spam, disease or not)
1. Linear Regression
[Lab] [Theory] [Viva]
Fits a straight line: y = mx + b. Predicts a continuous value.
• m = slope, b = intercept
• Goal: minimize prediction error (MSE)
• Multiple Linear Regression — uses more than one input feature
from sklearn.linear_model import LinearRegression
model = LinearRegression()
[Link](X_train, y_train)
y_pred = [Link](X_test)
print(model.coef_, model.intercept_)
2. Logistic Regression
[Lab] [Theory] [Viva]
Despite the name — it is used for classification, not regression! Predicts probability (0 to 1) using a
sigmoid function.
• Output: 0 or 1 (binary classification)
• Threshold usually 0.5 — above = class 1, below = class 0
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
[Link](X_train, y_train)
y_pred = [Link](X_test)
3. Decision Tree
[Lab] [Viva]
Splits data into branches using yes/no questions. Works for both classification and regression.
• Root node — first split (most important feature)
• Leaf node — final prediction
• Easy to visualize and explain
• Can overfit easily — use max_depth to control
from [Link] import DecisionTreeClassifier
model = DecisionTreeClassifier(max_depth=3)
[Link](X_train, y_train)
4. KNN — K Nearest Neighbors
[Lab] [Viva]
Classifies a new point by looking at its K nearest neighbors. Majority vote wins.
• K is a hyperparameter you choose
• Small K = complex boundary (overfitting risk)
• Large K = simple boundary (underfitting risk)
• Sensitive to feature scaling — always normalize first!
from [Link] import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=5)
[Link](X_train, y_train)
5. SVM — Support Vector Machine
[Theory] [Viva]
Finds the best boundary (hyperplane) that separates classes with the maximum margin.
• Support Vectors — data points closest to the boundary
• Kernel trick — handles non-linear data (RBF, polynomial kernel)
• Good for high-dimensional data
from [Link] import SVC
model = SVC(kernel='rbf')
[Link](X_train, y_train)
6. Random Forest
[Lab] [Viva]
Collection of many decision trees. Each tree votes, and the majority wins.
• Reduces overfitting compared to a single tree
• Ensemble method — combining multiple models
• Can show which features are most important
from [Link] import RandomForestClassifier
model = RandomForestClassifier(n_estimators=100)
[Link](X_train, y_train)
print(model.feature_importances_)
Topic 6: Unsupervised Learning
[Theory] [Lab] [Viva]
No labels given. The model finds hidden patterns or structure in the data on its own.
• Clustering — group similar data points together
• Dimensionality Reduction — reduce number of features
• Association — find rules (e.g. people who buy X also buy Y)
1. K-Means Clustering
[Lab] [Theory] [Viva]
Groups data into K clusters. Each point belongs to the nearest cluster center (centroid).
Steps:
• 1. Choose K (number of clusters)
• 2. Randomly place K centroids
• 3. Assign each point to nearest centroid
• 4. Recalculate centroids (mean of each cluster)
• 5. Repeat until centroids stop moving
Tip: How to choose K? Use the Elbow Method — plot inertia vs K, pick where the curve bends like an elbow.
from [Link] import KMeans
model = KMeans(n_clusters=3, random_state=42)
[Link](X)
labels = model.labels_
centroids = model.cluster_centers_
2. Hierarchical Clustering
[Theory] [Viva]
Builds a tree of clusters called a dendrogram. No need to choose K in advance.
• Agglomerative (bottom-up) — start with each point as its own cluster, merge closest ones
• Divisive (top-down) — start with one big cluster, split it
• Linkage types: single, complete, average, ward
from [Link] import dendrogram, linkage
import [Link] as plt
Z = linkage(X, method='ward')
dendrogram(Z)
[Link]()
3. PCA — Principal Component Analysis
[Lab] [Theory] [Viva]
Reduces the number of features while keeping as much information as possible. Used for visualization
and speeding up models.
• Finds new axes (principal components) that capture maximum variance
• PC1 captures the most variance, PC2 second most, etc.
• Features must be scaled before applying PCA
from [Link] import PCA
from [Link] import StandardScaler
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X_scaled)
print(pca.explained_variance_ratio_)
4. DBSCAN
[Theory] [Viva]
Density-based clustering. Groups points that are close together and marks outliers as noise.
• Does not need K specified in advance
• Can find clusters of any shape
• eps — max distance between two points to be neighbors
• min_samples — minimum points needed to form a cluster
• Points not in any cluster are labelled as noise/outliers
from [Link] import DBSCAN
model = DBSCAN(eps=0.5, min_samples=5)
labels = model.fit_predict(X)
Comparing Clustering Algorithms
[Viva]
Algorithm Needs K? Handles Noise? Cluster Shape Speed
K-Means Yes No Spherical only Fast
Hierarchical No (dendrogram) No Any Slow (large data)
DBSCAN No Yes Any Medium
Good luck on your exams!