Lesson 1: Python Basics
1.2 Installing Python
Python can be installed from python.org. IDEs like VS Code, PyCharm, or Jupyter Notebook can be used for coding.
Explanation:-
No code for this topic.1.3 Hello World
The first program prints text to the screen using the print() function.
print("Hello World")
Explanation:-
print() outputs the text "Hello World" to the console.# Alternative print example
print("Hi there!")
Explanation:-
Alternative way to print a message.1.4 Python Comments
Comments are used to explain code and are ignored by the interpreter.
# This is a comment
print("Hello")
Explanation:-
Lines starting with # are ignored. Only print("Hello") executes.# Multi-line comment
"""
This is a comment
"""
Explanation:-
Alternative way to write multi-line comment.1.5 Variables
Variables store data values and can be named anything following Python naming rules.
x = 10
y = "Kapil"
print(x, y)
Explanation:-
x stores integer 10, y stores string "Kapil". print() displays both values.z = 3.14
print(z)
Explanation:-
z stores float value 3.14.1.6 Data Types
Python supports different data types like int, float, string, list, tuple, set, dictionary, etc.
x = 5
y = 3.14
name = "Kapil"
Explanation:-
int, float, and string examples.nums = [1,2,3,4]
Explanation:-
A list example.1.7 Type Conversion
Convert one data type to another using int(), float(), str(), etc.
x = int(3.14)
print(x)
Explanation:-
Float 3.14 converted to int 3.y = str(100)
print(y)
Explanation:-
Integer 100 converted to string "100".1.8 Operators
Python supports arithmetic, comparison, logical, assignment, and bitwise operators.
a = 5
b = 2
print(a+b, a-b, a*b, a/b)
Explanation:-
Arithmetic operations example.print(a==b, a!=b, a>b, a<b)
Explanation:-
Comparison operations example.1.9 Conditional Statements
Use if, elif, and else to execute code based on conditions.
x = 10
if x>5:
print("Greater than 5")
Explanation:-
Simple if statement example.x = 2
if x>5:
print("Yes")
else:
print("No")
Explanation:-
If-else statement example.1.10 Loops - for & while
Loops allow you to execute code multiple times.
for i in range(5):
print(i)
Explanation:-
For loop example.i=0
while i<5:
print(i)
i+=1
Explanation:-
While loop example.1.11 Quiz - Python Basics
Test your understanding of Python basics.
Lesson 2: NumPy & Pandas Fundamentals
2.12 Functions
Functions allow you to organize code into reusable blocks.
def greet():
print("Hello")
greet()
Explanation:-
Simple function example.def add(a,b):
return a+b
print(add(3,5))
Explanation:-
Function with parameters and return value.2.13 Lambda Functions
Anonymous functions using lambda keyword.
square = lambda x: x*x
print(square(5))
Explanation:-
Lambda function to square a number.add = lambda a,b: a+b
print(add(3,4))
Explanation:-
Lambda function to add two numbers.2.14 Lists
Lists store multiple items in a single variable.
fruits = ["apple","banana","mango"]
print(fruits)
Explanation:-
List creation example.fruits.append("orange")
print(fruits)
Explanation:-
Appending item to list example.2.15 Tuples
Tuples are immutable sequences of items.
t = (1,2,3)
print(t)
Explanation:-
Tuple creation example.print(t[0])
Explanation:-
Accessing tuple elements.2.16 Sets
Sets are unordered collections of unique items.
s = {1,2,3,2}
print(s)
Explanation:-
Set creation and uniqueness.s.add(4)
print(s)
Explanation:-
Adding element to set.2.17 Dictionaries
Dictionaries store key-value pairs.
d = {"name":"Kapil","age":30}
print(d)
Explanation:-
Dictionary creation.d["city"]="Delhi"
print(d)
Explanation:-
Adding new key-value pair.2.18 String Operations
Strings have many useful operations like slicing, formatting, concatenation.
name = "Kapil"
print(name[0:3])
Explanation:-
String slicing example.greeting = "Hello"
print(greeting + " Kapil")
Explanation:-
String concatenation example.2.19 Modules & Packages
Modules are Python files; packages are collections of modules.
import math
print(math.sqrt(16))
Explanation:-
Using math module.import random
print(random.randint(1,10))
Explanation:-
Using random module.2.20 File Handling
Read and write files using open(), read(), write().
f = open("test.txt","w")
f.write("Hello")
f.close()
Explanation:-
Writing to a file example.f = open("test.txt","r")
print(f.read())
f.close()
Explanation:-
Reading from a file example.2.21 NumPy Introduction
NumPy is a library for numerical computing with Python. It provides arrays, matrices, and functions to operate on them.
import numpy as np
arr = np.array([1,2,3,4,5])
print(arr)
Explanation:-
Creating a NumPy array example.arr = np.arange(0,10,2)
print(arr)
Explanation:-
Using arange to generate array.2.22 NumPy Array Operations
Perform mathematical operations efficiently on NumPy arrays.
arr = np.array([1,2,3])
print(arr + 5)
Explanation:-
Add scalar to array example.arr2 = np.array([4,5,6])
print(arr + arr2)
Explanation:-
Add two arrays element-wise.2.23 Array Indexing & Slicing
Access elements of NumPy arrays using indexing and slicing.
arr = np.array([10,20,30,40])
print(arr[1])
Explanation:-
Indexing example.print(arr[1:3])
Explanation:-
Slicing example.2.24 Array Shape & Reshape
Change the dimensions of arrays using reshape.
arr = np.arange(6)
print(arr.reshape(2,3))
Explanation:-
Re-shaping 1D array to 2D.2.25 Mathematical Functions
NumPy provides mathematical functions like sum(), mean(), sqrt(), etc.
arr = np.array([1,2,3])
print(np.sum(arr))
Explanation:-
Sum of array elements.print(np.sqrt(arr))
Explanation:-
Square root of array elements.2.26 Random Numbers
Generate random numbers using NumPy.
print(np.random.rand(3))
Explanation:-
Random float numbers between 0-1.print(np.random.randint(1,10,5))
Explanation:-
Random integers between 1-10.2.27 Pandas Introduction
Pandas is a library for data manipulation and analysis. It provides Series and DataFrames.
import pandas as pd
s = pd.Series([1,2,3])
print(s)
Explanation:-
Creating a Series.df = pd.DataFrame({"A":[1,2],"B":[3,4]})
print(df)
Explanation:-
Creating a DataFrame.2.28 Series Operations
Perform operations on Pandas Series.
s = pd.Series([1,2,3])
print(s + 5)
Explanation:-
Add scalar to series.print(s.mean())
Explanation:-
Mean of series.2.29 DataFrame Indexing
Access rows and columns in DataFrame using loc and iloc.
print(df.loc[0,"A"])
Explanation:-
Access using loc.print(df.iloc[0,1])
Explanation:-
Access using iloc.2.30 Data Cleaning
Handle missing values, duplicates, and incorrect data.
d = pd.DataFrame({"A":[1,None,3],"B":[4,5,None]})
d.fillna(0)
Explanation:-
Replace missing values.d.dropna()
Explanation:-
Drop missing values.2.31 Quiz - NumPy & Pandas Basics
Test your understanding of NumPy arrays and Pandas basics.
Lesson 3: Pandas Advanced & Visualization
3.32 DataFrame Operations
Add, drop, rename columns and rows in DataFrame.
d["C"] = d["A"] + d["B"]
Explanation:-
Adding a new column.d.drop("C", axis=1)
Explanation:-
Dropping a column.3.33 GroupBy Operations
Group data and perform aggregation.
d.groupby("A").sum()
Explanation:-
Group by sum example.d.groupby("A")["B"].mean()
Explanation:-
Group by mean example.3.34 Merging & Joining
Combine DataFrames using merge and join.
pd.merge(df1, df2, on="key")
Explanation:-
Merging DataFrames.df1.join(df2)
Explanation:-
Joining DataFrames.3.35 Pivot Tables
Create pivot tables for summarizing data.
d.pivot_table(values="B", index="A", aggfunc="sum")
Explanation:-
Pivot table example.3.36 Sorting & Ranking
Sort DataFrames by column values and rank.
d.sort_values("B")
Explanation:-
Sort by column.d["B"].rank()
Explanation:-
Rank values.3.37 Filtering & Querying
Filter data using conditions or query function.
d[d["A"]>2]
Explanation:-
Filter using condition.d.query("B>4")
Explanation:-
Filter using query.3.38 Data Visualization with Matplotlib
Plot graphs using Matplotlib.
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,5,6])
plt.show()
Explanation:-
Line plot example.plt.bar([1,2,3],[4,5,6])
plt.show()
Explanation:-
Bar plot example.3.39 Scatter & Histogram Plots
Visualize data using scatter and histogram plots.
plt.scatter([1,2,3],[4,5,6])
plt.show()
Explanation:-
Scatter plot example.plt.hist([1,2,2,3,3,3])
plt.show()
Explanation:-
Histogram example.3.40 Subplots & Figures
Organize multiple plots in a single figure.
fig, ax = plt.subplots(2,1)
ax[0].plot([1,2,3],[4,5,6])
ax[1].bar([1,2,3],[4,5,6])
plt.show()
Explanation:-
Subplots example.3.41 Seaborn Introduction
Seaborn is a Python library for statistical data visualization built on Matplotlib.
import seaborn as sns
df = sns.load_dataset("iris")
sns.scatterplot(x="sepal_length", y="sepal_width", data=df)
plt.show()
Explanation:-
Scatter plot using Seaborn.3.42 Line & Bar Plots in Seaborn
Create line and bar plots easily.
sns.lineplot(x=[1,2,3], y=[4,5,6])
plt.show()
Explanation:-
Line plot example.sns.barplot(x=[1,2,3], y=[4,5,6])
plt.show()
Explanation:-
Bar plot example.3.43 Histograms & KDE
Visualize distribution of data using histograms and KDE.
sns.histplot(df["sepal_length"], kde=True)
plt.show()
Explanation:-
Histogram with KDE example.3.44 Box & Violin Plots
Show data distribution and outliers using box and violin plots.
sns.boxplot(x="species", y="sepal_length", data=df)
plt.show()
Explanation:-
Box plot example.sns.violinplot(x="species", y="sepal_length", data=df)
plt.show()
Explanation:-
Violin plot example.3.45 Heatmaps
Visualize correlation matrices and data patterns using heatmaps.
corr = df.corr()
sns.heatmap(corr, annot=True)
plt.show()
Explanation:-
Heatmap example.3.46 Quiz - Data Visualization
Test your understanding of Matplotlib & Seaborn visualizations.
Lesson 4: Data Handling with Pandas
4.47 Pandas Read CSV & Excel
Read data from CSV and Excel files using Pandas.
df = pd.read_csv("data.csv")
Explanation:-
Reaing CSV example.df = pd.read_excel("data.xlsx")
Explanation:-
Reading Excel example.4.48 Exporting Data
Save DataFrames to CSV, Excel, and JSON.
df.to_csv("output.csv", index=False)
Explanation:-
Export to CSV.df.to_excel("output.xlsx", index=False)
Explanation:-
Export to Excel.df.to_json("output.json")
Explanation:-
Export to JSON.4.49 Handling Missing Data
Identify and handle missing values in DataFrames.
df.isnull().sum()
Explanation:-
Count missing values.df.fillna(0)
Explanation:-
Replace missing values.df.dropna()
Explanation:-
Drop rows with missing values.4.50 DataFrame Filtering
Filter rows based on conditions.
df[df["age"]>25]
Explanation:-
Filter using condition.df.query("salary>50000")
Explanation:-
Filter using query method.4.51 String Manipulation in Pandas
Use string methods on Pandas columns.
df["name"].str.upper()
Explanation:-
Convert to uppercase.df["name"].str.contains("Kapil")
Explanation:-
Check substring presence.4.52 Datetime in Pandas
Work with dates and times in DataFrames.
pd.to_datetime("2025-01-01")
Explanation:-
Convert string to datetime.df["date"] = pd.to_datetime(df["date"])
Explanation:-
Convert column to datetime.4.53 Indexing & Selecting Data
Select rows and columns efficiently.
df.loc[0:2, ["name","age"]]
Explanation:-
Select using loc.df.iloc[0:3, 0:2]
Explanation:-
Select using iloc.4.54 Renaming Columns
Rename columns for better readability.
d.rename(columns={"old":"new"}, inplace=True)
Explanation:-
Rename columns example.4.55 Dropping Columns & Rows
Remove unnecessary columns or rows.
d.drop("column_name", axis=1, inplace=True)
Explanation:-
Drop column example.d.drop(0, axis=0)
Explanation:-
Drop row example.4.56 Sorting DataFrames
Sort data by column values.
d.sort_values("age")
Explanation:-
Sort by one column.d.sort_values(["age","salary"])
Explanation:-
Sort by multiple columns.4.57 Aggregations
Aggregate data using sum, mean, min, max, etc.
d.groupby("department")["salary"].sum()
Explanation:-
Sum aggregation.d.groupby("department")["salary"].mean()
Explanation:-
Mean aggregation.4.58 Pivot Tables Advanced
Advanced pivot tables with multiple indexes and values.
d.pivot_table(values="salary", index=["department","team"], aggfunc="sum")
Explanation:-
Advanced pivot example.4.59 Merging Multiple DataFrames
Combine multiple DataFrames efficiently.
pd.concat([df1, df2, df3])
Explanation:-
Concatenate DataFrames.pd.merge(df1, df2, on="key")
Explanation:-
Merge DataFrames.4.60 Quiz - Pandas Advanced
Test your understanding of Pandas data manipulation.
Lesson 5: Data Preprocessing & ML Introduction
5.61 Matplotlib Customization
Customize plots with titles, labels, colors, and styles.
plt.plot([1,2,3],[4,5,6], color="red")
Explanation:-
Change line color.plt.title("Line Plot")
Explanation:-
Add plot title.plt.xlabel("X-axis")
plt.ylabel("Y-axis")
Explanation:-
Add axis labels.5.62 Seaborn Customization
Customize Seaborn plots with hue, style, palette, etc.
sns.scatterplot(x="sepal_length", y="sepal_width", hue="species", data=df)
Explanation:-
Add hue to scatter plot.sns.set_style("darkgrid")
Explanation:-
Set plot style.5.63 Correlation Analysis
Check relationships between numerical features using correlation.
corr = df.corr()
print(corr)
Explanation:-
Print correlation matrix.sns.heatmap(corr, annot=True)
plt.show()
Explanation:-
Visualize correlations with heatmap.5.64 Handling Outliers
Identify and handle outliers in the data.
q1 = df["salary"].quantile(0.25)
q3 = df["salary"].quantile(0.75)
ir = q3-q1
Explanation:-
Compute IQR.df_no_outliers = df[(df["salary"]>q1-1.5*ir) & (df["salary"]<q3+1.5*ir)]
Explanation:-
Remove outliers using IQR method.5.65 Feature Scaling
Scale features using normalization or standardization.
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
df_scaled = scaler.fit_transform(df)
Explanation:-
Standardize features.from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
df_norm = scaler.fit_transform(df)
Explanation:-
Normalize features.5.66 Quiz - Data Preprocessing
Test your knowledge on data cleaning, scaling, and outlier handling.
Lesson 6: Introduction to Supervised Learning
6.67 Train-Test Split
Split data into training and testing sets.
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)
Explanation:-
Split dataset into train and test sets.6.68 Linear Regression
Predict continuous values using Linear Regression.
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Explanation:-
Train linear regression model and predict.6.69 Logistic Regression
Predict binary outcomes using Logistic Regression.
from sklearn.linear_model import LogisticRegression\nmodel = LogisticRegression()\nmodel.fit(X_train, y_train)\ny_pred = model.predict(X_test)
Explanation:-
Train logistic regression model and predict.6.70 Evaluation Metrics
Check model performance using accuracy, precision, recall, F1-score, MSE, etc.
from sklearn.metrics import accuracy_score
accuracy_score(y_test, y_pred)
Explanation:-
Classification accuracy example.from sklearn.metrics import mean_squared_error
mean_squared_error(y_test, y_pred)
Explanation:-
Regression MSE example.Lesson 7: Linear Regression & Multiple Regression
7.71 K-Nearest Neighbors
KNN algorithm for classification or regression.
from sklearn.neighbors import KNeighborsClassifier
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Explanation:-
Train KNN classifier and predict.7.72 Decision Trees
Decision tree model for classification and regression.
from sklearn.tree import DecisionTreeClassifier
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Explanation:-
Train decision tree and predict.7.73 Random Forest
Random Forest ensemble model for better predictions.
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Explanation:-
Train Random Forest model and predict.7.74 Support Vector Machine
SVM algorithm for classification.
from sklearn.svm import SVC
model = SVC()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Explanation:-
Train SVM and predict.Lesson 8: Logistic Regression
8.75 Naive Bayes
Probabilistic classifier using Bayes theorem.
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
Explanation:-
Train Naive Bayes and predict.8.76 Quiz - ML Models
Test your understanding of Linear, Logistic, KNN, Decision Tree, Random Forest, SVM, and Naive Bayes.
8.77 Hyperparameter Tuning
Optimize model parameters using GridSearchCV or RandomizedSearchCV.
from sklearn.model_selection import GridSearchCV
param_grid = {"n_neighbors":[3,5,7]}
grid = GridSearchCV(KNeighborsClassifier(), param_grid)
grid.fit(X_train, y_train)
Explanation:-
Perform hyperparameter tuning with GridSearchCV.Lesson 9: Decision Trees & Random Forest
9.78 Cross Validation
Validate model performance using k-fold cross-validation.
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5)
print(scores)
Explanation:-
5-fold cross-validation example.9.79 Feature Selection
Select important features for modeling using techniques like RFE.
from sklearn.feature_selection import RFE
selector = RFE(model, n_features_to_select=3)
selector.fit(X_train, y_train)
Explanation:-
Recursive Feature Elimination example.9.80 PCA - Principal Component Analysis
Reduce dimensionality of dataset using PCA.
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
X_pca = pca.fit_transform(X)
Explanation:-
Apply PCA for dimensionality reduction.9.81 Clustering - KMeans
Cluster data points using KMeans algorithm.
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)
labels = kmeans.labels_
Explanation:-
KMeans clustering example.9.82 Clustering - DBSCAN
Cluster data points using DBSCAN algorithm.
from sklearn.cluster import DBSCAN
dbscan = DBSCAN(eps=0.5, min_samples=5)
dbscan.fit(X)
Explanation:-
DBSCAN clustering example.9.83 Hierarchical Clustering
Cluster data using hierarchical techniques.
from scipy.cluster.hierarchy import dendrogram, linkage
linked = linkage(X, "single")
dendrogram(linked)
plt.show()
Explanation:-
Hierarchical clustering and dendrogram.9.84 Evaluation of Clustering
Evaluate clusters using silhouette score and other metrics.
from sklearn.metrics import silhouette_score
score = silhouette_score(X, labels)
print(score)
Explanation:-
Silhouette score calculation.Lesson 10: Support Vector Machines & K-NN
10.85 Time Series Introduction
Understand time-dependent data and trends.
import pandas as pd
date_rng = pd.date_range(start="1/1/2025", periods=5, freq="D")
df = pd.DataFrame(date_rng, columns=["date"])
Explanation:-
Create date range example.10.86 Quiz - Clustering & Time Series
Test your knowledge on clustering and time series basics.
10.87 Time Series Plotting
Plot time series data using Matplotlib or Pandas.
df.plot(x="date", y="value")
plt.show()
Explanation:-
Plot time series data example.10.88 Moving Averages
Compute moving averages to smooth time series.
df["MA"] = df["value"].rolling(window=3).mean()
Explanation:-
3-day moving average example.10.89 Seasonality & Trend
Detect seasonality and trend using decomposition.
from statsmodels.tsa.seasonal import seasonal_decompose
result = seasonal_decompose(df["value"], model="additive")
result.plot()
plt.show()
Explanation:-
Decompose time series example.10.90 ARIMA Model
Build ARIMA model for forecasting.
from statsmodels.tsa.arima.model import ARIMA
model = ARIMA(df["value"], order=(1,1,1))
model_fit = model.fit()
print(model_fit.summary())
Explanation:-
ARIMA model fitting example.10.91 Forecasting with ARIMA
Use ARIMA model to predict future values.
y_pred = model_fit.forecast(steps=5)
print(y_pred)
Explanation:-
Forecast next 5 periods using ARIMA.Lesson 11: Model Optimization & Evaluation
11.92 Feature Engineering
Create new features from existing data to improve model performance.
df["new_feature"] = df["feature1"] * df["feature2"]
Explanation:-
Multiply two features to create new feature.11.93 Encoding Categorical Data
Convert categorical variables to numeric using label encoding or one-hot encoding.
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
df["encoded"] = le.fit_transform(df["category"])
Explanation:-
Label encoding example.df_encoded = pd.get_dummies(df["category"])
Explanation:-
One-hot encoding example.11.94 Handling Imbalanced Data
Use techniques like oversampling, undersampling, or SMOTE to handle class imbalance.
from imblearn.over_sampling import SMOTE
smote = SMOTE()
X_res, y_res = smote.fit_resample(X, y)
Explanation:-
SMOTE oversampling example.11.95 Pipeline & Automation
Automate data processing and modeling using Pipelines.
from sklearn.pipeline import Pipeline
pipe = Pipeline([("scaler", StandardScaler()), ("model", LogisticRegression())])
pipe.fit(X_train, y_train)
Explanation:-
Pipeline example for scaling + model.11.96 Quiz - Feature Engineering & ML
Test your knowledge on feature engineering, encoding, and pipelines.
11.97 Model Deployment Basics
Introduction to deploying ML models using Flask or FastAPI.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/")
def home():
return "Hello World"
Explanation:-
Basic Flask app example.11.98 Model Saving & Loading
Save models using pickle or joblib.
import pickle
pickle.dump(model, open("model.pkl","wb"))
Explanation:-
Save model to file.model = pickle.load(open("model.pkl","rb"))
Explanation:-
Load model from file.11.99 Project Workflow
End-to-end workflow: Data collection, cleaning, modeling, evaluation, deployment.
# Pseudo code
# 1. Collect data
# 2. Clean data
# 3. Train model
# 4. Evaluate
# 5. Deploy
Explanation:-
Project workflow steps example.11.100 Capstone Project
Apply all learned concepts to a final project.
# Example: Predict house prices using dataset
# Implement data cleaning, feature engineering, ML model, evaluation
Comments (3)
Login to comment
addkee: hi
addkee: nice course
addkee: superb course