0% found this document useful (0 votes)
53 views70 pages

PHP and Linear Regression Solutions

Uploaded by

yadavaj752
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)
53 views70 pages

PHP and Linear Regression Solutions

Uploaded by

yadavaj752
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

WT SLIP SOLUTION

SLIP 1
Q. 1) Write a PHP script to keep track of number of times the web page has been accessed
(Use Session Tracking).
Ans:-
.php

<html>
<head>
<title> Number of times the web page has been visited.</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['count']))
$_SESSION['count']=$_SESSION['count']+1;
else
$_SESSION['count']=1;
echo "<h3>This page is accessed</h3>".$_SESSION['count'];
?>

Q. 2)Create ‘Position_Salaries’ Data set. Build a linear regression model by identifying


independent and target variable. Split the variables into training and testing sets. then
divide the training and testing sets into a 7:3 ratio, respectively and print them. Build a
simple linear regression model.
Ans:-
import numpy as np
import [Link] as plt
import pandas as pd
df=pd.read_csv(r'E:/dataset/Datasets/Salary_Data.csv')
df

print([Link])

print([Link]().sum)

new_df=df[['Salary','YearsExperience']]

new_df.sample(10)

import numpy as np
X = [Link](new_df[['Salary']])
Y = [Link](new_df[['YearsExperience']])
print([Link])
print([Link])

[Link](X,Y,color="red")
[Link]('Salary vs YearsExperience')
[Link]('Salary')
[Link]('YearsExperience')
[Link]()

from sklearn.model_selection import train_test_split


X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.25,random_state=15)
X_train
X_test
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.25,random_state=15)
Y_train
Y_test

from sklearn.linear_model import LinearRegression


regressor=LinearRegression()
[Link](X_train,Y_train)

LinearRegression()

[Link](X_train,Y_train,color="blue")
[Link](X_train,[Link](X_train),color="red",linewidth=3)
[Link]('Regression(Test Set)')
[Link]('Salary')
[Link]('YearsExperience')
[Link]()

[Link](X_train,Y_train,color="blue")
[Link](X_train,[Link](X_train),color="red",linewidth=3)
[Link]('Regression(training Set)')
[Link]('Salary')
[Link]('YearsExperience')
[Link]()
SLIP 2
Q. 1Write a PHP script to change the preferences of your web page like font style, font size,
font color, background color using cookie. Display selected setting on next web page and
actual implementation (with new settings) on third page (Use Cookies).

Ans:-
HTML file :

<html>
<body>
<form action="slip21_2_1.php" method="get">
<center>
<b>Select font style :</b><input type=text name=s1> <br>
<b>Enter font size : </b><input type=text name=s><br>
<b>Enter font color : </b><input type=text name=c><br>
<b>Enter background color :</b> <input type=text name=b><br>
<input type=submit value="Next">
</center>
</form>
</body>
</html>

PHP file : slip21_2_1.php

<?php
echo "style is ".$_GET['s1']."<br>color is ".$_GET['c']."<br>Background color is ".
$_GET['b']."<br>size is ".$_GET['s'];
setcookie("set1",$_GET['s1'],time()+3600);
setcookie("set2",$_GET['c'],time()+3600);
setcookie("set3",$_GET['b'],time()+3600);
setcookie("set4",$_GET['s'],time()+3600);
?>

<html>
<body>
<form action="slip21_2_2.php">
<input type=submit value=OK>
</form>
</body>
</html>

PHP file : slip21_2_2.php


<?php
$style = $_COOKIE['set1'];
$color = $_COOKIE['set2'];
$size = $_COOKIE['set4'];
$b_color = $_COOKIE['set3'];
$msg = "NR Classes";
echo "<body bgcolor=$b_color>";
echo "<font color=$color size=$size>$msg";
echo "</font></body>";
?>
Q. 2)Create ‘Salary’ Data set . Build a linear regression model by identifying independent
and target variable. Split the variables into training and testing sets and print them. Build a
simple linear regression model for predicting purchases.

Ans:-
import numpy as np
import [Link]

Import pandas as pd
df=pd.read_csv(r'C:\Users\HP\Documents\DS\Salary_Data.csv')
df

import [Link] as plt


from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from [Link] import r2_score,mean_squared_error
%matplotlib inline
[Link](5)

print('Shape of dataset=',[Link])

import numpy as np
X = [Link](df[['Height']])
Y = [Link](df[['Weight']])
print([Link])
print([Link])

X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.2,random_state=42)

model=LinearRegression()
[Link](X_train,Y_train)

[Link](X_test,Y_test,color="red")
[Link]('Height vs Weight')
[Link]('Height')
[Link]('Weight')
[Link]()

[Link](X_train,Y_train,color="blue")
[Link](X_train,[Link](X_train),color="red",linewidth=3)
[Link]('Regression(training Set)')
[Link]('Height')
[Link]('Weight')
[Link]()

slip 3
Q. 1) Write a PHP script to accept username and password. If in the first three chances,
username and password entered is correct then display second form with “Welcome
message” otherwise display error message. [Use Session]

Ans:-

HTML file :

<html>
<head>
<script>
function getans()
{
st1=[Link]('txtname').value;
st2=[Link]('txtpass').value;
ob=new XMLHttpRequest();
[Link]=function()
{
if([Link]==4 && [Link]==200)
{
if([Link]==3)
{
alert("sorry you lost the chances to login");
location="[Link]";
}
else if([Link]=="correct")
{
alert("you entered correct details");
}
else alert([Link]);
}
}
[Link]("GET","slip8_Q2.php?n="+st1+"&p="+st2);
[Link]();
}
</script>
</head>
<body>
<input type=text id=txtname placeholder="username"></br>
<input type=password id=txtpass placeholder="password"></br>
<input type="button" onclick="getans()" value="Login">
</body>
</html>
HTML file : [Link]

<html>
<body>
<h1>YOu lossed the chances of login</h1>
</body>
</html>

PHP file :
<?php
session_start();
$nm=$_GET['n'];
$ps=$_GET['p'];
if($nm==$ps)
{
echo "correct";
}
else if(isset($_SESSION['cnt']))
{
$x=$_SESSION['cnt'];
$x=$x+1;
$_SESSION['cnt']=$x;
echo $_SESSION['cnt'];
if($_SESSION['cnt']>=3)
$_SESSION['cnt']=1;
}
else
{
$_SESSION['cnt']=1;
echo "1";
}
?>

Q. 2)Create ‘User’ Data set having 5 columns namely: User ID, Gender, Age, Estimated
Salary and Purchased. Build a logistic regression model that can predict whether on the
given parameter a person will buy a car or not.

Ans:-
import numpy as np
import [Link] as plt
import pandas as pd
df = pd.read_csv("/root/sampada_vaibhavi/Data Anlytics/dataset/[Link]")
df

x= [Link][:, [2,3]].values
y= [Link][:, 4].values
x

x= [Link][:, [2,3]].values
y= [Link][:, 4].values
y

from sklearn.model_selection import train_test_split


x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.25, random_state=0)
x_train
x_test
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.25, random_state=0)
y_train
y_test

from sklearn.linear_model import LogisticRegression


logistic_regression=LogisticRegression()
logistic_regression.fit(x_train,y_train)
y_pred=logistic_regression.predict(x_test)

from sklearn import metrics


import seaborn as sn
import [Link] as plt
confusion_matrix=[Link](y_test,y_pred,rownames=['Actual'],colnames=['Predicted'])
[Link](confusion_matrix,annot=True)
print('Accuracy:',metrics.accuracy_score(y_test,y_pred))
[Link]

print(x_test)
print(y_pred)
SLIP 4
Q. 1) Write a PHP script to accept Employee details (Eno, Ename, Address) on first page. On
second page accept earning (Basic, DA, HRA). On third page print Employee information
(Eno, Ename, Address, Basic, DA, HRA, Total) [ Use Session]
Ans:-

HTML file :
<html>
<body>
<form action="slip18_2_1.php" method="get">
<center> <h2>Enter Enployee Details :</h2> <br>
<table>
<tr> <td><b>Emp no :</b></td> <td><input type=text name=eno></td> </tr>
<tr> <td><b> Name :</b></td> <td><input type=text name=enm></td> </tr>
<tr> <td><b>Address :</b></td> <td><input type=text name=eadd></td>
</tr>
</table>
<br> <input type=submit value=Show name=submit>
</center>
</form>
</body>
</html>

PHP file : slip_18_2_1.php

<?php
session_start();
$eno = $_GET['eno'];
$enm = $_GET['enm'];
$eadd = $_GET['eadd'];
$_SESSION['eno'] = $eno;
$_SESSION['enm'] = $enm;
$_SESSION['eadd'] = $eadd;
?>
<html>
<body>
<form action="slip18_2_2.php" method="post">
<center>
<h2>Enter Earnings of Employee:</h2>
<table>
<tr><td>Basic : </td><td><input type="text" name="e1"></td><tr>
<tr><td>DA : </td><td><input type="text" name="e2"></td></tr>
<tr><td>HRA : </td><td><input type="text" name="e3"></td></tr>
<tr><td></td><td><input type="submit" value=Next></td></tr>
</table>
</center>
</form>
</body>
</html>

PHP file : slip18_2_2.php

<?php
session_start();
$e1 = $_POST['e1'];
$e2 = $_POST['e2'];
$e3= $_POST['e3'];
echo "<h3>Employee Details</h3> ";
echo "Name : ".$_SESSION['eno']."<br>";
echo "Address : ".$_SESSION['enm']."<br>";
echo "Class : ".$_SESSION['eadd']."<br><br>";

echo "basic : ".$e1."<br>";


echo "DA : ".$e2."<br>";
echo "HRA : ".$e3."<br>";

$total = $e1+$e2+$e3;
echo "<h2>Total Of Earnings Is : ".$total."</h2>";
?>

Q. 2)Build a simple linear regression model for Fish Species Weight Prediction.

Ans:-

import numpy as np
import [Link] as plt
import pandas as pd
df = pd.read_csv("/root/sampada_vaibhavi/Data Anlytics/dataset/[Link]")
df

print([Link])
print([Link]().sum())

new_df = df[['Height','Weight']]
new_df.sample(10)
X = [Link](new_df[['Height']])
Y = [Link](new_df[['Weight']])
print([Link])
print([Link])

[Link](X,Y,color="green")
[Link]('Height vs Weight')
[Link]('Height')
[Link]('Weight')
[Link]()

from sklearn.model_selection import train_test_split


X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.25,random_state=15)
X_train
X_test

from sklearn.model_selection import train_test_split


X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.25,random_state=15)
Y_train
Y_test

from sklearn.linear_model import LinearRegression


regressor = LinearRegression()
[Link](X_train,Y_train)

[Link](X_test,Y_test,color="red")
[Link](X_train,[Link](X_train),color="cyan",linewidth=3)
[Link]('Regression(Test Set)')
[Link]('Height')
[Link]('Weight')
[Link]()

[Link](X_train,Y_train,color="blue")
[Link](X_train,[Link](X_train),color="red",linewidth=3)
[Link]('Regression(training Set)')
[Link]('Height')
[Link]('Weight')
[Link]()

from [Link] import r2_score,mean_squared_error


Y_pred = [Link](X_test)
print('R2 score: %.2f' % r2_score(Y_test,Y_pred))
print('Mean Error :',mean_squared_error(Y_test,Y_pred))

SLIP 5
Q. 1) Create XML file named “[Link]”with item-name, item-rate, item quantity Store the
details of 5 Items of different Types
Ans:-

<?xml version="1.0" encoding="UTF-8"?>


<?xml-stylesheet type= "text/css" href="[Link]"?>

<ItemDetails>
<Item>
<ItemName>php</ItemName>
<ItemPrice>100</ItemPrice>
<Quantity>10</Quantity>
</Item>
<Item>
<ItemName>java</ItemName>
<ItemPrice>200</ItemPrice>
<Quantity>11</Quantity>
</Item>
<Item>
<ItemName>python</ItemName>
<ItemPrice>300</ItemPrice>
<Quantity>12</Quantity>
</Item>
<Item>
<ItemName>software tool</ItemName>
<ItemPrice>400</ItemPrice>
<Quantity>13</Quantity>
</Item>
<Item>
<ItemName>software tool</ItemName>
<ItemPrice>400</ItemPrice>
<Quantity>13</Quantity>

</Item>
</ItemDetails>

Q. 2)Use the iris dataset. Write a Python program to view some


basic statistical details like percentile,
mean, std etc. of the species of 'Iris-setosa', 'Iris-versicolor' and 'Iris-virginica'. Apply logistic
regression
on the dataset to identify different species (setosa, versicolor, verginica) of Iris flowers given
just 4
features: sepal and petal lengths and widths.. Find the accuracy of the model.

Ans:-

import numpy as np
import [Link] as plt
import pandas as pd
df = pd.read_csv("/root/sampada_vaibhavi/Data Anlytics/dataset/[Link]")
df

x= [Link][:, [2,3]].values
y= [Link][:, 4].values
x

x= [Link][:, [2,3]].values
y= [Link][:, 4].values
y

from sklearn.model_selection import train_test_split


x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.25, random_state=0)
x_train
x_test

from sklearn.model_selection import train_test_split


x_train, x_test, y_train, y_test= train_test_split(x, y, test_size= 0.25, random_state=0)
y_train
y_test

from sklearn.linear_model import LogisticRegression


logistic_regression=LogisticRegression()
logistic_regression.fit(x_train,y_train)
y_pred=logistic_regression.predict(x_test)

from sklearn import metrics


import seaborn as sn
import [Link] as plt
confusion_matrix=[Link](y_test,y_pred,rownames=['Actual'],colnames=['Predicted'])
[Link](confusion_matrix,annot=True)
print('Accuracy:',metrics.accuracy_score(y_test,y_pred))
[Link]

print(x_test)
print(y_pred)

SLIP 6
Q. 1) Write PHP script to read “[Link]” file into simpleXML object. Display
attributes and elements .( simple_xml_load_file() function )
Ans:-

[Link]
<?xml version="1.0" encoding="utf-8"?>
<ABCBOOK>
<Technical>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Technical>
<Cooking>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Cooking>
<Yoga>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Yoga>
</ABCBOOK>

[Link]

<?php
$xml=simplexml_load_file("[Link]") or die("cannnot load");
$xmlstring=$xml->asXML();
echo $xmlstring;
?>

Q. 2)Create the following dataset in python & Convert the categorical values
into numeric [Link] the apriori algorithm on the above dataset to
generate the frequent itemsets and association rules. Repeat the process
with different min_sup values.

TID Item
1 Bread,Milk
2 Bread,Diaper,Beer,Eggs
3 Milk,Diaper,Beer,Coke
4 Bread,Milk,Diaper,Beer
5 Bread,Milk,Diaper,Coke

ans:

import pandas as pd
from mlxtend.frequent_patterns import apriori,association_rules
transactions = [['Bread','Milk'],['Bread','Diaper','Beer','Eggs'],
['Milk','Diaper','Beer','Coke'],
['Bread','Milk','Diaper','Beer'],['Bread','Milk','Diaper','Coke ']]

from [Link] import TransactionEncoder


te = TransactionEncoder()
te_array=[Link](transactions).transform(transactions)
df = [Link](te_array,columns=te.columns_)
df

freq_items = apriori(df,min_support=0.5,use_colnames=True)
print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0)
rules=rules.sort_values(['support','confidence'], ascending=[False,False])
print(rules)

slip 7
Q. 1) Write a PHP script to read “[Link]” file and print all MovieTitle and
ActorName of file using DOMDocument Parser. “[Link]” file should
contain following information with at least 5 records with values.
MovieInfoMovieNo, MovieTitle, ActorName ,ReleaseYear
Ans:-
[Link]

<?xml version="1.0" encoding="UTF-8"?>


<moviedtails>
<movie>
<movno>1</movno>
<movname>Sagar</movname>
<movactor>salman</movactor>
<movyear>2002</movyear>
</movie>
<movie>
<movno>2</movno>
<movname>radhe</movname>
<movactor>salman</movactor>
<movyear>2022</movyear>
</movie>
<movie>
<movno>3</moveno>
<movname>kgf</movname>
<movactor>yash</movactor>
<movyear>2022</movyear>
</movie>

[Link]

<?php
$xml=simplexml_load_file("[Link]");
foreach($xml->movie as $mov)
{
echo "movie no=$mov->movno"."<br>";
echo "movie name=$mov->movname"."<br>";
echo "movie actor=$mov->actor"."<br>";
echo "movie year=$mov->movyear"."<br>";
}
?>
Q. 2)Download the Market basket dataset. Write a python program to read
the dataset and display its information. Preprocess the data (drop null values
etc.) Convert the categorical values into numeric format. Apply the apriori
algorithm on the above dataset to generate the frequent itemsets and
association rules.
Ans:

import numpy as np
import [Link] as plt
import pandas as pd

df = pd.read_csv(' [Link]')
df

[Link]()
[Link]()
import numpy as np
import [Link] as plt
import pandas as pd

df = pd.read_csv('/root/sampada_vaibhavi/Data Anlytics/dataset/groceries -
[Link]')
df

[Link]()
[Link]()

from [Link] import TransactionEncoder


te = TransactionEncoder()
te_array=[Link](df).transform(df)
df = [Link](te_array,columns=te.columns_)
df

from mlxtend.frequent_patterns import apriori,association_rules


freq_items=apriori(df,min_support=0.0001,use_colnames=True)
print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0005)
rules=rules.sort_values(['support','confidence'],ascending=[False,False])
print(rules)

slip 8
Q. 1) Write a JavaScript to display message ‘Exams are near, have you started preparing for?’
(usealert box ) and Accept any two numbers from user and display addition of two number .(Use
Prompt and confirm box)

Ans:-

[Link]

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset=utf-8>

<title>Javascript alert box example-1</title>

</head>

<body>

<h1 style="color: red">JavaScript alert() box example</h1>

<hr />
<script type="text/javascript">

alert("This is a alert box");

</script>

</body>

</html>

[Link]

<!doctype html>

<html>

<head>

<title>Adding two numbers using JavaScript in HTML</title>

<script>

var num1 = 10;

var num2 = 40;

var sum = num1+num2;

[Link]("Sum of two numbers is " + sum);

</script>

</head>

<body></body>

</html>

Q. 2) Download the groceries dataset. Write a python program to read the dataset and display its

information. Preprocess the data (drop null values etc.) Convert the categorical values into numeric

format. Apply the apriori algorithm on the above dataset to generate the frequent itemsets and
association rules.

Ans:

import numpy as np

import [Link] as plt

import pandas as pd
df = pd.read_csv(' [Link]')

df

[Link]()

[Link]()

import numpy as np

import [Link] as plt

import pandas as pd

df = pd.read_csv('/root/sampada_vaibhavi/Data Anlytics/dataset/groceries - [Link]')

df

[Link]()

[Link]()

from [Link] import TransactionEncoder

te = TransactionEncoder()

te_array=[Link](df).transform(df)

df = [Link](te_array,columns=te.columns_)

df

from mlxtend.frequent_patterns import apriori,association_rules

freq_items=apriori(df,min_support=0.0001,use_colnames=True)

print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0005)

rules=rules.sort_values(['support','confidence'],ascending=[False,False])

print(rules)
slip 9
slip 10
Q. 1) Create a HTML fileto insert text before and after a Paragraph using jQuery.

[Hint : Use before( ) and after( )]

Ans:-

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Inserting HTML Contents At the End of the Elements in jQuery</title>

<script src="[Link]

<script>

$(document).ready(function(){

// Append all paragraphs on document ready

$("p").append(' <a href="#">read more...</a>');

// Append a div container on button click

$("button").click(function(){

$("#container").append("This is demo text.");

});

});

</script>

</head>

<body>
<button type="button">Insert Text</button>

<div id="container">

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu sem tempor, varius quam at,
luctus dui. Mauris magna metus, dapibus nec turpis vel, semper malesuada ante.</p>

<p>Quis quam ut magna consequat faucibus. Pellentesque eget nisi a mi suscipit tincidunt. Ut
tempus dictum risus. Pellentesque viverra sagittis quam at mattis. Suspendisse potenti.</p>

</div>

</body>

</html>

Q. 2)Create the following dataset in python & Convert the categorical values into numeric
[Link] the apriori algorithm on the above dataset to generate the frequent itemsets
and association rules. Repeat the process with different min_sup values.
TID Items
1 'eggs', 'milk','bread'
2 'eggs', 'apple'
3 'milk', 'bread'
4 'apple', 'milk'
5 'milk', 'apple', 'bread'
Ans:
import pandas as pd
from mlxtend.frequent_patterns import apriori,association_rules

transactions = [['Bread','Milk'],['Bread','Diaper','Beer','Eggs'],
['Milk','Diaper','Beer','Coke'],
['Bread','Milk','Diaper','Beer'],
[ 'Bread','Milk','Diaper','Coke ']]
from [Link] import TransactionEncoder
te = TransactionEncoder()
te_array=[Link](transactions).transform(transactions)
df = [Link](te_array,columns=te.columns_)
df

freq_items = apriori(df,min_support=0.5,use_colnames=True)
print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0)rules=rules.sort_val
ues(['support','confidence'],ascending[False,False])
print(rules)

slip 11
Q. 1) Write a Javascript program to accept name of student, change font color to red, font
size to 18 if student name is present otherwise on clicking on empty text box display image
which changes its size (Use onblur, onload, onmousehover, onmouseclick, onmouseup)
Ans:-
<html>
<head>
<!--Function to do the background color-->
<script language="JavaScript">
var backColor = new Array(); // don't change this
backColor[0] = 'red';
backColor[1] = '#00FF00';
backColor[2] = '#0000FF';
backColor[3] = '#FFFFFF';
function changeBG(whichColor){
[Link] = backColor[whichColor];
}
</script>
<!--Function to do the font color-->

<script language="JavaScript">
var fontColor = new Array(); // don't change this
fontColor[0] = 'red';
fontColor[1] = '#00FF00';
fontColor[2] = '#0000FF';
fontColor[3] = '#FFFFFF';
function changefont(whichColor){
[Link] = fontColor[whichColor];
}
</script>

<!--Function to do the font type-->

<script language="JavaScript">
var fontType = new Array(); // don't change this
fontType[0] = 'Arial';
fontType[1] = 'Verdana';
fontType[2] = 'Tahoma';
function changetype(whichType){
[Link] = fontType[whichColor];
}
</script>

<!--Function to do the font size-->

<script language="JavaScript">
var fontSize = new Array(); // don't change this
fontSize[0] = '12';
fontSize[1] = '14';
fontSize[2] = '16';
fontSize[3] = '18';
function changesize(whichSize){
[Link] = fontSize[whichSize];
}
</script>
</head>

<body>
<form>
<center>

<!--<option value ="">Backgroun Color</option>-->

<select OnClick="[Link]=[Link][[Link]].value">
<option value = "javascript:changeBG(0);">Red
<option value = "javascript:changeBG(1);">Green
<option value = "javascript:changeBG(2);">Blue
<option value = "javascript:changeBG(3);"> White
</select>

<!--<option value ="">Font Color</option>-->

<select OnClick="[Link]=[Link][[Link]].value">
<option value = "javascript:changefont(0);">Red Font
<option value = "javascript:changefont(1);">Green Font
<option value = "javascript:changefont(2);">Blue Font
<option value = "javascript:changefont(3);">White Font
</select>

<!--<option value ="">Font Size</option>-->

<select OnClick="[Link]=[Link][[Link]].value">
<option value = "javascript:changetype(0);">Arial
<option value = "javascript:changetype(1);">Verdana
<option value = "javascript:changetype(2);">Tahoma
</select>

<!--<option value ="">Font Type</option>-->

<select OnClick="[Link]=[Link][[Link]].value">
<option value = "javascript:changesize(0);">12
<option value = "javascript:changesize(1);">14
<option value = "javascript:changesize(2);">16
<option value = "javascript:changesize(3);">18
</select>

</br>
BLA BLA BLA test font

<input type=button value="Go!" onClick="javascript:changeBG(this)">

</form>
</body>
</html>
Q. 2)Create the following dataset in python & Convert the categorical values into numeric
[Link] the apriori algorithm on the above dataset to generate the frequent itemsets
and associationrules. Repeat the process with different min_sup values.
TID Items
1 butter, bread, milk
2 butter, flour, milk, sugar
3 butter, eggs, milk, salt
4 eggs
5 butter, flour, milk, salt

import pandas as pd
from mlxtend.frequent_patterns import apriori,association_rules

transactions = [['Bread','Milk'],['Bread','Diaper','Beer','Eggs'],
['Milk','Diaper','Beer','Coke'],
['Bread','Milk','Diaper','Beer'],[
'Bread','Milk','Diaper','Coke ']]
from [Link] import TransactionEncoder
te = TransactionEncoder()
te_array=[Link](transactions).transform(transactions)
df = [Link](te_array,columns=te.columns_)
df

freq_items = apriori(df,min_support=0.5,use_colnames=True)
print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0)rules=rules.sort_val
ues(['support','confidence'],ascending[False,False])
print(rules)
slip 12
slip 13
slip 14
slip 15
Q. 1) Write Ajax program to fetch suggestions when is user is typing in a textbox. (eg like
google suggestions. Hint create array of suggestions and matching string will be displayed)
Ans:-

[Link]

<html>
<head>
<script>
function showHint(str)
{
if ([Link] == 0)
{
[Link]("txtHint").innerHTML = "";
return;
}
else
{
var xmlhttp = new XMLHttpRequest();
[Link] = function()
{
if ([Link] == 4 && [Link] == 200)
{
[Link]("txtHint").innerHTML = [Link];
[Link]("txtHint1").innerHTML = [Link];
}
};
[Link]("GET", "[Link]?q=" + str, true);
[Link]();
}
}
</script>
</head>
<body>
<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint([Link])">
</form>
<p>Name: <span id="txtHint"></span></p>
</body>
</html>

[Link]

<?php
$q = $_REQUEST["q"];
$hint = "";
if ($q !== "")
{
$hint = $q;
}
echo $hint ;
?>

Q. 2)Create the following dataset in python & Convert the categorical values
into numeric [Link] the apriori algorithm on the above dataset to
generate the frequent itemsets and association rules. Repeat the process
with different min_sup values.

company model year


0 tata nexon 2017
1 mg astor 2021
2 kia seltos 2019
3 hyundai creata 2015

-->

import pandas as pd
from mlxtend.frequent_patterns import apriori,association_rules

transactions = [['Bread','Milk'],['Bread','Diaper','Beer','Eggs'],
['Milk','Diaper','Beer','Coke'],
['Bread','Milk','Diaper','Beer'],
[ 'Bread','Milk','Diaper','Coke ']]
from [Link] import TransactionEncoder
te = TransactionEncoder()
te_array=[Link](transactions).transform(transactions)
df = [Link](te_array,columns=te.columns_)
df

freq_items = apriori(df,min_support=0.5,use_colnames=True)
print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0)rules=
rules.sort_values(['support','confidence'],ascending[False,False])
print(rules)

slip 16
Q. 1) Write Ajax program to get book details from XML file when user select a
book name. Create XML file for storing details of book(title, author, year,
price).
Ans:-

[Link]

<html>
<body>
<script type="text/javascript">
function show_confirm()
{
var r=confirm("Press a button !");
if(r==true)
{
ver i;
var mybooks = new Array();
mybooks[0]="Mysql";
mybooks[1]="PHP";
mybooks[2]="Java";
for(i=0;i {
[Link](mybookks[i]+"
");
}
}
else
{
alert("Cancel books cannot br displayed !");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_confirm()" value="List of Books"/>
</body>
</html>

[Link]

<?xml version='1.0' encoding='utf-8'?>


//use to double qoute for display version "1.0" and "utf-8".don't use singlr
qoute.
<ABCBOOLK>
<Book>
<Book_Title>Networking</Book_Title>
<Book_Author>400</Book_Author>
<Book_PubYear>2015</Book_PubYear>
<Book_Price>450</Book_Price>
</Book>
<Book>
<Book_Title>php </Book_Title>
<Book_Author>400</Book_Author>
<Book_PubYear>2015</Book_PubYear>
<Book_Price>450</Book_Price>
</Book>
<Book>
<Book_Title>java</Book_Title>
<Book_Author>400</Book_Author>
<Book_PubYear>2015</Book_PubYear>
<Book_Price>450</Book_Price>
</Book>
</ABCBOOLK>
Q. 2)Consider any text paragraph. Preprocess the text to remove any special
characters and digits. Generate the summary using extractive summarization
process
-->
pip install nltk
pip install wordcloud
formatted_article_text = [Link]('[^a-zA-Z]', ' ', article_text )
formatted_article_text = [Link](r'\s+', ' ', formatted_article_text)
import bs4 as bs
import [Link]
import re
scraped_data =
[Link]('[Link]
article = scraped_data.read()
parsed_article = [Link](article,'lxml')
paragraphs = parsed_article.find_all('p')
article_text = ""
for p in paragraphs:
article_text += [Link]
article_text
formatted_article_text = [Link]('[^a-zA-Z]', ' ', article_text )
formatted_article_text = [Link](r'\s+', ' ', formatted_article_text)
formatted_article_text
import bs4 as bs
import [Link]
import re
article_text="Arti!fi!ci!al intelligence (AI) is 1intelligence
demonstr@ated by machi!nes,.... as opposed to the natural intelligence
displayed by animals including humans."
article_text
formatted_article_text = [Link]('[^a-zA-Z]', ' ', article_text )
formatted_article_text = [Link](r'\s+', ' ', formatted_article_text)
formatted_article_text

slip 17
Q. 1) Write a Java Script Program to show Hello Good Morning message
onload event using alert box and display the Student registration from.
Ans:-
<!DOCTYPE html>
<html>
<body>
<head>
<title>Show good morning good night wish as per time Javascript</title>
</head>
<script type="text/javascript">
[Link]("<center><font size=+3 style='color: green;'>");
var day = new Date();
var hr = [Link]();
if (hr >= 0 && hr < 12) {
[Link]("Good Morning!");
} else if (hr == 12) {
[Link]("Good Noon!");
} else if (hr >= 12 && hr <= 17) {
[Link]("Good Afternoon!");
} else {
[Link]("Good Evening!");
}
[Link]("</font></center>");
</script>
</html>
</body>
</html>
REGISTRATION FORM

<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<title>JavaScript Form Validation using a sample registration form</title>
<meta name="keywords" content="example, JavaScript Form Validation,
Sample registration form" />
<meta name="description" content="This document is an example of
JavaScript Form Validation using a sample registration form. " />
<link rel='stylesheet' href='[Link]' type='text/css' />
<script src="[Link]"></script>
</head>
<body onload="[Link]();">
<h1>Registration Form</h1>
Use tab keys to move from one input field to the next.
<form name='registration' onSubmit="return formValidation();">
<ul>
<li><label for="userid">User id:</label></li>
<li><input type="text" name="userid" size="12" /></li>
<li><label for="passid">Password:</label></li>
<li><input type="password" name="passid" size="12" /></li>
<li><label for="username">Name:</label></li>
<li><input type="text" name="username" size="50" /></li>
<li><label for="address">Address:</label></li>
<li><input type="text" name="address" size="50" /></li>
<li><label for="country">Country:</label></li>
<li><select name="country">
<option selected="" value="Default">(Please select a country)</option>
<option value="AF">Australia</option>
<option value="AL">Canada</option>
<option value="DZ">India</option>
<option value="AS">Russia</option>
<option value="AD">USA</option>
</select></li>
<li><label for="zip">ZIP Code:</label></li>
<li><input type="text" name="zip" /></li>
<li><label for="email">Email:</label></li>
<li><input type="text" name="email" size="50" /></li>
<li><label id="gender">Sex:</label></li>
<li><input type="radio" name="msex" value="Male"
/><span>Male</span></li>
<li><input type="radio" name="fsex" value="Female"
/><span>Female</span></li>
<li><label>Language:</label></li>
<li><input type="checkbox" name="en" value="en" checked
/><span>English</span></li>
<li><input type="checkbox" name="nonen" value="noen" /><span>Non
English</span></li>
<li><label for="desc">About:</label></li>
<li><textarea name="desc" id="desc"></textarea></li>
<li><input type="submit" name="submit" value="Submit" /></li>
</ul>
</form>
</body>
</html>

[Link]

h1 {
margin-left: 70px;
}
form li {
list-style: none;
margin-bottom: 5px;
}

form ul li label{
float: left;
clear: left;
width: 100px;
text-align: right;
margin-right: 10px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:14px;
}

form ul li input, select, span {


float: left;
margin-bottom: 10px;
}

form textarea {
float: left;
width: 350px;
height: 150px;
}

[type="submit"] {
clear: left;
margin: 20px 0 0 230px;
font-size:18px
}

p{
margin-left: 70px;
font-weight: bold;
}

[Link]

function formValidation()
{
var uid = [Link];
var passid = [Link];
var uname = [Link];
var uadd = [Link];
var ucountry = [Link];
var uzip = [Link];
var uemail = [Link];
var umsex = [Link];
var ufsex = [Link]; if(userid_validation(uid,5,12))
{
if(passid_validation(passid,7,12))
{
if(allLetter(uname))
{
if(alphanumeric(uadd))
{
if(countryselect(ucountry))
{
if(allnumeric(uzip))
{
if(ValidateEmail(uemail))
{
if(validsex(umsex,ufsex))
{
}
}
}
}
}
}
}
}
return false;
}

userid_validation.JS

function userid_validation(uid,mx,my)
{
var uid_len = [Link];
if (uid_len == 0 || uid_len >= my || uid_len < mx)
{
alert("User Id should not be empty / length be between "+mx+" to "+my);
[Link]();
return false;
}
return true;
}

Q. 2)Consider text [Link], keep working. Keep striving. Never give up.
Fall down seven times, get up eight. Ease is a greater threat to progress than
hardship. Ease is a greater threat to progress than hardship. So, keep moving,
keep growing, keep learning. See you at [Link] the text to remove
any special characters and digits. Generate the summary using extractive
summarization process.
-->
pip install nltk
import nltk
[Link]('punkt')
from [Link] import sent_tokenize
from [Link] import word_tokenize
paragraph_text = """Hello all,Welcome to python programming
[Link]
programming academy is a nice platform to learn new programming [Link]
is difficult to get enrolled in thin academy."""
tokenized_text_data = sent_tokenize(paragraph_text)
tokenized_words = word_tokenize(paragraph_text)
print("Tokenized sentences : \n",tokenized_text_data,"\n")
print("Tokenized words : \n",tokenized_words,"\n")
[Link]('stopwords')
from [Link] import stopwords
stop_words_data = set([Link]("english"))
print(stop_words_data)
from [Link] import word_tokenize
from [Link] import FreqDist
tokenized_words = word_tokenize(paragraph_text)
frequency_distribution = FreqDist(tokenized_words)
print(frequency_distribution)
print(frequency_distribution.most_common(2))
import [Link] as plt
frequency_distribution.plot(32,cumulative = False)
[Link]()
slip 18
Q. 1) Write a Java Script Program to print Fibonacci numbers on onclick event.
Ans:-

<html>
<head><title>fabonnic series</title>
<script>
function fab(){
var A = 0;
var B = 1;
var C;

var N = [Link]("number").value;

[Link](A+"<br />");
[Link](B+"<br />");

for(var i=3; i <= N;i++)


{
C = A + B;
A = B;
B = C;

[Link](C+"<br />");
}
}
</script>
</head>
<body>
<h2>
Please input any Number<input id="number" value="15">
<button type="button" onclick="fab()">fab</button>
</h2>
</body>
</html>

Q. 2)Consider any text paragraph. Remove the stopwords. Tokenize the


paragraph to extract words and sentences. Calculate the word frequency
distribution and plot the frequencies. Plot the wordcloud of the text.
-->
pip install nltk
import nltk
[Link]('punkt')
from [Link] import sent_tokenize
from [Link] import word_tokenize
paragraph_text = """Hello all,Welcome to python programming
[Link]
programming academy is a nice platform to learn new programming [Link]
is difficult to get enrolled in thin academy."""
tokenized_text_data = sent_tokenize(paragraph_text)
tokenized_words = word_tokenize(paragraph_text)
print("Tokenized sentences : \n",tokenized_text_data,"\n")
print("Tokenized words : \n",tokenized_words,"\n")
[Link]('stopwords')
from [Link] import stopwords
stop_words_data = set([Link]("english"))
print(stop_words_data)
from [Link] import word_tokenize
from [Link] import FreqDist
tokenized_words = word_tokenize(paragraph_text)
frequency_distribution = FreqDist(tokenized_words)
print(frequency_distribution)
print(frequency_distribution.most_common(2))
import [Link] as plt
frequency_distribution.plot(32,cumulative = False)
[Link]()

slip 19
Q. 1) create a [Link] file containing at least 5 student information
Ans:-

<?xml-stylesheet type="text/css" href="[Link]" ?>


<!DOCTYPE HTML>
<html>
<head>
<h1>
STUDENTS DESCRIPTION </h1>
</head>
<students>
<student>
<usn>USN : 1CG15CS001</USN>
<name>NAME : SANTHOS</name>
<college>COLLEGE : CIT</college>
<branch>BRANCH : Computer Science and Engineering</branch>
<year>YEAR : 2015</year>
<e-mail>E-Mail : santosh@[Link]</e-mail>
</student>
<student>
<usn>USN : 1CG15IS002</USN>
<name>NAME : MANORANJAN</name>
<college>COLLEGE : CITIT</college>
<branch>BRANCH : Information Science and Engineering</branch>
<year>YEAR : 2015</year>
<e-mail>E-Mail : manoranjan@[Link]</e-mail>
</student>
<student>
<usn>USN : 1CG15EC101</USN>
<name>NAME : CHETHAN</name>
<college>COLLEGE : CITIT</college>
<branch>BRANCH : Electronics and Communication Engineering
</branch>
<year>YEAR : 2015</year>
<e-mail>E-Mail : chethan@[Link]</e-mail>
</student>
</students>
</html>

[Link]

student{
display:block; margin-top:10px; color:Navy;
}
USN{
display:block; margin-left:10px;font-size:14pt; color:Red;
}
name{display:block; margin-left:20px;font-size:14pt; color:Blue;
}
college{
display:block; margin-left:20px;font-size:12pt; color:Maroon;
}
branch{
display:block; margin-left:20px;font-size:12pt; color:Purple;
}
year{
display:block; margin-left:20px;font-size:14pt; color:Green;
}
e-mail{
display:block; margin-left:20px;font-size:12pt; color:Blue;
}
Q. 2)Consider text paragraph."""Hello all, Welcome to Python Programming
Academy. Python Programming Academy is a nice platform to learn new
programming skills. It is difficult to get enrolled in this Academy."""Remove
the stopwords.
-->

pip install nltk


import nltk
[Link]('punkt')
from [Link] import sent_tokenize
from [Link] import word_tokenize
paragraph_text = """Hello all,Welcome to python programming
[Link]
programming academy is a nice platform to learn new programming [Link]
is difficult to get enrolled in thin academy."""
tokenized_text_data = sent_tokenize(paragraph_text)
tokenized_words = word_tokenize(paragraph_text)
print("Tokenized sentences : \n",tokenized_text_data,"\n")
print("Tokenized words : \n",tokenized_words,"\n")
[Link]('stopwords')
from [Link] import stopwords
stop_words_data = set([Link]("english"))
print(stop_words_data)
from [Link] import word_tokenize
from [Link] import FreqDist
tokenized_words = word_tokenize(paragraph_text)
frequency_distribution = FreqDist(tokenized_words)
print(frequency_distribution)
print(frequency_distribution.most_common(2))
import [Link] as plt
frequency_distribution.plot(32,cumulative = False)
[Link]()

slip 20
Q. 1) create a [Link] file containing at least 5 student information
Ans:-

<?xml-stylesheet type="text/css" href="[Link]" ?>


<!DOCTYPE HTML>
<html>
<head>
<h1>
STUDENTS DESCRIPTION </h1>
</head>
<students>
<student>
<usn>USN : 1CG15CS001</USN>
<name>NAME : SANTHOS</name>
<college>COLLEGE : CIT</college>
<branch>BRANCH : Computer Science and Engineering</branch>
<year>YEAR : 2015</year>
<e-mail>E-Mail : santosh@[Link]</e-mail>
</student>
<student>
<usn>USN : 1CG15IS002</USN>
<name>NAME : MANORANJAN</name>
<college>COLLEGE : CITIT</college>
<branch>BRANCH : Information Science and Engineering</branch>
<year>YEAR : 2015</year>
<e-mail>E-Mail : manoranjan@[Link]</e-mail>
</student>
<student>
<usn>USN : 1CG15EC101</USN>
<name>NAME : CHETHAN</name>
<college>COLLEGE : CITIT</college>
<branch>BRANCH : Electronics and Communication Engineering
</branch>
<year>YEAR : 2015</year>
<e-mail>E-Mail : chethan@[Link]</e-mail>
</student>
</students>
</html>

[Link]
student{
display:block; margin-top:10px; color:Navy;
}
USN{
display:block; margin-left:10px;font-size:14pt; color:Red;
}
name{display:block; margin-left:20px;font-size:14pt; color:Blue;
}
college{
display:block; margin-left:20px;font-size:12pt; color:Maroon;
}
branch{
display:block; margin-left:20px;font-size:12pt; color:Purple;
}
year{
display:block; margin-left:20px;font-size:14pt; color:Green;
}
e-mail{
display:block; margin-left:20px;font-size:12pt; color:Blue;
}

Q. 2)Consider text paragraph."""Hello all, Welcome to Python Programming


Academy. Python Programming Academy is a nice platform to learn new
programming skills. It is difficult to get enrolled in this Academy."""Remove
the stopwords.

-->

pip install nltk


import nltk
[Link]('punkt')
from [Link] import sent_tokenize
from [Link] import word_tokenize
paragraph_text = """Hello all,Welcome to python programming
[Link]
programming academy is a nice platform to learn new programming [Link]
is difficult to get enrolled in thin academy."""
tokenized_text_data = sent_tokenize(paragraph_text)
tokenized_words = word_tokenize(paragraph_text)
print("Tokenized sentences : \n",tokenized_text_data,"\n")
print("Tokenized words : \n",tokenized_words,"\n")
[Link]('stopwords')
from [Link] import stopwords
stop_words_data = set([Link]("english"))
print(stop_words_data)
from [Link] import word_tokenize
from [Link] import FreqDist
tokenized_words = word_tokenize(paragraph_text)
frequency_distribution = FreqDist(tokenized_words)
print(frequency_distribution)
print(frequency_distribution.most_common(2))
import [Link] as plt
frequency_distribution.plot(32,cumulative = False)
[Link]()

slip 21
Q. 1)Add a JavaScript File in Codeigniter. The Javascript code should check
whether a number is positive or negative.
Ans:-
<!DOCTYPE html>
<html>
<head>
<style> * {font-family: Calibri;}
</style>
</head>
<body>
<h2>Checking if a given number is positive or negative using JavaScript
Comparative Operator.</h2>
<p>
<a
href='[Link]
son_operator' target='_blank'>Learn more about Comparison Operators.</a>
</p>
</body>

<script>
const number = 12;

if (number < 0)
[Link] (number + ' is negative');
else
[Link] (number + ' is positive');
</script>
</html>
Q. 2)Build a simple linear regression model for User Data.
-->
import numpy as np
import [Link] as plt
import pandas as pd
df = pd.read_csv("/root/sampada_vaibhavi/Data Anlytics/dataset/[Link]")
df
print([Link])
print([Link]().sum())
new_df = df[['Height','Weight']]
new_df.sample(10)
X = [Link](new_df[['Height']])
Y = [Link](new_df[['Weight']])
print([Link])
print([Link])
[Link](X,Y,color="green")
[Link]('Height vs Weight')
[Link]('Height')
[Link]('Weight')
[Link]()
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size =
0.25,random_state=15)
X_train
X_test
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size =
0.25,random_state=15)
Y_train
Y_test
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
[Link](X_train,Y_train)
[Link](X_test,Y_test,color="red")
[Link](X_train,[Link](X_train),color="cyan",linewidth=3)
[Link]('Regression(Test Set)')
[Link]('Height')
[Link]('Weight')
[Link]()
[Link](X_train,Y_train,color="blue")
[Link](X_train,[Link](X_train),color="red",linewidth=3)
[Link]('Regression(training Set)')
[Link]('Height')
[Link]('Weight')
[Link]()
from [Link] import r2_score,mean_squared_error
Y_pred = [Link](X_test)
print('R2 score: %.2f' % r2_score(Y_test,Y_pred))
print('Mean Error :',mean_squared_error(Y_test,Y_pred))
slip 22
slip 23
slip 24
slip 25
slip 26
slip 27
slip 28
slip 29
Q. 1) Write a PHP script for the following: Design a form to accept a number
from the user. Perform the operations and show the results.
1) Fibonacci Series.
2) To find sum of the digits of that number.
(Use the concept of self processing page.)
Ans:-

<html>
<body bgcolor = "navyblue">
<form action = "<?php echo $_SERVER['PHP_SELF'] ?>" method = "POST">
Enter the first number:
<input type = "text" name = "n1" id = "n1"> <BR>
<input type = "submit" value = "submit">
</form>
<?php
$num = $_POST['n1'];
$n1 = 0;
$n2 = 1;
echo "<BR> Fibonacci series are:<BR>";
echo "<BR> $n1";
echo "<BR> $n2";
for($i = 1; $i<=$num-2; $i++)
{
$n3 = $n1 + $n2;
echo "<BR> $n3";
$n1 = $n2;
$n2 = $n3;
}
$temp = $num;
$sum=0;
while($temp!=0)
{
$sum += $temp % 10;
$temp = $temp / 10;
}
echo "<BR>sum of digits of ".$num." is :".$sum;
?>
</body>
</html>
Q. 2 ) Build a logistic regression model for Student Score Dataset.
-->
import numpy as np
import [Link] as plt
import pandas as pd
df = pd.read_csv("/root/sampada_vaibhavi/Data Anlytics/dataset/[Link]")
df
print([Link])
print([Link]().sum())
new_df = df[['Height','Weight']]
new_df.sample(10)
X = [Link](new_df[['Height']])
Y = [Link](new_df[['Weight']])
print([Link])
print([Link])
[Link](X,Y,color="green")
[Link]('Height vs Weight')
[Link]('Height')
[Link]('Weight')
[Link]()
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size =
0.25,random_state=15)
X_train
X_test
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size =
0.25,random_state=15)
Y_train
Y_test
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
[Link](X_train,Y_train)
[Link](X_test,Y_test,color="red")
[Link](X_train,[Link](X_train),color="cyan",linewidth=3)
[Link]('Regression(Test Set)')
[Link]('Height')
[Link]('Weight')
[Link]()
[Link](X_train,Y_train,color="blue")
[Link](X_train,[Link](X_train),color="red",linewidth=3)
[Link]('Regression(training Set)')
[Link]('Height')
[Link]('Weight')
[Link]()
from [Link] import r2_score,mean_squared_error
Y_pred = [Link](X_test)
print('R2 score: %.2f' % r2_score(Y_test,Y_pred))
print('Mean Error :',mean_squared_error(Y_test,Y_pred))
slip 30
Q. 1) Create a XML file which gives details of books available in “Bookstore”
from following categories.
1) Yoga
2) Story
3) Technical
and elements in each category are in the following format
<Book>
<Book_Title> --------------</Book_Title>
<Book_Author> ---------------</Book_Author>
<Book_Price> --------------</Book_Price>
</Book>
Save the file as “[Link]”
Ans:-

[Link]

<?xml version="1.0" encoding="utf-8"?>


<ABCBOOK>
<Technical>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Technical>
<Cooking>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Cooking>
<Yoga>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Yoga>
</ABCBOOK>

[Link]

<?php
$xml=simplexml_load_file("[Link]") or die("cannnot load");
$xmlstring=$xml->asXML();
echo $xmlstring;
?>

Q. 2 ) Create the dataset . transactions = [['eggs', 'milk','bread'], ['eggs',


'apple'], ['milk', 'bread'], ['apple', 'milk'], ['milk', 'apple', 'bread']] .Convert the
categorical values into numeric [Link] the apriori algorithm on the
above dataset to generate the frequent itemsets and association rules.
Ans:

import pandas as pd
from mlxtend.frequent_patterns import apriori,association_rules

transactions = [['Bread','Milk'],['Bread','Diaper','Beer','Eggs'],
['Milk','Diaper','Beer','Coke'],
['Bread','Milk','Diaper','Beer'],[
'Bread','Milk','Diaper','Coke ']]
from [Link] import TransactionEncoder
te = TransactionEncoder()
te_array=[Link](transactions).transform(transactions)
df = [Link](te_array,columns=te.columns_)
df

freq_items = apriori(df,min_support=0.5,use_colnames=True)
print(freq_items)

rules=association_rules(freq_items,metric='support',min_threshold=0.0)rules=
rules.sort_values(['support','confidence'],ascending[False,False])
print(rules)

Common questions

Powered by AI

Tokenization divides text into sentences or words, simplifying analysis by allowing individual elements to be processed separately, and enabling easier manipulation and identification of key patterns in the data .

Challenges in converting XML data to relational databases include handling deep XML hierarchy mappings to tables, maintaining referential integrity, and dealing with non-tabular data such as attributes, which require complex transformations and storage decisions .

In linear regression model training, the training dataset is used to fit the model, while the test dataset is used to evaluate its performance. Training involves learning parameter values that minimize the error, and evaluation on test data checks the model's generalization ability by using metrics like R2 score and Mean Error .

The apriori algorithm is used in data analysis to identify frequent itemsets and deduce association rules, enabling the discovery of relationships between different items in transactional databases .

Using a random state ensures that train-test data splits are the same across different runs, which is critical for reproducibility and compares model performance fairly among different experiments .

Support represents how frequently itemsets appear in the dataset, while confidence indicates the likelihood of the consequent given the antecedent. High support and confidence values point to strong and meaningful rule patterns, helping filter out less significant relationships .

Preprocessing steps like removing stopwords, tokenization, and frequency distribution analysis refine the text by eliminating noise and focusing on significant terms, which enhances the efficiency and accuracy of extractive summarization methods .

The R2 score measures the proportion of variance in the dependent variable that is predictable from the independent variable(s). It serves as an indicator of the model's goodness of fit, with a score closer to 1 suggesting a better fit .

Ajax enhances user experience in web applications by allowing asynchronous data fetching, which leads to faster updates and less page reloading, thus providing a smoother and more dynamic interaction between users and servers .

Logistic regression efficiently classifies species by mapping physical characteristics to probabilities using a logistic function, allowing for clear decision boundaries between classes, such as species types, based on features like petal and sepal dimensions .

You might also like