SkillDzire Internship Report: ML Focus
SkillDzire Internship Report: ML Focus
MACHINE
LEARNING
An Internship Report Submitted at the end
of seventh semester
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING
Submitted By
KAMISETTY SAi VIKASH
(21981A0570)
2024-2025
RAGHU ENGINEERING COLLEGE
AUTONOMOUS
Approved by AICTE, New Delhi, Accredited by NBA (CIV, ECE, MECH, CSE),
NAAC with 'A+' grade, Permanently Affiliated to JNTU-GV, Vizianagaram
CERTIFICATE
This is to certify that this project entitled "Machine Learning" done by "KAMISETTY SAi VIKASH
(21981A0570)" is a student of [Link] in the Department of Computer Science and Engineering, RAGHU
ENGINEERING COLLEGE, during the period 2021-2025, in partial fulfillment for the award of the Degree of
Bachelor of Technology in Computer Science and Engineering to the Jawaharlal Nehru Technological University,
Gurajada Vizianagaram is a record of bonafide work carried out under my guidance and supervision.
The results embodied in this internship report have not been submitted to any other University or
Institute for the award of any Degree.
EXTERNAL EXAMINER
DISSERTATION APPROVAL SHEET
This is to certify that the dissertation titled
PROJECT GUIDE
(Assistant Professor)
Internal Examiner
External Examiner
HOD
(Professor)
Date:
11
DECLARATION
This is to certify that this internship titled "Machine Learning" is bonafied work done
by my me, impartial fulfillment of the requirements for the award of the degree [Link] and
submitted to the Department of Computer Science and Engineering, RAGHU
ENGINEERING COLLEGE, Dakamarri.
I also declare that this internship is a result of my own effort and that has not been
copied from anyone and I have taken only citations from the sources which are mentioned in the
references.
This work was not submitted earlier at any other University or Institute for the reward of
any degree.
Date:
Place:
(21981A0570)
111
CERTIFICATE
Sl<illDzire
CERTIFICATE OF INTERNSHIP
SDST-30995
I u d On: M o
lf DER,_ I'
01-Jul-24
Approved By AICTE Authorized Signature
iv
ACKNOWLEDGEMENT
I sincerely express our deep sense of gratitude to Dr.R. Sivaranjani, Professor, Head of
Department in Department of Computer Science and Engineering, Raghu Engineering College,
for her perspicacity, wisdom and sagacity coupled with compassion and patience. It is my great
pleasure to submit this work under her wing. I thank for guiding us for the successful completion
of this project work.
I would like to thank Mr. V. Tata Rao, Assistant Professor for providing the technical
guidance to carry out module assigned. Your expertise in the subject matter and dedication
towards our project have been a source of inspiration for all of us.
I extend my deep hearted thanks to all faculty members of the Computer Science
department for their value-based imparting of theory and practical subjects, which were used in
the project.
Regards
KAMISETTY SAi VIKASH
(21981A0570)
V
TABLE OF CONTENTS
1. INTRODUCTION TO PYTHON 1
2. OOPS IN PYTHON 4
3.
NUMPY AND PANDAS 6
5. ADVANCED ML ALGORITHMS 16
7. CONCLUSION 31
vi
1. INTRODUCTION TO PYTHON
1.1 PYTHON
Python is a widely used, high-level, general-purpose programming language known for its
simplicity and readability. It enables developers to express concepts with fewer lines of
code compared to languages like C++ or Java. Python's clean syntax and design philosophy
make it accessible to beginners while providing powerful tools for experienced developers
to work on both small and large-scale applications.
• Integer int: Represents whole numbers, both positive and negative, without a
fractional component. e.g: 10, -5.
• Float float: Represents numbers that contain decimal points or fractions. e.g: 3.14,
- 0.75.
• String str: Represents a sequence of characters enclosed in single, -double, or triple
quotes. e.g: "Python", 'Hello World'.
• Boolean bool: Represents logical values, either True or False.
1
• List list: An ordered, mutable collection of items, which can be of different data types.
e.g: [1, "apple", 3.5].
• Tuple tuple: An ordered, immutable collection of items. e.g: (1, 2, "banana").
• Set set: An unordered collection of unique elements. e.g: {1, 2, 3, "apple"}.
• Dictionary diet: A collection of key-value pairs, where each key is associated with a
specific value. e.g: {"name": "Alice", "age": 25}.
Ex:
x=5
if X > 5:
print("x is greater than 5")
elif x == 5:
print("x is equal to 5")
Ex:
x=lO
if x>5:
if x<15:
print("Between 5 and 15")
2. while Loop: Repeatedly executes a block of code as long as a specified condition is True.
2
Ex:
x=O
while x < 5:
print(x)
X += 1
4. continue Statement: Skips the current iteration and moves to the next iteration in the
loop. Ex:
for i in range(5):
if i == 2:
continue
print(i)
A function in Python is defined using the def keyword, followed by the function name and
parentheses containing optional parameters.
Syntax
def function_name(parameters):
# Function body
# Optional return statement
Ex:
3
2.00PS IN PYTHON
Python is an object-oriented programming (OOP) language that allows for the creation and
utilization of classes and objects. The major principles of object-oriented programming in
Python include the following:
1. Object:
An object is an entity that has a state (attributes) and behavior (methods). Objects can be
physical (e.g., a mouse, keyboard) or logical (e.g., a user account). In Python, everything
is an object, and all objects have associated attributes and methods. For instance,
functions have a built-in attribute _doc_, which returns the docstring defined in the
function source code.
2. Class:
A class is a blueprint for creating objects. It defines a set of attributes and methods
that the created objects (instances) will have. For example, an Employee class may
contain attributes such as email, name, age, and salary.
Syntax:
class ClassName:
attribute = value
def method_name(self):
# Method body
3. Method:
A method is a function that is associated with an object. In Python, methods are not
unique to class instances; any object type can have methods.
4. Inheritance:
Inheritance is a feature of OOP that allows one class (the derived class or child class) to
inherit the properties and behaviors of another class (the base class or parent class).
This promotes code reusability and reduces redundancy.
Example:
class Parent:
def greet(self):
print("Hello from Parent")
class Child(Parent):
def greet_child(self):
print("Hello from Child")
4
5. Polymorphism:
Polymorphism allows methods to perform different functions based on the object that is
calling them. It enables a single interface to be used for different underlying forms (data
types). For instance, a method named talk can have different implementations for
different animal classes.
Example:
class Animal:
def talk(self):
pass
class Dog(Animal):
def talk(self):
return "Bark"
class Cat(Animal):
def talk(self):
return "Meow"
6. Encapsulation:
Encapsulation is a mechanism that restricts access to certain components of an object
and bundles the data (attributes) and methods (functions) that operate on the data
within a single unit. This can be implemented using private variables and getter/setter
methods to control access.
Example:
class Account:
def get_balance(self):
return self._balance
5
3. NUMPY & PANDAS
3.1 NUMPY
NumPy is a powerful library for numerical computing in Python, providing support for
large, multi-dimensional arrays and matrices, along with a collection of mathematical functions
to operate on these arrays.
3.1. lARRAY
An array is a central data structure in NumPy, allowing for efficient storage and
manipulation of numerical data. It is a grid of values, all of the same type, indexed by a tuple
of non-negative integers. The number of dimensions is called the rank of the array.
NumPy gives you an enormous range of fast and efficient numerically-related options. While a
Python list can contain different data types within a single list, all of the elements in a NumPy
array should be homogenous. The mathematical operations that are meant to be performed on
arrays wouldn't be possible if the arrays weren't homogenous.
WhyNumPy?
NumPy arrays are faster and more compact than Python lists. An array consumes less
memory and is far more convenient to use. NumPy uses much less memory to store data
and it provides a mechanism of specifying the data types, which allows the code to be
optimized even further.
import numpy as np
# Creating a 1D array
array_ld = [Link]([l, 2, 3, 4, 5])
# Sorting an array
sorted_array = [Link](array_ld)
6
Resizing an Array:
You can change the shape of an array using the reshape() method.
# Resizing an array
reshaped_array = [Link](array_ld, (5, 1)) # Reshaping to 5 rows and 1 column
Indexing:
You can access elements of a NumPy array using indexing.
# Indexing an array
element= array_ ld[2] # Accesses the element at index 2
Slicing:
Slicing allows you to access a range of elements in an array.
# Slicing an array
slice_array = array_1d[1:4] # Gets elements from index 1 to 3
Broadcasting:
Broadcasting refers to the ability ofNumPy to perform operations on arrays of different shapes.
For instance, you can add a scalar to an array.
# Broadcasting example
array_broadcast = array_1d + 5 # Adds 5 to each element in the array
# Creating a 2D array
array_2d = [Link]([[l, 2, 3], [4, 5, 6], [7, 8, 9]])
# Accessing an element
element = array_2d[1, 2] # Accesses the element in the second row and third column
print("Element at (1, 2):", element) # Output: 6
7
3.2 PANDAS
Pandas is a powerful Python library used for data manipulation and analysis, especially
in structured data environments. It provides versatile data structures to efficiently work
with large datasets.
import pandas as pd
1. Series: A one-dimensional labeled array, similar to a list, where each element has
an associated index.
2. DataFrame: A two-dimensional, tabular data structure with labeled axes (rows
and columns), similar to a table in relational databases.
3. Panel: A three-dimensional container for data, though less commonly used and
largely replaced by multi-dimensional arrays in 'NumPy'.
3.2.3 DATAFRAME
A 'DataFrame' is the primary data structure in Pandas, used to store and manipulate tabular
data.
df = pd.read_csv('[Link]')
print([Link]()) # Displays the first 5 rows
# Sorting by a column
sorted_df = df.sort_values(by='Age')
8
3.2.7 GROUPING AND CONCATENATION
Pandas allows grouping data for aggregation and concatenating DataFrames.
9
4. INTRODUCTION TO MACHINE LEARNING
Machine Leaming (ML) is a branch of artificial intelligence (Al) that creates algorithms that learn
from data and make predictions or decisions. Rather than being manually programmed for specific
tasks, ML models find patterns in data and improve automatically with experience. This ability
makes machine learning useful for many applications, including data analysis and automating
decisions.
1. Data Collection
The first step involves gathering and preparing data from different sources. The quality and
quantity of data significantly influence model performance.
2. Data Preprocessing
The data is cleaned and transformed to prepare it for the model. This includes handling missing
values, normalizing features, and encoding categorical variables.
3. Model Building
A machine learning algorithm is selected and trained on the prepared data to learn the underlying
patterns.
4. Model Evaluation
The model's performance is assessed using metrics like accuracy, precision, recall, and mean
squared error, often with a validation dataset.
5. Model Deployment
Once the model is trained and evaluated, it is deployed for real-time predictions or integrated into
applications for decision-making.
10
Example Algorithms: K-Means Clustering, Hierarchical Clustering, Principal
Component Analysis (PCA).
3. Semi-Supervised Learning
Semi-supervised learning is a hybrid approach where the model is trained on a small
amount of labeled data along with a large amount of unlabeled data. This technique helps
when labeling data is costly or time-consuming.
4. Reinforcement Learning
In reinforcement learning, the model learns through trial and error by interacting with an
environment and receiving feedback in the form of rewards or penalties.
Linear regression is a statistical technique used to model the relationship between one or more
independent variables and a dependent variable by fitting a linear equation to observed data. It is
widely used in predictive analytics, machine learning, and data science to understand and predict
continuous outcomes. The primary goal of linear regression is to find the best-fitting line that
minimizes the difference between predicted and actual values.
Simple linear regression is the most basic form of linear regression where we model the
relationship between a single independent variable (X) and a dependent variable (Y). The
relationship between the two is represented by the equation:
Y = o+ 1 X + E:
Where:
Simple linear regression is useful when there is only one predictor variable, and the relationship
between the variables is assumed to be linear.
Multiple linear regression extends simple linear regression by incorporating more than one
independent variable to predict the dependent variable. The equation for multiple linear regression
is:
Where:
To evaluate the performance of a linear regression model, several metrics are commonly used:
1. Mean Squared Error (MSE): The average squared difference between the observed
and predicted values. Lower values indicate better model performance.
i=l
. 2
MSE = 1 L} - Yi)
n
2. Root Mean Squared Error (RMSE): The square root of MSE, providing an
interpretable error metric in the same units as the dependent variable.
RMSE =MSE
3. R-squared (R2): Represents the proportion of variance in the dependent variable that
is explained by the independent variables. Values range from O to 1, with higher
values indicating a better fit
2 L 1( t)2
R = 1 L7_1( Y)2
4. Adjusted R-squared: Similar to R2, but adjusted for the number of predictors in the
model, preventing overfitting when using multiple independent variables.
Each of these metrics provides insights into how well the linear regression model fits the data and
how accurately it predicts outcomes.
Binary logistic regression is the simplest form of logistic regression where the dependent
variable has two possible outcomes (e.g., 0 or 1, yes or no, true or false). The logistic regression
model for binary outcomes can be written as:
12
Where:
The logistic function transforms the linear equation into a value between O and 1, representing
the probability of a certain class.
Multinomial logistic regression is used when the dependent variable has more than two
categories. Unlike binary logistic regression, which predicts probabilities for two classes,
multinomial logistic regression predicts probabilities for multiple classes (e.g., A, B, C). Each
class has its own logistic function, and the probability of an outcome belonging to a particular
class is calculated based on a set of logistic functions. The model is represented as:
Where pk is the probability of class k and pl is the probability of a reference class. This model is
widely used in scenarios like predicting customer choices or categorizing text into multiple
classes.
Several metrics are used to evaluate the performance of a logistic regression model, especially in
classification problems:
14
Fl= 2 Precision x Recall
x----------------------
Recall
These metrics help assess how well the logistic regression model performs in classification tasks.
Decision trees are intuitive, easy to interpret, and can handle both numerical and categorical data,
making them useful for a wide range of problems.
Constructing a decision tree involves selecting the feature that best separates the data at each step,
typically based on a criterion like information gain or Gini impurity. The tree is built recursively by
splitting the dataset until all data points in a subset belong to the same class (for classification) or
until a stopping condition is reached (for regression).
1. Select the Best Feature: Choose the feature that provides the most significant
separation between data points using criteria like information gain or Gini index.
2. Create Decision Nodes: Split the dataset into smaller subsets based on the selected feature.
3. Repeat the Process: Recursively apply the same process to the resulting subsets.
4. Stopping Condition: Stop splitting when a certain condition is met (e.g., maximum
depth, all samples in a node belong to the same class).
Several algorithms are used to construct decision trees, the most common being:
1. 1D3 (Iterative Dichotomiser 3): This algorithm uses information gain based on entropy
to select the best feature for splitting at each node. It continues building the tree until all
attributes are exhausted or the data is perfectly classified.
2. CART (Classification and Regression Trees): CART is used for both classification
and regression tasks. It splits the data using the Gini impurity for classification or the
least squared deviation for regression. Unlike ID3, CART builds binary trees where each
split produces exactly two branches.
3. C4.5: An extension of ID3, C4.5 handles both categorical and continuous features and
uses a concept of gain ratio (a normalized version of information gain) to split the nodes.
It can handle missing values and allows pruning after tree construction.
15
4.6.3 MODEL EVALUATION
Evaluating a decision tree model involves several metrics depending on whether the task is
classification or regression:
4.6.4 PRUNING
Pruning is a crucial step in decision tree optimization that helps reduce overfitting by removing
sections of the tree that are not significant. There are two main types of pruning:
1. Pre-pruning (Early Stopping): Stops the tree construction early, based on predefined
conditions like maximum depth, minimum samples per leaf, or maximum number of
nodes.
2. Post-pruning: Involves growing the full tree first and then removing the least important
branches. Post-pruning techniques like cost-complexity pruning use a validation set to
prune branches that do not improve performance.
Pruning enhances the generalization ability of the model by reducing the complexity of the tree,
preventing overfitting to the training data.
16
5. ADVANCED ML ALGORITHMS
Advanced Algorithms and Applications in Machine Leaming focus on developing sophisticated
techniques to solve complex problems more efficiently. These algorithms include deep learning,
reinforcement learning, ensemble methods (e.g., Random Forest, Gradient Boosting), and
optimization techniques like Genetic Algorithms and Simulated Annealing. They are applied in
areas such as natural language processing, computer vision, recommendation systems, and
autonomous systems. Advanced algorithms improve accuracy, scalability, and generalization,
making them essential for real-world applications in AI-driven industries.
1. Choose the value of K: Select the number of nearest neighbors (K). A smaller K can lead
to overfitting, while a larger K may smooth out the decision boundary but risk underfitting.
2. Calculate the Distance: For a new data point, calculate the distance to all training
data points using a distance metric such as Euclidean distance (most common),
Manhattan distance, or Minkowski distance.
n
d(p, q) L(p·
i-1
3. Identify Neighbors: Select the K nearest neighbors (those with the smallest distances).
4. Voting or Averaging:
• Classification: Assign the new data point to the class that is most
common among its K neighbors (majority vote).
• Regression: Calculate the average of the values of the K neighbors to predict
the output.
5. Predict the Label: Return the predicted class label or continuous value.
5.2 CORRELATION
Correlation is a statistical measure that describes the strength and direction of a relationship
between two variables. It quantifies how changes in one variable are associated with changes in
another. A correlation coefficient ranges from -1 to 1, where:
• 1 indicates a perfect positive correlation (both variables move in the same direction),
• -1 indicates a perfect negative correlation (one variable increases while the other decreases),
• 0 indicates no correlation (no relationship between the variables).
The Pearson correlation coefficient (r) is the most commonly used measure of correlation and
assesses the linear relationship between two continuous variables. It assumes that the variables
are normally distributed and measures how much one variable changes as the other changes.
The formula for Pearson correlation is:
I: (Xi X)( Y)
r = - --;=I:=(=X=i=x=)2=L=(Y:=i =Y=)2
Where:
Pearson correlation is useful when you want to assess the strength and direction of a linear
relationship.
18
5.2.2 SPEARMAN CORRELATION COEFFICIENT
6 I: d;
p=1
n(n2 - 1)
Where:
Spearman is commonly used when the data is ordinal or when the relationship is not linear.
Correlation analysis is used to determine the strength and direction of relationships between
variables. When interpreting correlation results, consider the following guidelines:
• Positive correlation: As one variable increases, the other also increases (closer to +1).
• Negative correlation: As one variable increases, the other decreases (closer to -1).
• No correlation: The variables do not move together in any discernible way (closer to 0).
While correlation helps identify relationships, it does not imply causation. A strong correlation
between two variables does not necessarily mean that changes in one cause changes in the
other; there may be other factors or variables influencing the relationship.
Example:
• A Pearson correlation of 0.85 between hours studied and exam scores indicates a strong
positive relationship, meaning that more study hours are associated with higher exam
scores.
• A Spearman correlation of -0.75 between rank in a race and finish time suggests a
strong negative relationship; the faster the finish time, the higher the rank.
19
True Positives (TP)
True Positives represent instances where the model correctly predicted the positive class. For
example, in a disease classification task, TP would be cases where the model correctly identified
patients as having the disease.
True Negatives are instances where the model correctly predicted the negative class. In the same
disease classification example, TN would be cases where the model correctly identified patients as
not having the disease.
False Positives, also known as Type I errors, occur when the model incorrectly predicts the positive
class for an actual negative instance. This would be when a healthy patient is wrongly classified as
having the disease.
False Negatives, or Type II errors, happen when the model incorrectly predicts the negative
class for an actual positive instance. In this case, the model fails to detect the disease in a patient
who actually has it.
5.3.1 ACCURACY
Accuracy is a measure of how often the model's predictions are correct, calculated as the ratio of
correct predictions (TP + TN) to the total number of predictions. It is useful when the classes are
balanced.
TP- TN
Accuracy == TP + TN+ FP+ FN
5.3.2 PRECISION
Precision measures the proportion of true positive predictions out of all positive predictions. It
is crucial when the cost of false positives is high.
TP
Pred ion = -- -
TP-FP
5.3.3 RECALL
Recall, or Sensitivity, measures the proportion of true positive predictions out of all actual positive
instances. It is important in scenarios where missing positive instances (false negatives) is costly.
TP
Recall == -- -
TPFN
20
5.3.4 Fl SCORE
The Fl Score is the harmonic mean of precision and recall, providing a single metric that balances
the trade-off between them. It is especially useful when the dataset is imbalanced, and both false
positives and false negatives are critical.
Computer vision has rapidly evolved due to advancements in machine learning, especially deep
learning, which allows models to learn from vast amounts of visual data. It plays a critical role
in various sectors, including healthcare, retail, automotive, and robotics.
Image processing involves manipulating and analyzing images to improve their quality or
extract useful information. Some commonly used techniques in image processing include:
1. Image Smoothing: This technique reduces noise and variations in an image, making
it clearer. Methods such as Gaussian Blurring or Median Filtering are used to
smoothen images by reducing unnecessary details.
2. Edge Detection: Detecting the boundaries of objects in images is crucial for identifying
shapes. Algorithms like Canny Edge Detection and Sobel Filters are widely used to detect
sharp transitions in pixel intensity, highlighting the edges of objects.
3. Thresholding: Thresholding converts grayscale images into binary images (black and
white) by setting a pixel intensity threshold. Pixels above the threshold are set to white,
and
21
those below are set to black. This technique is used in applications like document scanning
and segmentation.
4. Morphological Operations: These operations, such as Erosion and Dilation, are used to
remove small objects or enhance structures within an image. They are commonly applied
in preprocessing tasks, such as noise removal or shape enhancement.
5. Image Segmentation: Image segmentation divides an image into meaningful regions
or segments. Watershed Segmentation and K-means Clustering are popular techniques
to separate objects from the background or other regions.
Object Detection involves locating and identifying objects within an image or video. It not only
classifies objects but also predicts their positions using bounding boxes. Object Recognition, on
the other hand, goes a step further by identifying specific instances of objects, such as
recognizing a particular face in a crowd or detecting a specific brand of a product.
1. Convolutional Neural Networks (CNNs): CNNs are the backbone of modern object
detection models. They can automatically learn features from images and are
particularly effective in tasks like image classification and face detection.
2. YOLO (You Only Look Once): YOLO is a real-time object detection algorithm that
divides an image into grids and predicts bounding boxes and class probabilities for objects
in a single pass through the network. It is widely used for tasks that require real-time
object detection, such as video surveillance or autonomous driving.
3. R-CNN (Region-based CNN): R-CNN family algorithms (e.g., Fast R-CNN, Faster
R CNN) are another set of powerful object detection models. They first generate
potential object regions (proposals) and then classify each region using a CNN.
4. Haar Cascades: Haar Cascade classifiers are an older but efficient method for object
detection, especially in detecting faces. They work by applying multiple stages of
classifiers to an image to detect objects in real-time.
22
5. Agriculture: Computer vision is used in precision agriculture to monitor crops, detect
diseases, and analyze soil health. Drones equipped with computer vision technologies
can survey large farmlands and provide insights to farmers.
6. Augmented Reality (AR): In AR applications, computer vision helps in overlaying
digital content onto the physical world. This is used in mobile apps, gaming, and even
navigation systems to enhance the user's real-world experience.
CNNs are widely used in applications such as image classification, object detection, face
recognition, and even natural language processing. By using convolutional layers, CNNs can
automatically learn hierarchical feature representations, from simple features like edges and
corners to more complex features like shapes and objects.
A typical CNN consists of several key layers, each contributing to the extraction and processing
of image features:
1. Convolutional Layers: The convolutional layer is the core building block of CNNs. It
applies filters (or kernels) to the input image to detect features like edges, textures, and
patterns. This layer generates feature maps, which highlight the presence of specific
features across the image. Each filter produces a different feature map, helping the network
capture various aspects of the image.
2. Pooling Layers: Pooling layers are used to down-sample the feature maps, reducing their
spatial dimensions and computational complexity while preserving important features.
Common pooling techniques include Max Pooling (which selects the maximum value from
a window of the feature map) and Average Pooling. Pooling helps make the model
invariant to small translations in the input image, ensuring that the model can detect
features regardless of their location.
3. Fully Connected Layers (FC Layers): After the convolutional and pooling layers, the
network typically includes one or more fully connected layers. These layers take the high
level features extracted by the convolutional layers and map them to the output classes. In
an image classification task, the final fully connected layer typically outputs a probability
distribution over the possible classes.
4. Activation Functions: Activation functions such as ReLU (Rectified Linear Unit)
introduce non-linearity into the network, allowing it to learn complex patterns. Without
these non linear functions, the network would behave like a simple linear model.
5. Softmax Layer: In classification tasks, the final layer of a CNN is usually a Softmax
layer, which converts the output into probabilities for each class.
23
5.5.2 TRANSFER LAERNING WITH PRE-TRAINDED MODELS
Transfer learning is a technique where a model that has been pre-trained on a large dataset is
fine-tuned on a smaller, domain-specific dataset. In the context of CNNs, popular pre-
trained models such as VGG, ResNet, Inception, and MobileNet are trained on massive
datasets like ImageNet, which contains millions of labeled images across thousands of
categories.
By leveraging transfer learning, the pre-trained model's convolutional layers can be used to
extract relevant features from a new dataset, while the fully connected layers can be re-trained
to suit the specific task. This approach saves time and computational resources and often leads
to improved performance, particularly when the target dataset is small or similar to the pre
trained dataset.
Transfer learning is especially effective in scenarios where labeled data is scarce, as the pre
trained model already has a good understanding of general features like edges, textures, and
shapes. Fine-tuning these models can significantly reduce the need for extensive training and
improve the performance of image classification tasks.
CNNs are highly effective for image classification tasks, where the goal is to categorize an
image into one of several predefined classes. The process of image classification using CNNs
involves the following steps:
1. Input Preprocessing: Before feeding images into the CNN, they are typically resized to
a fixed size, normalized (to adjust pixel values), and augmented (to generate variations
and reduce overfitting).
2. Feature Extraction: The CNN's convolutional layers extract high-level features from the
input image. For instance, in a task to classify images of animals, the early layers may
detect basic features like edges and textures, while deeper layers capture more complex
structures like fur patterns or specific shapes.
3. Classification: The fully connected layers at the end of the network take the
extracted features and map them to the output classes, where the final prediction is
made. The Softmax layer then converts these predictions into probabilities for each
class.
4. Training and Optimization: During training, the model's weights are adjusted using
techniques like Backpropagation and Stochastic Gradient Descent (SGD) to minimize
the loss function, which measures the difference between the predicted class and the
actual class.
25
meaningful way. It encompasses various tasks, including language translation, sentiment
analysis, text summarization, and conversational agents like chatbots.
NLP combines computational linguistics, machine learning, and linguistics to analyze and
understand human language. With the increasing volume of text data generated daily-from
social media, emails, articles, and customer reviews-NLP has become essential for businesses
and researchers seeking to extract insights from unstructured text. Advances in deep learning
and the availability of large datasets have significantly improved NLP models, enabling them to
achieve impressive performance in tasks such as text classification and language generation.
Text preprocessing is a crucial step in NLP that involves transforming raw text into a clean and
structured format suitable for analysis. This step helps to improve the performance of NLP
models by reducing noise and standardizing the input data. Common text preprocessing
techniques include:
1. Tokenization: Tokenization is the process of breaking down text into smaller units, called
tokens. Tokens can be words, phrases, or sentences, depending on the granularity required
for analysis. For example, the sentence "Natural Language Processing is fascinating!" can
be tokenized into ["Natural", "Language", "Processing", "is", "fascinating","!"].
2. Lowercasing: Converting all text to lowercase helps to ensure consistency by treating
words with different casing (e.g., "NLP" and "nlp") as the same token.
3. Removing Punctuation and Special Characters: Punctuation marks and special
characters often do not contribute to the meaning of the text and can be removed to simplify
analysis. For instance, "Hello, world!" would become "Hello world".
4. Stopword Removal: Stopwords are common words like "and," "the," and "is" that often
do not add significant meaning to the text. Removing stopwords can reduce the
dimensionality of the data and improve model performance.
5. Stemming and Lemmatization: Stemming involves reducing words to their base or
root form (e.g., "running" to "run"), while lemmatization considers the context and
converts words to their dictionary form (e.g., "better" to "good"). Both techniques help
standardize words and reduce variations.
Once text has been preprocessed, the next step is to represent it in a format that machine
learning models can understand. Several text representation techniques include:
1. Bag of Words (BoW): The Bag of Words model represents text as an unordered collection
of words, disregarding grammar and word order. Each document is converted into a vector
of word frequencies, where each dimension corresponds to a unique word in the
vocabulary. While simple, BoW does not capture word context or relationships.
2. Term Frequency-Inverse Document Frequency (TF-IDF): TF-IDF improves upon BoW
by weighing the frequency of words relative to their importance in a collection of
documents. It assigns higher weights to words that are frequent in a particular document
but rare across the entire corpus, helping to identify key terms.
3. Word Embeddings: Word embeddings, such as Word2Vec, GloVe, and FastText,
represent words as dense vectors in a continuous vector space. These embeddings capture
semantic relationships and contextual meanings, allowing similar words to have similar
vector
26
representations. For example, the words "king" and "queen" would have embeddings that
reflect their relationship in context.
4. Transformers: Transformers, particularly models like BERT and GPT, have revolutionized
text representation by using self-attention mechanisms to capture contextual information
and relationships between words in a sentence. These models have achieved state-of-the-art
performance in various NLP tasks.
Sentiment analysis is an NLP task that involves determining the sentiment or emotional tone of
a piece of text. It is widely used in applications like social media monitoring, customer
feedback analysis, and brand reputation management. Sentiment analysis can be categorized
into:
Text classification is a broader NLP task that involves categorizing text into predefined classes
or labels. This can include tasks like spam detection in emails, topic classification of news
articles, and intent recognition in chatbots. The process typically involves feature extraction,
training a classifier (e.g., logistic regression, support vector machines, or neural networks), and
evaluating model performance using metrics such as accuracy, precision, recall, and Fl score.
27
6. HOUSING PRICE PREDICTION MODEL
6.1 INTRODUCTION
The Housing Price Prediction Model aims to predict the price of houses based on various
features such as location, size, number of bedrooms, and other factors. By utilizing machine
learning algorithms, particularly linear regression, the model analyzes historical data to
establish a relationship between housing features and their respective prices. This project
showcases how machine learning can be applied in the real estate market to make informed
decisions based on data patterns.
6.2 PURPOSE
The primary purpose of this project is to develop a model that accurately predicts house prices
using regression techniques. By feeding historical housing data into the model, it will learn the
relationship between various features and the house prices, enabling it to predict the price of
new houses based on their features. This helps buyers, sellers, and real estate agents make
more data-driven decisions.
6.3 PURPOSE
The algorithm used for this project is Linear Regression, which is a supervised learning
technique. Linear regression helps in modeling the relationship between a dependent variable
(house price) and one or more independent variables (features such as size, location, etc.). The
goal is to fit a linear equation to observed data, which will be used to predict the house price
based on the given features.
6.4 INTRODUCTION
1. Data Collection
We collect housing data from reliable sources, including features like house size, number of
rooms, location, and price.
2. Data Preprocessing
Handling Missing Values: Any missing values in the dataset are handled by either filling
them with mean/median or removing them.
Feature Scaling: Standardization or normalization of features is performed to ensure
they are on the same scale, which improves model accuracy.
Encoding Categorical Variables: Categorical variables (e.g., location) are converted into
numerical representations using techniques like one-hot encoding.
3. Splitting Data
The dataset is split into two parts: training and testing sets. Typically, 80% of the data is
used for training, and 20% is used for testing.
28
4. Model Building
The Linear Regression algorithm is applied to the training data. The model learns the
relationship between the features and the house prices during this phase.
5. Model Evaluation
o The trained model is evaluated using the testing dataset. Evaluation metrics such
as Mean Squared Error (MSE) and R-squared (R2) are used to measure how well
the model performs.
6. Prediction
o The model is used to predict the prices of houses based on the input features
6.5 IMPLEMENTATION:
[Link] LIBRARIES
Ensure that you have the required libraries installed in your Python environment.
jupyter notebook
This will open the Jupyter interface in your browser. You can create a new notebook by clicking
on "New" and selecting "Python 3."
• C 0 localhoslS888/t,l'l' * o D s :
• python CPP 'l mdm doc 4- gdb ij Learn JAVA P,ogram nr srv ['J tbntpc D All Booktm11ks
Jupyter
File View Settings Help
• Fil•s O Running
Select item5 to perform actions on them. • N•w !. Upl0<1d C
Import the necessary libraries for data handling, model building, and evaluation.
import pandas as pd
29
import numpy as np
Load your housing dataset (assumed to be in CSV format) and perform basic exploration.
# Load the housing dataset (replace '[Link]' with your dataset path)
data= pd.read_csv('[Link]')
[Link]()
Handle missing values and split the dataset into features and target variables.
# Split the dataset into features (X) and target variable (y)
model = LinearRegression()
30
[Link](X_train, y_train)
y_pred = [Link](X_test)
# Evaluate the model performance
r2 = r2_score(y_test, y_pred)
Use the trained model to make predictions for new house data.
Execution
1. Save the Notebook: After writing all the cells, save the notebook (File-> Save As) and run
the cells (Cell -> Run All).
2. Running the Notebook: You can run each cell one by one by clicking the "Run" button, or
you can run all cells at once (Cell-> Run All).
3. Exporting the Notebook: You can export the notebook as a PDF or HTML by going to File
-> Download As and selecting your preferred format.
6.6 TESTCASES
1. Test Case 1: Basic Prediction
• Input: Features [2000, 3, 2, 1] representing a house of 2000 square feet with 3
bedrooms, 2 bathrooms, and 1 floor.
• Expected Output: Predicted price (e.g., 450,000).
2. Test Case 2: Model Evaluation
• Input: Test dataset (automatically selected from the dataset).
31
•
Expected Output: Mean Squared Error and R-squared score indicating the
performance of the model.
3. Test Case 3: Missing Values Handling
• Input: Dataset with missing values in some columns.
• Expected Output: The missing values are handled, and the model should
still function without errors.
4. Test Case 4: Prediction for Different House Features
• Input: Features [1500, 2, 1, l] representing a house of 1500 square feet with 2
bedrooms, 1 bathroom, and 1 floor.
• Expected Output: A predicted price (e.g., 320,000).
6.7 RESULTS
Longitude PRICE
0 -122.23 4.526
-122.22 3. 585
-122.24 3. 521
-122.25 3.413
4 -122.25 3.422
MedInc
HouseAge
AveRooms
AveBedrms
Population
AveOccup
Latitude
Longitude
PRICE
dtype: int64
Training set size: 16512, Test set size: 4128
Mean Squared Error: 0. 555891598695244
R- squared score: 0. 5757877060324511
The dataset used for the housing price prediction model contains key features such as median
income ('Medine'), house age ('HouseAge'), average rooms ('AveRooms'), bedrooms
('AveBedrms'), population ('Population'), occupancy ('AveOccup'), geographic coordinates
('Latitude', 'Longitude'), and the target variable, housing price ('PRICE'). The data is
complete with no missing values, ensuring consistency for model training. The dataset was
split into a training set of 16,512 records and a test set of 4,128 records.
The model's performance was evaluated using Mean Squared Error (MSE), which was
calculated as 0.555, and the R-squared score was 0.576, indicating the model explained 57.6%
of the variance in housing prices.
32
7. CONCLUSION
33