Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

The notes are related to machine learning, which can be helpful for BTech computer science, Study notes of Machine Learning

The notes are related to machine learning, which can be helpful for BTech computer science students.These notes are for BTech Computer Science students, whether they are in their second or third year, and are helpful for everyone. The notes are written in great detail, making them highly beneficial for students. These are verified notes and will be extremely useful for Computer Science students. Machine Learning plays a crucial role in subjects like Computer Science. Thank you.

Typology: Study notes

2022/2023

Available from 08/23/2024

anubhav-mishra-9
anubhav-mishra-9 🇮🇳

3 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Unit -1
Machine learning
What is "Machine" in Machine Learning?
In the context of machine learning, the "machine" refers to the computational system or model that processes data
and performs tasks. This "machine" can be
a computer program, algorithm, or model
that is designed to learn from data and
make predictions or decisions based on
that data. The machine processes the data,
identifies patterns, and uses these patterns
to perform specific tasks without explicit
instructions for each task.
Example:
Imagine you have a computer program
that predicts house prices. This program is
the "machine." It takes input data like the
size of the house, number of bedrooms,
location, etc., and processes this data to
predict the price of the house. The machine uses patterns it has learned from previous data to make these
predictions.
What is "Learning" in Machine Learning?
"Learning" in machine learning refers to the process by which the machine improves its performance on a task over
time through experience. This involves the machine being exposed to data, analyzing this data, and then making
adjustments to its algorithms or models to improve its accuracy or efficiency. Learning can occur through various
methods, such as supervised learning (learning from labeled data), unsupervised learning (finding patterns in
unlabeled data), or reinforcement learning (learning through rewards and punishments).
Example:
Continuing with the house price prediction example, the learning process involves the program being fed a large
dataset of houses with known prices. The program analyzes this data, identifying patterns and relationships
between house features and their prices. Over time, as it processes more data, it becomes better at predicting house
prices. Initially, its predictions might be inaccurate, but with more data and feedback, the program learns to make
more accurate predictions.
Summary
Machine: In machine learning, the "machine" is the computational model or algorithm that processes data and
performs tasks based on that data. It could be a simple program or a complex neural network.
o Example: A program predicting house prices based on features like size, number of bedrooms, and
location.
Learning: "Learning" refers to the process
by which the machine improves its
performance on a task over time by
analyzing data and adjusting its models or
algorithms accordingly.
o Example: The house price prediction
program improves its accuracy by
analyzing more data about house
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download The notes are related to machine learning, which can be helpful for BTech computer science and more Study notes Machine Learning in PDF only on Docsity!

Unit - 1

Machine learning

What is "Machine" in Machine Learning? In the context of machine learning, the "machine" refers to the computational system or model that processes data and performs tasks. This "machine" can be a computer program, algorithm, or model that is designed to learn from data and make predictions or decisions based on that data. The machine processes the data, identifies patterns, and uses these patterns to perform specific tasks without explicit instructions for each task. Example : Imagine you have a computer program that predicts house prices. This program is the "machine." It takes input data like the size of the house, number of bedrooms, location, etc., and processes this data to predict the price of the house. The machine uses patterns it has learned from previous data to make these predictions. What is "Learning" in Machine Learning? "Learning" in machine learning refers to the process by which the machine improves its performance on a task over time through experience. This involves the machine being exposed to data, analyzing this data, and then making adjustments to its algorithms or models to improve its accuracy or efficiency. Learning can occur through various methods, such as supervised learning (learning from labeled data), unsupervised learning (finding patterns in unlabeled data), or reinforcement learning (learning through rewards and punishments). Example : Continuing with the house price prediction example, the learning process involves the program being fed a large dataset of houses with known prices. The program analyzes this data, identifying patterns and relationships between house features and their prices. Over time, as it processes more data, it becomes better at predicting house prices. Initially, its predictions might be inaccurate, but with more data and feedback, the program learns to make more accurate predictions. SummaryMachine : In machine learning, the "machine" is the computational model or algorithm that processes data and performs tasks based on that data. It could be a simple program or a complex neural network. o Example: A program predicting house prices based on features like size, number of bedrooms, and location.  Learning : "Learning" refers to the process by which the machine improves its performance on a task over time by analyzing data and adjusting its models or algorithms accordingly. o Example: The house price prediction program improves its accuracy by analyzing more data about house

features and prices, identifying patterns, and refining its prediction model. Here are some key aspects of learning in machine learning:

  1. Data : Learning begins with data. This can be historical data, real-time data, or simulated data, which the system uses to identify patterns and relationships.
  2. Training : The system is exposed to a subset of the data, known as the training set. During training, the system adjusts its internal parameters to minimize errors in its predictions or classifications.
  3. Evaluation : After training, the system is tested on a separate subset of the data, called the test set, to evaluate its performance. This helps ensure that the system can generalize what it has learned to new, unseen data.
  4. Feedback Loop : In some systems, feedback is provided to continuously improve performance. For example, a recommendation system might update its suggestions based on user interactions, continuously refining its model.
  5. Models and Algorithms : Learning is facilitated through various models and algorithms that provide the structure for analyzing data and making predictions. Examples include neural networks, decision trees, and support vector machines. Machine learning is a branch of artificial intelligence where computers learn to perform tasks by analyzing data, rather than being explicitly programmed. Here are some examples to illustrate this:

1. Spam Email Filtering : An email service uses machine learning to automatically filter out spam

emails. It analyzes thousands of emails and learns to recognize patterns that are typical of spam,

such as certain keywords or sender behavior.

2. Recommendation Systems: Online platforms like Netflix or Amazon use machine learning to

recommend movies or products. By analyzing your past behavior and comparing it with other users,

the system learns your preferences and suggests items you might like.

3. Image Recognition : Apps like Google Photos use machine learning to recognize and categorize

images. For example, it can learn to identify pictures of cats or specific landmarks by analyzing

thousands of labeled images and recognizing patterns in the pixels.

4. Voice Assistants : Virtual assistants like Siri or Alexa use machine learning to understand and

respond to voice commands. They learn from millions of voice samples to understand different

accents, speech patterns, and commands.

5. Self-Driving Cars : Autonomous vehicles use machine learning to navigate and make decisions

on the road. They analyze data from sensors and cameras to recognize objects, predict their

movements, and make driving decisions in real-time.

Machine learning (ML) evaluation

Machine learning (ML) evaluation is the process of assessing how well a machine learning model performs on a specific task. Evaluation helps determine if the model is accurate, reliable, and ready to be deployed for real-world applications. Here are some simple ways to understand ML evaluation:

  1. Splitting Data:  Training Set: Used to train the model.  Test Set: Used to evaluate the model’s performance on new, unseen data.
  2. Metrics : Common metrics used to evaluate ML models include:  Accuracy: The percentage of correct predictions out of all predictions made. For example, if a spam filter correctly identifies 90 out of 100 emails as spam or not spam, its accuracy is 90%.  Precision: The percentage of true positive predictions out of all positive predictions made. For example, if a medical test predicts 10 cases as positive for a disease and 8 of those are correct, the precision is 80%.  Recall (Sensitivity): The percentage of true positive predictions out of all actual positive cases. For example, if there are 20 actual cases of a disease and the test correctly identifies 15, the recall is 75%.  F1 Score: The harmonic mean of precision and recall, giving a balance between the two. For example, if a model has a precision of 80% and a recall of 60%, the F1 score would be around 69%.
  3. Confusion Matrix : A table used to describe the performance of a classification model by showing true positives, true negatives, false positives, and false negatives.  True Positives (TP): Correctly predicted positive cases.  True Negatives (TN): Correctly predicted negative cases.  False Positives (FP): Incorrectly predicted positive cases (Type I error).  False Negatives (FN): Incorrectly predicted negative cases (Type II error). Example Scenario - Imagine you have a model that predicts whether an email is spam or not spam. After testing it on 100 emails, you get the following results:  True Positives (TP) : 40 (Emails correctly identified as spam)  True Negatives (TN) : 50 (Emails correctly identified as not spam)  False Positives (FP) : 5 (Emails incorrectly identified as spam)  False Negatives (FN) : 5 (Emails incorrectly identified as not spam) Confusion Matrix - The confusion matrix summarizes the results: Predicted Spam Predicted Not Spam Actual Spam^40 Actual Not Spam 5 50

Accuracy - Accuracy measures the overall correctness of the model. The summary of the calculated metrics indicates the following:  Accuracy (90%): The model correctly identifies 90% of the emails as either spam or not spam.  Precision (89%): When the model predicts an email as spam, it is correct 89% of the time.  Recall (89%): The model correctly identifies 89% of all actual spam emails.  F1 Score (89%): The harmonic mean of precision and recall, indicating a balanced performance, is 89%.

Here's a Python code snippet to compute accuracy, precision, recall, and F1 score for one of the examples, specifically the email spam filter case: _# Example confusion matrix values TP = 30 # True Positives TN = 50 # True Negatives FP = 10 # False Positives FN = 5 # False Negatives

Compute metrics directly from confusion matrix values

accuracy = (TP + TN) / (TP + TN + FP + FN) precision = TP / (TP + FP) if (TP + FP) > 0 else 0 recall = TP / (TP + FN) if (TP + FN) > 0 else 0 f1 = 2 * (precision * recall) / (precision + recall) if (precision + recall) > 0 else 0

Print results

print(f'Accuracy: {accuracy:.2f}') print(f'Precision: {precision:.2f}') print(f'Recall: {recall:.2f}') print(f'F1 Score: {f1:.2f}') This snippet uses basic Python and scikit-learn functions to compute and print these metrics based on provided confusion matrix values, making it straightforward and easy to understand._

Learning a network in machine learning

In machine learning, "learning a network" refers to the process by which a system (like a computer program) learns how to make predictions or decisions based on data. Think of it as teaching a machine to recognize patterns and make decisions, much like how a human learns from experience. In machine learning, "learning a network" typically refers to training a model that involves multiple interconnected components, such as decision trees, random forests, or other algorithms that rely on a network-like structure. Here’s an overview of how to approach learning a network using traditional machine learning methods: Steps of Learning a Network in Machine Learning

1. Define the Problem - Objective: Clearly define the specific problem you aim to solve, such as classification, regression, or clustering.

  • Model Updates: Retrain or adjust the model based on new data or changes in data patterns. This approach focuses on using various machine learning algorithms and methods to build, train, and deploy models, while specifically avoiding any neural network-related concepts. Examples Example 1: Learning to Classify Fruits Imagine you have a set of fruits: apples, bananas, and oranges. You want to teach a machine to identify these fruits based on their characteristics like color and shape. 1. Data Collection : You gather examples of apples, bananas, and oranges, noting their features (e.g., color and shape). For example, apples might be red and round, bananas are yellow and curved, and oranges are orange and round. 2. Learning Process : You show these examples to the machine. The machine looks at the features of each fruit and tries to understand how these features distinguish each type of fruit. It learns that:
  • Apples are often red and round.
  • Bananas are yellow and curved.
  • Oranges are orange and round. 3. Making Predictions : After learning, the machine can now look at a new fruit, check its color and shape, and predict whether it’s an apple, banana, or orange based on what it has learned. Example 2: Learning to Recognize Handwriting Think about teaching a machine to recognize handwritten numbers from 0 to 9. 1. Data Collection : You collect many examples of handwritten numbers. For each number, you note its shape, size, and style. 2. Learning Process : The machine examines all these handwritten numbers and learns how each digit looks. For example, it learns that:
  • The number 1 usually has a straight vertical line.
  • The number 8 has two loops stacked on top of each other. 3. Making Predictions : Once the machine has learned the patterns, you can show it a new handwritten number, and it can predict whether it’s a 0, 1, 2, or any other digit based on what it has learned from the examples. How Does It Work? o Patterns and Features: The machine looks for patterns and features in the data. In the fruit example, it focuses on color and shape; in the handwriting example, it looks at the shape and style of the digits. o Learning from Examples: Just like a student learns from practice problems, the machine learns from many examples to understand how to make accurate predictions. o Applying Knowledge: After learning, the machine can apply its knowledge to new, unseen examples and make educated guesses or decisions based on what it has learned.

In essence, learning a network involves teaching a machine to recognize patterns and make decisions by showing it many examples and letting it figure out how to use those examples to understand and predict new data. Example: Image Classification Example: Spam Email Filtering Here's a simplified Python program for classifying emails as spam or not spam. This version focuses on taking user input and predicting the classification. _import pandas as pd from sklearn.linear_model import LogisticRegression from sklearn.feature_extraction.text import CountVectorizer

Sample dataset (email text and labels)

data = { 'Email': [ 'Win a million dollars now!', # Spam 'Important meeting tomorrow', # Not Spam 'Get cheap loans and credit', # Spam 'Your invoice is attached', # Not Spam 'Special promotion just for you', # Spam 'Schedule your appointment', # Not Spam ], 'Label': [1, 0, 1, 0, 1, 0] # 1 for Spam, 0 for Not Spam }

Create DataFrame

df = pd.DataFrame(data)

Features and target variable

X = df[['Email']] # Feature: Email text y = df['Label'] # Target: Spam (1) or Not Spam (0)

Convert email text to numerical features using CountVectorizer

vectorizer = CountVectorizer() X_vectorized = vectorizer.fit_transform(X)

Create and train the model

model = LogisticRegression() model.fit(X_vectorized, y)

Take user input for prediction

user_email = input("Enter an email to classify: ") user_email_vectorized = vectorizer.transform([user_email]) prediction = model.predict(user_email_vectorized)[0]_

 Rows represent individual data points or observations.  Columns represent features or attributes of those data points. Why Are Datasets Used?  Training AI Models: To teach algorithms to recognize patterns or make predictions.  Testing Models: To evaluate how well a model performs on new, unseen data.  Analyzing Trends: To identify patterns and insights in data.  Informed Decision-Making: To make data-driven decisions in various fields like business, healthcare, and government.

Types of Datasets with Easy Examples:

In machine learning (ML), datasets come in various types, each tailored for specific tasks and types of analysis. Here’s a detailed overview of common dataset types used in ML, along with simple examples:

1. Training Dataset  Purpose: To train a machine learning model by exposing it to examples.  Example: A dataset of labeled images used to train a model to recognize objects (e.g., a collection of images labeled as "cat" or "dog"). 2. Validation Dataset  Purpose: To tune the model’s parameters and select the best version of the model.  Example: A separate set of labeled images (not used in training) to fine-tune a model’s hyperparameters and avoid overfitting. 3. Test Dataset  Purpose: To evaluate the final model’s performance on unseen data.  Example: A set of images that the model has not seen before, used to assess how well the model generalizes to new data. 4. Numerical Dataset  Purpose: Contains numerical data points for statistical analysis or predictive modeling.  Example: A dataset with features like “Temperature,” “Humidity,” and “Precipitation” used to predict weather conditions. 5. Categorical Dataset  Purpose: Contains data divided into categories or classes.  Example: A dataset with “Color” (Red, Blue, Green) and “Product Type” (Electronics, Clothing) used for classifying products. 6. Time Series Dataset  Purpose: Data collected over time, often used for forecasting and trend analysis.  Example: Daily stock prices over a year, with columns for “Date” and “Closing Price,” used to predict future stock prices. 7. Image Dataset  Purpose: Contains images used for computer vision tasks such as classification and object detection.  Example: A dataset of medical X-rays labeled with various conditions (e.g., “Pneumonia” or “Healthy”) used to train a model to detect diseases. 8. Text Dataset  Purpose: Contains text data for natural language processing tasks.

 Example: A dataset of movie reviews with text and corresponding sentiment labels (e.g., “Positive” or “Negative”) used for sentiment analysis.

9. Web Dataset  Purpose: Data collected from web sources, often in JSON or XML format.  Example: Data from an API showing “User Information” (name, email, location) retrieved from a social media platform. 10. Structured Dataset  Purpose: Data organized into tables with rows and columns.  Example: A relational database table with columns for “Customer ID,” “Purchase Amount,” and “Date” used for analyzing purchasing behavior. 11. Unstructured Dataset  Purpose: Data that does not have a predefined structure, often requiring more complex processing.  Example: Raw social media posts or emails, where the data is in free-form text and needs processing for sentiment analysis or topic modeling. 12. Semi-Supervised Dataset  Purpose: Combines a small amount of labeled data with a large amount of unlabeled data to improve learning.  Example: A dataset with 100 labeled images of animals and 1,000 unlabeled images used to enhance model performance with limited labels. 13. Synthetic Dataset  Purpose: Artificially generated data used when real data is scarce or not available.  Example: Simulated data of traffic patterns generated to train models for traffic prediction when real data is limited. 14. Multivariate Dataset  Purpose: Contains multiple features that are used together for analysis or modeling.  Example: A dataset with features like “Age,” “Income,” and “Education Level” used to predict “Credit Score.” 15. Bivariate Dataset  Purpose: Contains two variables that are analyzed for their relationship.  Example: A dataset with “Height” and “Weight” measurements used to understand the correlation between these two variables. Each type of dataset serves specific purposes in ML workflows, helping to develop, validate, and deploy models effectively.

Feature sets and how datasets are divided

In machine learning, understanding feature sets and how datasets are divided into training, validation, and test sets is crucial for building robust models. Here's an explanation along with examples: Feature Sets: Feature sets refer to the input variables or attributes used to train a machine learning model. These features represent different aspects or characteristics of the data that the model uses to make predictions or classifications. Features can be numeric, categorical, text-based, or derived from other data. Example of Feature Sets: o Housing Price Prediction:

| 1500 | 3 | 2 | Downtown | 300,000 | | 2000 | 4 | 3 | Suburbs | 400,000 | | 1200 | 2 | 1 | Downtown | 250,000 | Here, Square Footage, Number of Bedrooms, Number of Bathrooms, and Location are features used to predict the Price of the house. Dataset Division:

1. Training Set: - Purpose: Train the model. - Example: 80% of the dataset is used for training. For instance, if you have 100 houses, you might use data from 80 houses to train the model. 2. Validation Set: - Purpose: Tune model parameters and avoid overfitting. - Example: 10% of the dataset is used for validation. From the same 100 houses, you use data from 10 houses to tune your model. After training the model on the training set, you test the model on these 10 houses to check how well it performs. Based on this performance, you might adjust the model’s parameters (like learning rate or number of features) to improve performance. This process helps in selecting the best model configuration. 3. Test Set: - Purpose: Evaluate model performance. - Example: The remaining 10% of the dataset is used for testing. The data from the final 10 houses is used to assess how well the model performs on unseen data. Example 2: Classifying Emails as Spam or Not Spam Feature Sets: In a dataset for classifying emails, the feature set might include:  Email Subject: The subject line of the email.  Number of Links: The count of hyperlinks in the email.  Email Length: The length of the email in terms of word count.  Presence of Keywords: Whether certain keywords (e.g., “offer,” “free,” “win”) appear in the email. Example Data: | Email Subject | Number of Links | Email Length | Presence of Keywords | Label | |-----------------------------|------------------------------|--------------|------------------------------|---------| | “Win a free iPhone!” | 3 | 50 | Yes | Spam | | “Meeting at 3 PM” | 0 | 20 | No | Not Spam| | “Special offer just for you” | 2 | 40 | Yes | Spam | Here, Email Subject, Number of Links, Email Length, and Presence of Keywords are features used to classify the email as Spam or Not Spam. Dataset Division:

  1. Training Set:
    • Purpose: Train the classification model.
    • Example: 80% of the dataset is used for training. If you have 100 emails, you might use 80 of them to train the model.
  2. Validation Set:
    • Purpose: Adjust model settings and avoid overfitting.
    • Example: 10% of the dataset is used for validation. You use 10 emails out of 100 for validation. After training the model on the training set, you evaluate it on these 10 emails to see how well it classifies them. This helps you to make decisions about which model settings (e.g., choice of features, tuning thresholds) work best. For example, if the model performs poorly on the validation set, you might need to adjust the feature selection or change the model parameters
  3. Test Set:
    • Purpose: Measure how well the model works on new data.
    • Example: The remaining 10% of the dataset, or 10 emails, is used for testing to see how accurately the model classifies unseen emails. These examples show how datasets can be structured with feature sets and how they are divided into different subsets to train, validate, and test machine learning models. In summary, feature sets provide the inputs for training machine learning models, while dataset division into training, validation, and test sets ensures that the model is trained effectively, fine-tuned for optimal performance, and evaluated comprehensively before deployment in real-world applications. This structured approach helps in building models that generalize well and make reliable predictions or classifications on new data.

Cross-validation in machine learning

Cross-validation is a technique used to assess the performance and generalization ability of a machine learning model. It involves partitioning the data into subsets to train and validate the model multiple times, providing a more reliable estimate of its performance compared to a single train-test split. Here’s an explanation of different cross-validation methods with simple examples, limitations, and applications:

1. Validation Set Approach - Description: This method involves splitting the dataset into two parts: a training set and a validation set. The model is trained on the training set and evaluated on the validation set. - Example: If you have a dataset of 100 samples, you might use 80 samples for training and 20 samples for validation. After training the model on the 80 samples, you test its performance on the 20 samples. - Limitation: The model’s performance is dependent on the specific split, which might not be representative of the overall dataset. 2. Leave-P-Out Cross-Validation - Description: This method involves splitting the dataset into multiple training and validation sets, where P samples are left out for validation in each iteration, and the remaining samples are used for training.

 Model Selection: Helps in comparing different models and choosing the best one based on performance metrics.  Hyperparameter Tuning: Used to find the optimal hyperparameters by evaluating model performance on different sets of parameters.  Performance Estimation: Provides a more reliable estimate of a model’s ability to generalize to new data, reducing the risk of overfitting or underfitting. By using these cross-validation methods, you can obtain a more accurate estimate of how well your model performs and ensure that it generalizes well to new data_._ Self-Assessment Questions:

_1. Describe the concept of Machine Learning in simple terms.

  1. Explain the criteria that define whether a system is "learning" in the context of Machine Learning.
  2. Discuss different methods to evaluate the performance of Machine Learning models.
  3. Outline the basic steps involved in training a Machine Learning model.
  4. What are datasets in Machine Learning, and why are they important?
  5. Explain how datasets should be handled and preprocessed before training a model.
  6. What is a feature set, and how does it influence the learning process of a Machine Learning model?
  7. Differentiate between the training set, validation set, and test set in the context of Machine Learning.
  8. Describe the purpose of dividing a dataset into training, validation, and test sets.
  9. How does cross-validation improve the reliability of a Machine Learning model's evaluation?
  10. What are some common challenges associated with handling and preparing datasets for Machine Learning tasks?_

List of practical’s (lab)

1. Make use of Data sets in implementing the machine learning algorithms.

_Python program that also takes user input for predicting salaries based on years of experience: import pandas as pd from sklearn.linear_model import LinearRegression

Load the dataset from a CSV file

data = pd.read_csv('salary_data.csv')

Features and target variable

X = data[['Experience']] # Feature: Years of Experience y = data['Salary'] # Target: Salary

Create and train the model

model = LinearRegression() model.fit(X, y)

Take user input for prediction

user_experience = float(input("Enter years of experience: "))

Predict salary for the user input

predicted_salary = model.predict([[user_experience]])[0]_

print(f'Predicted Salary for {user_experience} years of experience: ${predicted_salary:.2f}') Explanation

_1. Load the Dataset: The pd.read_csv function loads data from salary_data.csv into a DataFrame. This file should be in the same directory as your script or provide the full path.

  1. Prepare Features and Target: The feature (Experience) and target (Salary) are separated.
  2. Create and Train Model: LinearRegression() creates a linear regression model. The fit method trains the model on the entire dataset.
  3. User Input: The program asks the user to enter their years of experience.
  4. Predict Salary: The predict method is used to estimate the salary based on the user's input. The input is converted into a format suitable for prediction (a list of lists).
  5. Display Prediction: The program prints out the predicted salary based on the user-provided years of experience. This code allows users to input their years of experience and receive a salary prediction based on the trained model. Make sure the salary_data.csv file is formatted correctly and accessible._

2. Implement the machine learning concepts and algorithms in any suitable language of choice.

The above provided program belongs to the machine learning concept and algorithm of Linear Regression. Linear Regression is a fundamental supervised learning algorithm used to model and analyze the relationship between a dependent variable (in this case, salary) and one or more independent variables (years of experience). In the program, the dataset consists of historical data on years of experience and corresponding salaries. By training the Linear Regression model on this dataset, the program learns how salary tends to increase with years of experience. The fit method estimates the best-fit line that represents this relationship. When the user inputs a new value for years of experience, the trained model uses this relationship to predict the corresponding salary. This predictive capability is the core of machine learning: using historical data to make informed predictions or decisions about new, unseen data. Linear Regression is a key algorithm because of its simplicity and interpretability, making it an ideal starting point for understanding machine learning concepts.

3. Write a program to implement a perceptron.

A Perceptron is a basic type of artificial neural network used for binary classification tasks. It's the simplest form of a neural network and can be seen as a linear classifier that separates data into two classes. The Perceptron algorithm updates weights based on errors made on training data, learning to classify data points by finding a decision boundary. Python Program to Implement a Perceptron _Here's a Python program using the sklearn library to implement a Perceptron with a simple dataset. This example takes user input for prediction: from sklearn.linear_model import Perceptron import numpy as np

Sample dataset: Features and labels

Features: [Hours Studied, Number of Practice Exercises]

Labels: 0 = Fail, 1 = Pass

X = np.array([[1, 2], [2, 1], [2, 3], [3, 1], [3, 2]]) y = np.array([0, 0, 1, 1, 1])_