0% found this document useful (0 votes)
21 views81 pages

FINAL Lab-1-81

Uploaded by

idhayaurcw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views81 pages

FINAL Lab-1-81

Uploaded by

idhayaurcw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

RECORD NOTE BOOK

MASTER OF COMPUTER SCIENCE

III SEMESTER

ADVANCED WEB TECHNOLOGY AND DATA


ANALYTICS LAB

CODE: 551305

Submitted By

NAME :

REG. NO. :

DEPARTMENT OF COMPUTER SCIENCE


ALAGAPPA UNIVERSITY
(Accredited with A+ Grade by NAAC (CGPA: 3.64) in the Third Cycle and
Graded as Category-I University by MHRD-UGC)
KARAIKUDI-630003
CERTIFICATE

This is to certify that the bonafide record work is done by Mr. / Ms.

(Reg No: ) in the third

semester of M.Sc. Computer Science course in ADVANCED WEB TECHNOLOGY

AND DATA ANALYTICS LAB (551305) at the Department of Computer Science,

Alagappa University, Karaikudi for November 2024 Examinations.

HEAD OF THE DEPARTMENT STAFF-IN-CHARGE

Submitted for the practical examination held on ...……………………..

INTERNAL EXAMINER EXTERNAL EXAMINER


TABLE OF CONTENT

S.NO DATE TOPIC PAGE


NO.
I ADVANCED WEB TECHNOLOGY
1 19/07/2024 CREATING WEB PAGE 05
2 24/07/2024 CSS FUNCTION 09
3 31/07/2024 VALIDATION USING JAVASCRIPT 13
4 02/08/2024 POP-UP BOX USING JAVASCRIPT 17
5 07/08/2024 AUTHETICATION WEBPAGE 21
6 09/08/2024 ROLL OVER MENU USING JAVASCRIPT 25
7 16/08/2024 COOKIES AND SESSION IN PHP 29
8 30/08/2024 SESSION IN PHP 34
9 11/09/2024 BOOK INFORMATION USING PHP & MYSQL 37
10 13/09/2024 XML DOCUMENT TO STORE INFORMATION 43
11 18/09/2024 XML DOM OBJECT 46
12 25/09/2024 XML Http REQUEST – TEXT FILE 49
13 27/09/2024 XML Http REQUEST – XML FILE 52
14 04/10/2024 SIMPLE APPLICATION USING NODE.JS 56
15 09/10/2024 ANGULAR JS, NODE JS, & MYSQL 59

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 -->


<div class="flex-container">
<div class="flex-item">Left Content</div>
<div class="flex-item">Center Content</div>
<div class="flex-item">Right Content</div>
</div>

<!-- Float Layout -->


<div class="float-container">
<div class="float-left">Left Content</div>
<div class="float-right">Right Content</div>
</div>
</body>
<style>
/* Grid Layout */
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
background-color: #f0f0f0;
padding: 10px;
}
.grid-item {
6
background-color: lightblue;
padding: 10px;
text-align: center;
}

/* 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;
}

if (lastName === "") {


alert("Please enter your Last Name.");
return false;
}

if (mobileNumber === "") {


alert("Please enter your Mobile Number.");
return false;
}

if (password === "") {


alert("Please enter your Password.");
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="lastName">Last Name:</label>


<input type="text" id="lastName" name="lastName"><br><br>

<label for="mobileNumber">Mobile Number:</label>


<input type="text" id="mobileNumber" name="mobileNumber"><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>

<input type="submit" value="Submit">


</form>
</body>
</html>

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;
}

// Function to calculate the factorial of a number


function calculateFactorial() {
var number = parseInt(prompt("Enter a number:"));
var factorial = 1;

for (var i = 1; i <= number; i++) {


factorial *= i;
}
alert("Factorial of " + number + " is: " + factorial);
}

// Function to display the multiplication table of a number from 1 to 10


function displayMultiplicationTable() {
var number = parseInt(prompt("Enter a number:"));
var table = "";

for (var i = 1; i <= 10; i++) {


var result = number * i;
table += number + " x " + i + " = " + result + "\n";
}

alert("Multiplication Table of " + number + ":\n\n" + table);


}

// Function to calculate the sum of a series of numbers

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>

<button onclick="displayMultiplicationTable()">Display Multiplication


Table</button><br><br><br>

<button onclick="calculateSum()">Calculate Sum</button>


</div>
</body>
</html>

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;
}

.dropdown a:hover {background-color: #ddd;}

.show {display: block;}


</style>
</head>
<body style="background-color:white;">
<h2>Clickable Dropdown</h2>
<p>Click on the button to open the dropdown menu.</p>

<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();

// Check if the "username" cookie is set


if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
} else {
$username = "";
}

// Check if the form is submitted


if (isset($_POST['submit'])) {
$username = $_POST['username'];

// Setting a cookie with the submitted username and lifetime of 5 minutes


setcookie('username', $username, time() + 300, '/');

// Storing the username in the session


$_SESSION['username'] = $username;
}
?>

<!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, '/');

// Destroy the session


session_destroy();

// Redirect to the login page


header("Location: index.php");
}
?>
</body>
</html>

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();

// Check if the form is submitted


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve the username from the form
$username = $_POST['username'];

// Store the username in the session


$_SESSION['username'] = $username;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Session Example</title>
</head>
<body>
<h1>Session Example</h1>

<?php if (isset($_SESSION['username'])): ?>


<p>Welcome, <?php echo $_SESSION['username']; ?>!</p>
<form method="post" action="">
<button type="submit" name="logout">Logout</button>
</form>
<?php else: ?>
<form method="post" action="">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required>
<button type="submit">Submit</button>
</form>
<?php endif; ?>
</body>
</html>

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>

<form method="post" action="process.php">


<label for="title">Title:</label>
<input type="text" name="title" id="title" required>

<label for="author">Author:</label>
<input type="text" name="author" id="author" required>

<label for="publication_date">Publication Date:</label>


<input type="date" name="publication_date" id="publication_date">

<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';

$conn = mysqli_connect($hostname, $username, $password, $database);

// Check the connection


if (!$conn) {
die('Connection failed: ' . mysqli_connect_error());
}
?>
<?php
// Retrieve the book information from the form
$title = $_POST['title'];
$author = $_POST['author'];
$publication_date = $_POST['publication_date'];
$price = $_POST['price'];

// Prepare the SQL statement


$sql = "INSERT INTO books (title, author, publication_date, price) VALUES
(?, ?, ?, ?)";

// Prepare and bind the parameters


$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, "sssd", $title, $author, $publication_date,
$price);

// Execute the statement


if (mysqli_stmt_execute($stmt)) {
$message="Book information inserted successfully!";
} else {
$message="Error inserting book information: " . mysqli_error($conn);
}

40
// Close the statement
mysqli_stmt_close($stmt);

// Close the database connection


mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<head>
<title>Book Information</title>
</head>
<body>
<script>
var message = "<?php echo addslashes($message); ?>";
var userInput = alert(message);
</script>
</body>
</html

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>";

parser = new DOMParser();


xmlDoc = parser.parseFromString(text,"text/xml");

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();

// Define the callback function to handle the response

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];

// Loop through the XML data and create table rows


var persons = xmlDoc.getElementsByTagName("person");
for (var i = 0; i < persons.length; i++) {
var name =
persons[i].getElementsByTagName("name")[0].textContent;
var age =
persons[i].getElementsByTagName("age")[0].textContent;

// Create a new row and cells


var row = tbody.insertRow();
var nameCell = row.insertCell(0);
var ageCell = row.insertCell(1);

// Populate the cells with data


nameCell.innerHTML = name;
ageCell.innerHTML = age;
}
}
};

// Open and send the HTTP request


xhttp.open("GET", "data.xml", true);
xhttp.send();
</script>
</body>
</html>

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");

http.createServer(function (request, response) {


// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});

// Send the response body as "Hello World"


response.end('Hello World\n');
}).listen(8081);

// Console will print the message


console.log('Server running at http://127.0.0.1:8081/');

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>

<div ng-app = "">


<p>Enter your Name: <input type = "text" ng-model = "name"></p>
<p>Hello <span ng-bind = "name"></span>! </p>
</div>

<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">


</script>

</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:

*** Verify Java version ***

*** Extract Hadoop at C:\Hadoop ***

 Rename Hadoop-3.3.0.tar into Hadoop.

*** Setting up the System Environment Variable ***

64
*** Set Hadoop & Java bin directory path ***

 Also add Hadoop sbin directory. (C:\hadoop\sbin)

*** Hadoop Configuration Files ***


 Go to ‘C:\hadoop\etc\hadoop’ and edit the following Configuration files:
1. Core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>

</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.

*** Creating datanode & namenode ***

1. Create folder “data” under “C:\hadoop”.


2. Create folder “datanode” under “C:\hadoop\data”.
3. Create folder “namenode” under “C:\hadoop\data”.

67
*** Format the namenode folder ***

*** Testing the setup ***

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

# Input transactions from the user


transactions = [set(input(f"Enter items for transaction {i+1} (space-separated): ").split())
for i in range(int(input("Enter the number of transactions: ")))]

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

# Output all possible itemsets


print("\nAll possible itemsets:")
for itemset in apriori():
print(" ".join(itemset))

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:

 Generate Synthetic Data


 Preprocess the Data
 Apply K-Means Clustering
 Visualize the Data
 Get Cluster Centers
 Plot the Results

73
Coding:

import matplotlib.pyplot as plt


from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans

X, y_true = make_blobs(n_samples=300, centers=4, cluster_std=0.60, random_state=0)

kmeans = KMeans(n_clusters=4, random_state=0)

kmeans.fit(X)

y_kmeans = kmeans.predict(X)

centers = kmeans.cluster_centers_

plt.figure(figsize=(8, 6))

plt.scatter(X[:, 0], X[:, 1], c=y_kmeans, s=50, cmap='viridis', label='Data points')

# Scatter plot of the cluster centers with a red 'X'


plt.scatter(centers[:, 0], centers[:, 1], c='red', s=200, alpha=0.75, marker='X', label='Cluster
Centers')

plt.title('K-Means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.legend()

plt.grid(True)

# Show the plot


plt.show()

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

 Split the dataset into training and testing sets.

 Train a linear regression model on the training set

 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

# Input data: Square footage (X) and house prices (y)


X = np.array([[500], [700], [800], [1000], [1200], [1500], [2000], [2500], [3000], [3500]])
y = np.array([150000, 200000, 230000, 275000, 300000, 375000, 450000, 500000, 600000,
650000])

# Step 1: Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Step 2: Create and train the Linear Regression model


model = LinearRegression()
model.fit(X_train, y_train)

# Step 3: Make predictions on the test set


y_pred = model.predict(X_test)

# 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))

# Step 5: Plot the results


plt.scatter(X_train, y_train, color='blue', label='Training Data')
plt.scatter(X_test, y_test, color='green', label='Test Data')
plt.plot(X, model.predict(X), color='red', label='Regression Line')
plt.xlabel('Square Footage')
plt.ylabel('House Price')
plt.legend()
plt.show()

77
Output:

Mean Squared Error: 1937500000.0


R² Score: 0.9867258908344897

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:

 Import Required Libraries

 Generate Synthetic Dataset

 Split Data into Training and Testing Sets


 Create the K-Nearest Neighbors Classifier

 Train the Model

 Make Predictions on the Test Data

 Evaluate the Model's Performance

 Visualize the Data

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

# Generate synthetic data with 3 centers (clusters)


X, y = make_blobs(n_samples=300, centers=3, random_state=0, cluster_std=1.0)

# 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)

# Initialize K-NN classifier with 5 neighbors


knn = KNeighborsClassifier(n_neighbors=5)

# Train the model on the training set


knn.fit(X_train, y_train)

# Make predictions on the test set


y_pred = knn.predict(X_test)

# Evaluate the accuracy of the model


accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)

# 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

You might also like