FINAL Lab-1-81
FINAL Lab-1-81
III SEMESTER
CODE: 551305
Submitted By
NAME :
REG. NO. :
This is to certify that the bonafide record work is done by Mr. / Ms.
II DATA ANALYTICS
1 16/10/2024 INSTALLING APACHE HADOOP 63
2 17/10/2024 A PRIORI ALGORITHM 70
3 26/10/2024 CLUSTERING ALGORITHM 75
4 30/10/2024 REGRESSION ALGORITHM 77
5 06/11/2024 K-MEANS NEAREST NEIGHBOUR 83
ALGORITHM
ADVANCED WEB
TECHNOLOGY
EX NO: 1 PAGE
CREATING WEB PAGE
DATE: 19/07/2024 NO: 05
Aim:
To create a web pages with advanced layouts and positioning with CSS and
HTML.
Algorithm:
Create and open a text file or notepad.
Type the html coding for creating a webpage with advanced layouts.
Save the file a “fileName.html”. ( .html as extension)
The html file will be created in the specified location.
Just open the created html file to see output.
5
Program:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Advanced Layout Example</title>
</head>
<body>
<!-- Grid Layout -->
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
</div>
/* Flexbox Layout */
.flex-container {
display: flex;
justify-content: space-between;
margin-top: 20px;
background-color: #f0f0f0;
padding: 10px;
}
.flex-item {
background-color: lightcoral;
padding: 10px;
flex: 1;
text-align: center;
}
/* Float Layout */
.float-container::after {
content: "";
display: table;
clear: both;
}
.float-left {
float: left;
width: 50%;
background-color: lightgreen;
padding: 10px;
}
.float-right {
float: right;
width: 50%;
background-color: yellow;
padding: 10px;
}
</style>
</html>
7
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
8
EX NO: 2 PAGE
CSS FUNCTION
DATE: 24/07/2024 NO: 09
Aim:
To develop and demonstrate the usage of inline, internal and external style
sheet using CSS.
Algorithm:
Open a text file or notepad.
Type the html coding to demonstrate the CSS functions.
And save the file with .html extension.
Also create another text file for the external CSS function and save as .css
as extension.
Save the html and the css file in the same folder.
Then open the created html file to get the result.
9
Program:
<html>
<head>
<style type="text/css">
body
{
background-image:url('images/cse.png');
background-repeat:no-repeat;
background-position:center center;
background-attachment:fixed;
background-color:pink;
}
a:link { text-decoration:none;color:orange; }
a:visited { text-decoration:none;color:red; }
a:hover { text-decoration:underline;color:blue; }
a:active { text-decoration:underline;color:purple; }
h3 { color:green; }
.c1{cursor:crosshair}
.c2{cursor:pointer}
.c3{cursor:move}
.c4{cursor:text}
.c5{cursor:wait}
.c6{cursor:help}
</style>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body bgcolor="cyan">
<h1 style="color:blue;text-align:center;"> CSS (Inline, Internal and External)
</h1>
<p>This Paragraph is a Not Styled</p>
<p class="left">This Paragraph is Styled by class "Left"</p>
<p class="center">This Paragraph is Styled by class "Center"</p>
<p class="right">This Paragraph is Styled by class "Right"</p>
<b>This is normal Bold</b> <br>
<b id="headline">This Bold Text is Styled </b>
<h2><b><a href=" ">This is a link</a></b></h2>
<h3 class="c1">The cursor over this element is plus sign</h3>
10
<h3 class="c2">The cursor over this element is a pointing hand</h3>
<h3 class="c3">The cursor over this element is a grasping hand</h3>
<h3 class="c4">The cursor over this element is a I bar</h3>
<h3 class="c5">The cursor over this element is a wait</h3>
<h3 class="c6">The cursor over this element is a question mark</h3>
</html>
Style.css
.left
{
color:yellow;
text-align:left;
padding:10;
}
.center
{
color:darkblue;
text-align:center;
padding:10;
}
.right
{
color:purple;
text-align:right;
padding:10;
}
11
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
12
EX NO: 3
PAGE
DATE: 31/07/2024 VALIDATION USING JAVASCRIPT
NO: 13
Aim:
To perform validations in a web page using JavaScript.
Algorithm:
Open a text file or notepad.
Type the JavaScript code with html to perform validation functions in a
web page.
Example to get and validate FirstName, LastName, Password, E-mail,
Mobile Number, Address, etc.
Then save as file as .html extension.
Open the saved html file to see results.
13
Program:
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script>
function validateForm() {
// Get form values
var firstName = document.forms["myForm"]["firstName"].value;
var lastName = document.forms["myForm"]["lastName"].value;
var mobileNumber = document.forms["myForm"]["mobileNumber"].value;
var password = document.forms["myForm"]["password"].value;
var address = document.forms["myForm"]["address"].value;
// Perform validation
if (firstName === "") {
alert("Please enter your First Name.");
return false;
}
14
if (address === "") {
alert("Please enter your Address.");
return false;
}
// Form submitted successfully
alert("Form submitted successfully!");
return true;
}
</script>
</head>
<body>
<form name="myForm" onsubmit="return validateForm()">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<label for="address">Address:</label>
<input type="text" id="address" name="address"><br><br>
15
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
16
EX NO: 4
PAGE
DATE: 02/08/2024 POP-UP BOX USING JAVASCRIPT
NO: 17
Aim:
To Develop and demonstrate JavaScript with POP-UP boxes and functions.
Algorithm:
Open a text file or notepad.
Type the JavaScript code with html to get results in POP-UP Box and to
demonstrate JavaScript functions.
Examples to display Date, obtain factorial of n number, multiplication
table, and add two numbers.
Then save as file as .html extension.
Open the saved html file to see results.
17
Program:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Popup Boxes and Functions</title>
<script>
// Function to display the current date in a textbox
function displayDate() {
var currentDate = new Date().toDateString();
document.getElementById("dateTextBox").value = currentDate;
}
18
function calculateSum() {
var number = parseInt(prompt("Enter a number:"));
var additionalNumber = parseInt(prompt("Enter an additional number:"));
var sum = number + additionalNumber;
alert("Sum of " + number + " and " + additionalNumber + " is: " + sum);
}
</script>
</head>
<style>
div{
text-align: center;
width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-color:grey;
border-width: 5px;
}
</style>
<body>
<h2 style="text-align:center">JavaScript Popup Boxes and Functions</h2>
<div clas="cont">
<button onclick="displayDate()">Display Date</button>
<input type="text" id="dateTextBox" readonly><br><br><br>
<button onclick="calculateFactorial()">Calculate
Factorial</button><br><br><br>
19
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
20
EX NO: 5
PAGE
DATE: 07/08/2024 AUTHETICATION WEBPAGE
NO: 21
Aim:
To create an authentication webpage using html and css.
Algorithm:
Open a text file or notepad.
Type the JavaScript code with html and JavaScript to create
authentication webpage.
Get a User ID and Password as an input in the webpage.
Then save as file as .html extension.
Open the saved html file to see results.
21
Program:
<html>
<head><title>Authentication page</title>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name===""){
alert("Name can't be blank");
return false;
}else if(password.length<6){
alert("Password must be at least 6 characters long.");
return false;
}
alert("successfully submited");
return true;
}
</script>
<style>
body
{
fontfamily:Arial,sans-serif;
}
.container
{
background-color:pink;
width: 300px;
margin:0 auto;
margin-top: 100px;
border: 3px solid black;
padding: 20px
box-sizing: border-box;
text-align: center;
}
h1
{
22
color:black;
}
input[type="text"], input[type="password"]
{
width: 100%;
padding: 10px;
margin-bottom: 10px;
box-sizing:border-box;
}
.btn
{
background-color:green;
padding:10px 30px;
cursor:pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>Authentication</h1>
<form name="myform" method="post" onsubmit="return validateform()" >
Name: <input type="text" name="username"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="login" class="btn">
</form>
</body>
</html>
23
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
24
EX NO: 6
PAGE
DATE: 09/08/2024 ROLL OVER MENU USING JAVASCRIPT
NO: 25
Aim:
To Implement the Roll over menus using JavaScript
Algorithm:
Open a text file or notepad.
Type the JavaScript code to implement the roll over menu bars in the
webpage.
Then save as file as .html extension.
Open the saved html file to see results.
.
25
Program:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
background-color: #3498DB;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropbtn:hover, .dropbtn:focus {
background-color: #2980B9;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
26
text-decoration: none;
display: block;
}
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Dropdown</button>
<div id="myDropdown" class="dropdown-content">
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</div>
</div>
<script>
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
27
}
}
}
</script>
</body>
</html>
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
28
EX NO: 7
PAGE
DATE: 16/08/2024 COOKIES AND SESSION IN PHP
NO: 29
Aim:
To Implement Cookies and Session in PHP.
Algorithm:
Download and install XAMPP server to run local server programs.
Start the Apache module in the XAMPP server.
Then open a text file or notepad.
Type the php coding to implement cookies and Session.
Then save file as “.php extension” in a folder inside the C:\xampp\htdocs
location.
Now launch the localhost/folderName to get output.
29
Program:
<?php
// Starting a session
session_start();
<!DOCTYPE html>
<html>
<head>
<title>Cookie and Session Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
30
}
form {
display: flex;
flex-direction: column;
max-width: 200px;
margin: 20px auto;
}
label {
margin-bottom: 5px;
}
input[type="text"] {
padding: 5px;
margin-bottom: 10px;
}
input[type="submit"] {
padding: 5px 10px;
}
</style>
</head>
<body>
<h1>Welcome <?php echo $username; ?></h1>
<?php
// Display a login form if the username is not set
if ($username == "") {
?>
<form method="POST" action="">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required>
<input type="submit" name="submit" value="Login">
</form>
<?php
} else {
31
// Display logout button if the username is set
?>
<form method="POST" action="">
<input type="submit" name="logout" value="Logout">
</form>
<?php
}
?>
<?php
// Check if the logout button is clicked
if (isset($_POST['logout'])) {
// Delete the "username" cookie
setcookie('username', '', time() - 3600, '/');
32
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
33
EX NO: 8 PAGE
SESSION IN PHP NO: 34
DATE:30/08/2024
Aim:
To Implement of Session in PHP
Algorithm:
Download and install XAMPP server to run local server programs.
Start the Apache module in the XAMPP server.
Then open a text file or notepad.
Type the php coding to implement Session.
Then save file as “.php extension” in a folder inside the C:\xampp\htdocs
location.
Now launch the localhost/folderName to get output.
34
Program:
<?php
// Starting the session
session_start();
35
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
36
EX NO: 9
BOOK INFORMATION USING PHP & PAGE
DATE:11/09/2024 MYSQL NO: 37
Aim:
To develop a program to create and accept book information using PHP and
MySQL.
Algorithm:
Download and install XAMPP server to run local server programs.
Start the Apache module and MySQL in the XAMPP server.
Then open a text file or notepad.
Type the php coding to get book information and store it in MySQL
database.
Then save file as “.php extension” in a folder inside the C:\xampp\htdocs
location.
Here, we have create two php file so-called library.php and process.php.
Now launch the localhost/folderName to get output.
37
Program:
Library.php
<!DOCTYPE html>
<html>
<head>
<title>Book Information</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
}
form {
max-width: 400px;
margin: 20px auto;
padding: 20px;
background-color: #f4f4f4;
border: 1px solid #ccc;
border-radius: 5px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"],
input[type="date"],
input[type="number"] {
width: 100%;
padding: 5px;
margin-bottom: 10px;
38
border: 1px solid #ccc;
border-radius: 3px;
}
button[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 3px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Book Information</h1>
<label for="author">Author:</label>
<input type="text" name="author" id="author" required>
<label for="price">Price:</label>
<input type="number" name="price" id="price" step="0.01">
<button type="submit">Submit</button>
</form>
</body>
</html>
39
Process.php
<?php
$hostname = 'localhost';
$username = 'root';
$password = '';
$database = 'library';
40
// Close the statement
mysqli_stmt_close($stmt);
41
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
42
EX NO: 10
XML DOCUMENT TO STORE PAGE
DATE: 13/09/2024 INFORMATION NO: 43
Aim:
To Design an XML document to store information about students
Algorithm:
Open a text file or notepad.
Type the xml coding to store student information in it.
Then save file as “.xml extension” in a folder.
Then click the created xml file to see output.
43
Program:
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student>
<id>1</id>
<name>John Doe</name>
<email>[email protected]</email>
<courses>
<course>
<code>MATH101</code>
<name>Mathematics 101</name>
<instructor>Professor Smith</instructor>
<grade>A-</grade>
</course>
<course>
<code>ENG101</code>
<name>English 101</name>
<instructor>Professor Johnson</instructor>
<grade>B+</grade>
</course>
</courses>
</student>
<student>
<id>2</id>
<name>Jane Smith</name>
<email>[email protected]</email>
<courses>
<course>
<code>PHYS101</code>
<name>Physics 101</name>
<instructor>Professor Brown</instructor>
<grade>A</grade>
</course>
<course>
<code>HIST101</code>
<name>History 101</name>
<instructor>Professor Davis</instructor>
44
<grade>A+</grade>
</course>
</courses>
</student>
</students>
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
45
EX NO: 11
PAGE
DATE: 18/09/2024 XML DOM OBJECT NO: 46
Aim:
To create an application that loads a text string into an XML DOM object,
and extracts the info from it with JavaScript.
Algorithm:
Open a text file or notepad.
Type the html coding using javascript to store xml DOM object in a
string.
Then save file as “.html extension” in a folder.
Then open the html file to see output.
46
Program:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var parser, xmlDoc;
var text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
</script>
</body>
</html>
47
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
48
EX NO: 12
PAGE
DATE: 25/09/2024 XML Http REQUEST – TEXT FILE
NO: 49
Aim:
To create a simple XML Http Request, and retrieve data from a TXT file.
Algorithm:
Start the Apache module in the XAMPP server.
Then open a text file or notepad.
Type the html coding to create an XMLHttpRequest.
Then save file as “.html extension” in a folder inside the C:\xampp\htdocs
location.
Here, we have create a text file holding string data in it and saved in the
same folder, where the html program in saved.
Now launch the localhost/folderName to get output.
49
Program:
<html>
<head>
<title> XMLHttpRequest </title>
<script type="text/javascript">
function loadtxt()
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 )
{
if(xhr.status == 200)
{
document.getElementById("show").innerHTML = xhr.responseText;
}
}
};
xhr.open("get","Hello.txt",true);
xhr.send();
}
</script>
</head>
<body>
<div id="show"> </div>
<button onclick="loadtxt()"> Click Here </button>
</body>
</html>
Hello.txt
This is Example Program For Retriving Data From Text File Using
XMLHttpsRequest.
50
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
51
EX NO: 13
PAGE
DATE: 27/09/2024 XML Http REQUEST – XML FILE
NO: 52
Aim:
To create an XML Http Request to retrieve data from an XML file and
display the data in an HTML table
Algorithm:
Start the Apache module in the XAMPP server.
Then open a text file or notepad.
Type the html coding to create a XMLHttpRequest to retrieve data from
an XML file.
Then save file as “.html extension” in a folder inside the C:\xampp\htdocs
location.
Here, we have create a text file holding xml data in it and saved in the
same folder, where the html program in saved with .xml extension.
Now launch the localhost/folderName to get output.
52
Program:
<!DOCTYPE html>
<html>
<head>
<title>XML HTTP Request Example</title>
<style>
table,th,td{
border: 1px solid black;
margin-left:500px;
text-align:center;
width:300px;
}
</style>
</head>
<body>
<h1 style="text-align:center">XML Data in HTML Table</h1>
<table id="data-table">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<th>Mk</th>
<th>25</th>
</tr>
</thead>
<tbody>
<!-- Data will be inserted here -->
</tbody>
</table>
<script>
// Create an XML HTTP request object
var xhttp = new XMLHttpRequest();
53
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Parse the XML response
var xmlDoc = this.responseXML;
var table = document.getElementById("data-table");
var tbody = table.getElementsByTagName("tbody")[0];
54
Data.xml
<data>
<person>
<name>Mk</name>
<age>25</age>
</person>
<person>
<name>Smk</name>
<age>27</age>
</person>
<person>
<name>Ak</name>
<age>24</age>
</person>
</data>
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
55
EX NO: 14
PAGE
DATE: 04/09/2024 SIMPLE APPLICATION USING NODE.JS NO: 56
Aim:
To develop a simple applications using node.js
Algorithm:
Download and install node.js version (v18.18.0) from official website.
After successfully installation of node.js, open a notepad and type the coding
for simple application.
Then, save the file in a folder with filename.js as extension.
Run the command prompt from the directory where the node.js program is
stored.
Program can be run using (node programName.js)
The go to the localhost:8081 to see the result output.
56
Program:
var http = require("http");
57
Output:
Result:
Thus, the above program has been executed and output is verified successfully.
58
EX NO: 15
PAGE
DATE: 09/10/2023 ANGULAR JS, NODE JS, & MYSQL NO: 59
Aim:
To program simple application with Angular JS, Node.JS and MySQL to access
database.
Algorithm:
Download and install the necessary file for Angular.js from the official
website.
The open a notepad and write the coding for simple application.
Remember to mention the source of the angular.js file in the coding.
Launch the saved html file to get the output
59
Program:
<html>
<head>
<title>AngularJS First Application</title>
</head>
<body>
<h1>Sample Application</h1>
</body>
</html>
60
Output:
Result:
Thus, the above program has been executed and output is verified successfully
61
DATA ANALYTICS
EX NO: 1 PAGE
INSTALLING APACHE HADOOP
DATE: 16/10/2024 NO: 63
Aim:
To install and set-up Apache Hadoop with operating node.
Procedure:
Download Apache Hadoop-3.3.0.tar package and extract to C: drive.
Then download and install Java Jdk-8 version.
Set System Environment Variable & path for both Hadoop and Java.
Hadoop configuration and modify five files in C:\hadoop\etc\hadoop.
Create two folder datanode & namenode inside another folder named as data in
C:\hadoop.
Format the namenode in HDFS.
Testing the setup by starting all demons using start-all.cmd.
Launch localhost: 8088 and localhost: 9870.
63
Coding:
64
*** Set Hadoop & Java bin directory path ***
</property>
</configuration>
65
2. Hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>C:\hadoop\data\namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>C:\hadoop\data\datanode</value>
</property>
</configuration>
3. Mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
4. Yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
</configuration>
66
5. Hadoop-env.cmd.
67
*** Format the namenode folder ***
Output:
Localhost: 8088
68
Localhost: 9870
Result:
Thus, the above program is executed successfully and the output is verified.
69
EX NO: 2 PAGE
A PRIORI ALGORITHM
DATE: 17/10/2024 NO: 70
Aim:
To implement the A Priori algorithm is used for finding frequent itemsets in a
transaction database
Procedure:
Set Parameters
Generate the Candidate Itemsets
Calculate the Support for Each Candidate Itemset
Generate Larger Candidate Itemsets
Prune Infrequent Itemsets
Repeat Steps 4-5 for k-itemsets (k ≥ 2)
Generate Association Rules from Frequent Itemsets
Stop When No More Frequent Itemsets or Strong Rules Exist.
70
Coding:
from itertools import combinations
def apriori():
# Get the unique items from all transactions
items = {item for t in transactions for item in t}
result = []
# Generate combinations of items for all sizes from 1 to the total number of unique items
for k in range(1, len(items) + 1):
for combo in combinations(items, k):
result.append(set(combo))
return result
71
Output:
Result:
Thus, the above program is executed successfully and the output is verified.
72
EX NO: 3 PAGE
CLUSTERING ALGORITHM
DATE: 26/10/2024 NO: 75
Aim:
The aim of this code is to demonstrate K-Means clustering on a synthetic 2D dataset
using the function to generate the data points
Procedure:
73
Coding:
kmeans.fit(X)
y_kmeans = kmeans.predict(X)
centers = kmeans.cluster_centers_
plt.figure(figsize=(8, 6))
plt.title('K-Means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.legend()
plt.grid(True)
74
OUTPUT:
Result:
Thus, the above program is executed successfully and the output is verified.
75
EX NO: 4 PAGE
REGRESSION ALGORITHM
DATE: 30/10/2024 NO: 77
Aim:
The aim of a regression algorithm is to model and establish the relationship between a dependent
variable (target variable) and one or more independent variables (predictors or features), with the
objective of predicting continuous values.
Procedure:
Import Libraries
Prepare the Data
Evaluate the model using performance metrics like Mean Squared Error (MSE) and R² score.
Visualize the regression line along with the training and testing data.
76
Coding:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
# Step 4: Evaluate the model using Mean Squared Error and R² Score
print("Mean Squared Error:", mean_squared_error(y_test, y_pred))
print("R² Score:", r2_score(y_test, y_pred))
77
Output:
Result:
Thus, the above program is executed successfully and the output is verified.
78
EX NO: 5 K-MEANS NEAREST NEIGHBOUR PAGE
DATE: 06/11/2024 NO: 83
Aim:
To implement the K-Nearest Neighbors (K-NN) algorithm is a supervised machine learning
algorithm used primarily for classification and regression tasks.
Procedure:
79
CODING:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
# Split the dataset into training and testing sets (80% training, 20% testing)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Visualize the data points with colors representing the true labels
plt.scatter(X[:, 0], X[:, 1], c=y, s=50, cmap='viridis', alpha=0.5)
plt.title('K-Nearest Neighbors Classification')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.show()
80
OUTPUT:
Result:
Thus, the above program is executed successfully and the output is verified.
81