You are on page 1of 67

University Institute of Engineering

Department of Computer Science & Engineering

Experiment 1.1:
Student Name: ROSHAN M ROY
UID:22BCS10095
Branch: Computer Science & Engineering Section/Group: 203(A)
Semester:1 Date of Performance:10/10/22
Subject Name: Disruptive technologies
Subject Code: 22ECH-102

2. Tool Used: Google Colaboratory

4. Code:
1. WAP to print your name two times:

#Assignment 1: WAP to print your name two times

print("Enter your name :\


n") name = input() for i in
range(2):
print(name)
2. WAP to add three numbers,inputs from user and print.

#Assignment 2: WAP to add three numbers, inputs from user and print result
print("Enter the first
number:") a = int(input())
print("Enter the second number:")
b = int(input())
print("Enter the Third number:")
c = int(input())
print("Sum of the numbers is "+str(a+b+c))

3. WAP to concrete three strings,input from the user and print.

#Assignment 3: WAP to concatenate three strings, inputs from user and print
University Institute of Engineering

Department of Computer Science & Engineering

print("Enter the first string:")

a = input()
print("Enter the second string:") b = input()
print("Enter the Third string:") c = input()
print(a+" "+b+" "+c)
4. WAP to find max among three numbers and input from user.

#Assignment 4: WAP to find max among three numbers and input from
user print("Enter the first number:") a = int(input())
print("Enter the second number:")
b = int(input())
print("Enter the Third
number:") c = int(input())
if(a>=b):
if(a>=c):
max = a
else: max
= c
else:
if(b>=c):
max = b
else:
max = c
print("Max of the numbers is "+ str(max))

5. WAP to print the table of n; where n will be given by the user

#Assignment 5: WAP to print the table of n; where n will be given by the


user print("Enter the number :") n = int(input())
print("The table of "+ str(n) + " :") for
i in range(1,11): print(str(n)+" *
"+str(i)+" = "+str(n*i))

6. WAP to print the table of 7, 9.

#Assignment 6: WAP to print the table of 7, 9.


print("The table of "+ str(7) + " & " +
str(9)) for i in range(1,11):
print(str(7)+" * "+str(i)+" = "+str(7*1) + " | " + str(9)+" * "+str(9)+" = "+str(9*i))

7. WAP to add all the numbers from 1 to n and n is given by user.

#Assignment 7: WAP to add all the numbers from 1 to n and n is given by user.
print("Enter the number :") n
University Institute of Engineering

Department of Computer Science & Engineering

= int(input())

sum = 0 for i in
range(n+1):
sum = sum + i
print("sum of the numbers is "
+ str(sum))
8. WAP using function that add all odd numbers from 1 to n; n given by user.

#Assignment 8: WAP using function that add all odd numbers from 1 to n; n given by user.

print("Enter the number :")


n = int(input()) #Defining
a function def oddSum():
sum = 0 for i in range(1
, n+1):
if(i%2!=0):
sum = sum + i
return sum

9. WAP using function that add all even numbers from 1 to n; n given by user.

#Assignment 9: WAP using function that add all even numbers from 1 to n; n given by
user.

print("Enter the
number :") n =
int(input()) #Defining a
function def evenSum():
sum = 0 for i in range(1
, n+1):
if(i%2==0):
sum = sum + i
return sum
print("sum of all the Even numbers are :")
print(evenSum())
10.WAP using function that adds all prime numbers from 1 to n; n given by user.
if (count == 0 and Num > 1):
sum = sum + i
return sum

print("Sum of all prime numbers are:") print(primeSum()) #Assignment 10: WAP using function that add all prime numbers from 1
to n; n given by user.

print("Enter the
University Institute of Engineering

Department of Computer Science & Engineering

number :")

Num = int(input())

#Declaring a function
def primeSum():

sum = 0
for i in range(2,Num+1):

count = 0 for j in range(2,

(i//2 + 1)):

if(i % j == 0):

count = count + 1
break

11.WAP to create 500 txt files in a directory. Every file contains 20,000 lines and every line contains random
string of length 20 characters.

#Assignment 11: WAP to create 500 txt files in a directory. Every file contains 20,000 lines and
e very line contains random string of length 20 characters.
import
string import
random
for i in range(1 , 500): with
open("random"+str(i)+".txt", 'a') as file1:
for j in range(20000):
# initializing size of string
N = 20
# using random.choices() #
generating random strings
res = ''.join(random.choices(string.ascii_uppercase +string.digits, k=N))
file1.write(res+"\n")
print("All the files are created !")
University Institute of Engineering

Department of Computer Science & Engineering

5. Output:

1:

2:

3.

5:

6
University Institute of Engineering

Department of Computer Science & Engineering

9.

10.
University Institute of Engineering

Department of Computer Science & Engineering

11.
University Institute of Engineering

Department of Computer Science & Engineering

Evaluation Grid (To be filled by Faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1. Student Performance (task 12
implementation and result evaluation)
2. Viva-Voce 10
3. Worksheet Submission (Record) 8
Signature of Faculty (with Date): Total Marks Obtained: 30
University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 1.2
Student Name:ROSHAN M ROY UID:22BCS10095

Branch: CSE Section/Group: 203(A)


Semester: 1ST Date of Performance:20/10/22
Subject Name: Disruptive Technology
Subject Code: 22ECH102

1. Aim of the practical: To explore, visualize, transform and summarize input datasets for
building classification/regression/prediction models.

2. Tool Used: Google Colaboratory

3. Basic Concept/ Command Description: The basic concept is to explore, visualize,


transform and summarize input datasets for building classification/regression/prediction
models.

4. Code:
To install the pycaret

! pip install pycaret &> /dev/null print("pycaret

installed successfully")
University Institute of Engineering

Department of Computer Science & Engineering


To get the version of installed pycaret

from pycaret .utils import version

version()

To import data from pycaret

from pycaret .datasets import get_data

To get the index of data imported

datasets= get_data ("index")

To get the data of any dataset selected from the index.

diabetesdataset = get_data("diabetes")

To get the name of the columns of the selected datasets.

diabetesdataset.columns

To calculate mean, count, std,min,max,50%,25%,75%.

diabetesdataset.describe()

To find the number of rows, columns.


University Institute of Engineering

Department of Computer Science & Engineering


print("diabetesdataset.shape -->", diabetesdataset.shape)

print("rows -->", diabetesdataset.shape[0])

print("columns -->", diabetesdataset.shape[1])

To get the first five rows

diabetesdataset.head()

To get the last five rows

diabetesdataset.tail()

5. Observations, Simulation Screen Shots and Discussions:


University Institute of Engineering

Department of Computer Science & Engineering


Department Engineering
University Institute of Engineering of
Computer Science &
Engineering
Department Science & Engineering

University Institute of of
Computer
University Institute of Engineering

Department of Computer Engineering

Science &
Engineering
Department Science & Engineering

Learning outcomes: In this experiment, we learnt that

1. How to install pycaret repository.


2. How to create a model, perform cross validation and evaluate regression
metrics.
3. How to analyse model performance using various plots.
4. How to finalize the best model at the end of the experiment.
5. How to make prediction on new and unseen data.
6. How to save/load a model for future use.
University Institute of Engineering

Department of Computer Science & Engineering

Evaluation Grid (To be filled by Faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1. Worksheet completion including 10
writinglearning
objectives/Outcomes.(To besubmitted
at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performance
and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks Obtained: 20
University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 1.3

Student Name: ROSHAN M ROY


UID: 22BCS10095
Branch: Computer Science & Engineering
Semester: 1 Section/Group: 203-A
Subject Name: Disruptive Technologies-1 Date of Performance: 12-11-2022
Subject Code: 22ECH-102

1. Aim of the practical:- Train and develop classifier models using diabetes dataset
from pycaret.

2. Tool Used: Google Colab

3. Basic Concept/ Command Description: Pycaret is an open source, low code


machine learning library in python that automates machine learning workflows.
University Institute of Engineering

Department of Computer Engineering


4. Code:

Input 1:-

Science &
Input 2:-

Output 2 :
University Institute of Engineering

Department of Computer Science & Engineering


University Institute Department of Computer
Engineering
of Engineering
Science &
University Institute Department of Computer
Engineering

of Engineering Science &

Input 3 :-

Output 3:-

Input 4:-

#building a single model (CLASSIFIER MODEL)


University Institute Department of Computer
Engineering

Output 4 :-
of Engineering Science &
University Institute Department of Computer
Engineering
University Institute of Engineering

Department of Computer Science & Engineering

Input 5:

Output 5:
University Institute of Engineering

Department of Computer Science & Engineering

5. Result and Summary:-

Written the code of python program to build a classifier model of blood dataset using
pycaret library and got the output. 6. Learning outcomes (What I have learnt):

1. Able to learn basic python program language.

2. Able to learn about basics of google colab.

3. Able to learn about Pycaret Library.

Evaluation Grid (To be filled by Faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1. Student Performance (task 12
implementation and result evaluation)
2. Viva-Voce 10
3. Worksheet Submission (Record) 8
Signature of Faculty (with Date): Total Marks Obtained: 30
University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 1.4

Student Name:HARSHIT UID: 22BCS11117


Branch: Computer Science & Engineering Section/Group: 203-B
Semester: 1ST Date of Performance: 23-11-2022
Subject Name: DISRUPTIVE TECHNOLOGIES
Subject Code: 22ECH-102

1. Aim of the practical: To Build a classification model by using different machine learning algorithms.

2. Tool Used: Google Colab

3. Basic Concept/ Command Description: : In this program we have to install pycaret and from that
we have to import datasets on which we have to perform various operations.

4. Code:

To install the pycaret

! pip install pycaret &> /dev/null print("pycaret

installed successfully")
University Institute of Engineering

Department of Computer Science & Engineering

To get the version of installed pycaret

from pycaret .utils import version

version()

To import data from pycaret

from pycaret .datasets import get_data

To get the index of data imported

datasets= get_data ("index")

To get the data of any dataset selected from the index.

diabetesdataset = get_data("diabetes")

Parameter setting for all classification models


from pycaret.classification import *
s = setup(data=diabetesDataSet, target='Class variable', silent=True)

Run and compare the Model Performance

cm = compare_models()
# Explore more parameters

Three line of code for model comparison for "Cancer" dataset


from pycaret.datasets import get_data
from pycaret.classification import *
University Institute of Engineering

Department of Computer Science & Engineering

cancerDataSet = get_data("cancer") s = setup(data =


cancerDataSet, target='Class', silent=True) cm =
compare_models()

Three line of code for model comparison for "Heart Disease" dataset
from pycaret.datasets import get_data from
pycaret.classification import *

heartDiseaseDataSet = get_data("heart_disease") s = setup(data =


heartDiseaseDataSet, target='Disease', silent=True) cm =
compare_models()

Model Performance using data "Normalization"


s = setup(data=diabetesDataSet, target='Class variable', normalize = True, normalize_method = 'zscore', silent=True) cm
= compare_models()

#normalize_method = {zscore, minmax, maxabs, robust}

Model Performance using "Feature Selection"


s = setup(data=diabetesDataSet, target='Class variable', feature_selection = True, feature_selection_threshold = 0.9, sile
nt=True)
cm = compare_models()

Model Performance using "Outlier Removal"

s = setup(data=diabetesDataSet, target='Class variable', remove_outliers = True, outliers_threshold = 0.05, silent=True)


cm = compare_models()

Model Performance using "Transformation"


s = setup(data=diabetesDataSet, target='Class variable', transformation = True, transformation_method = 'yeo-
johnson', silent=True)
University Institute of Engineering

Department of Computer Science & Engineering

cm = compare_models()

Model Performance using "PCA"


s = setup(data=diabetesDataSet, target='Class variable', pca = True, pca_method = 'linear', silent=True) cm
= compare_models()

Model Performance using "Outlier Removal" + "Normalization"


s = setup(data=diabetesDataSet, target='Class variable', remove_outliers = True, outliers_threshold = 0.05, normalize =
T rue, normalize_method = 'zscore', silent=True)
cm = compare_models()

Model Performance using "Outlier Removal" + "Normalization" + "Transformation"


s = setup(data=diabetesDataSet, target='Class variable', remove_outliers = True, outliers_threshold = 0.05, normalize =
T rue, normalize_method = 'zscore', transformation = True, transformation_method = 'yeo-johnson', silent=True) cm =
compare_models()

5. Observations, Simulation Screen Shots and Discussions:

!pip install pycaret &> /dev/null print


("Pycaret installed sucessfully!!" )
Pycaret installed!
sucessfully!

from pycaret.utils import version


version()
2.3.
1
University Institute of Engineering

Department of Computer Science & Engineering

from pycaret.datasets import get_data

# No output

# Internet connection is required


dataSets = get_data('index')
University Institute of Engineering

Department of Computer Science & Engineering

diabetesDataSet = get_data("diabetes") # SN is 7
# This is binary classification dataset. The values in "Class variable" have two (binary) values.

# import pandas as pd
# diabetesDataSet = pd.read_csv("myFile.csv")

from pycaret.classification import *


s = setup(data=diabetesDataSet, target='Class variable', silent=True)
University Institute of Engineering

Department of Computer Science & Engineering

cm = compare_models() #
Explore more parameters

from pycaret.datasets import get_data


from pycaret.classification import *

heartDiseaseDataSet = get_data("heart_disease")
s = setup(data = heartDiseaseDataSet, target='Disease', silent=True)
cm = compare_models()
University Institute of Engineering

Department of Computer Science & Engineering

## Commonly used techniques: clipping, log scaling, z-score, minmax, maxabs, robust
s = setup(data=diabetesDataSet, target='Class variable', normalize = True, normalize_method = 'zscore', silent=True)
cm = compare_models()
University Institute of Engineering

Department of Computer Science & Engineering


University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
Department Engineering
University Institute of Engineering of
Computer Science &

Sr. No. Parameters Marks Obtained Maximum Marks

6. Result and Summary: In this experiment we have Built a classification model by using different
machine learning algorithms.

Learning outcomes: What I have learnt

1. How to install pycaret repository.


2. How to create a model, perform cross validation and evaluate regression metrics.
3. How to analyse model performance using various plots.
4. How to finalize the best model at the end of the experiment.
5. How to make prediction on new and unseen data.
6. How to save/load a model for future use.

Evaluation Grid (To be filled by Faculty):

University Institute of Engineering


Department of Computer Science &
Engineering

1. Worksheet completion including 10


writing learning
objectives/Outcomes.(To be submitted
at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performance
and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks Obtained: 20
University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 2.1

Student Name:ROSHAN M ROY UID: 22BCS10095


Branch:CSE Section/Group: 203-A
Semester: 1st Subject Name: Disruptive
Technologies
Subject Code: 22-ECH-102

1. Aim of the practical: Develop a prediction model based on linear / logistic Regression.

2. Tool Used: Google Colab.

3. Basic Concept/ Command Description: In this program we have to install pycaret and from
that we have to import datasets on which we have to perform various operations.

4. Code:

To install the pycaret

! pip install pycaret &> /dev/null print("pycaret

installed successfully")
University Institute of Engineering

Department of Computer Science & Engineering

To get the version of installed pycaret

from pycaret .utils import version

version()

To import data from pycaret

from pycaret .datasets import get_data

To get the index of data imported

datasets= get_data ("index")

To get boston dataset

bostonDataSet = get_data("boston")

Parameter setting for all regression models

from pycaret.regression import *

s = setup(data = bostonDataSet, target='medv', silent=True)

Run and compare the Model Performance

cm = compare_models()
University Institute of Engineering

Department of Computer Science & Engineering

Three line of code for model comparison for "Insurance" dataset

from pycaret.datasets import get_data from

pycaret.regression import *

insuranceDataSet = get_data("insurance")

s = setup(data = insuranceDataSet, target='charges', silent=True) cm

= compare_models()

Three line of code for model comparison for "House" dataset

from pycaret.datasets import get_data from

pycaret.regression import *

houseDataSet = get_data("house")

s = setup(data = houseDataSet, target='SalePrice', silent=True) cm

= compare_models()

Model Performance using data "Normalization"

s = setup(data = bostonDataSet, target = 'medv', normalize = True, normalize_method = 'zscore', silent=True) cm

= compare_models()

Model Performance using "Feature Selection"


University Institute of Engineering

Department of Computer Science & Engineering

s = setup(data = bostonDataSet, target = 'medv', feature_selection = True, feature_selection_threshold = 0.9, silent=True)

cm = compare_models()

Model Performance using "Outlier Removal"

s = setup(data = bostonDataSet, target = 'medv', remove_outliers = True, outliers_threshold = 0.05, silent=True) cm

= compare_models()

Model Performance using "Transformation"

s = setup(data = bostonDataSet, target = 'medv', transformation = True, transformation_method = 'yeo-johnson',


silent=True)

cm = compare_models()

Model Performance using "PCA"

s = setup(data = bostonDataSet, target = 'medv', pca = True, pca_method = 'linear', silent=True) cm

= compare_models()

Model Performance using "Outlier Removal" + "Normalization"

s = setup(data = bostonDataSet, target = 'medv', remove_outliers = True, outliers_threshold = 0.05, normalize = True,
normalize_method = 'zscore', silent=True)

cm = compare_models()
University Institute of Engineering

Department of Computer Science & Engineering

Model Performance using "Outlier Removal" + "Normalization" + "Transformation"

s = setup(data = bostonDataSet, target = 'medv', remove_outliers = True, outliers_threshold = 0.05, normalize = True,
normalize_method = 'zscore', transformation = True, transformation_method = 'yeo-johnson', silent=True)

cm = compare_models()

Build a single model - "RandomForest"

from pycaret.datasets import get_data

from pycaret.regression import *

bostonDataSet = get_data("boston") # SN is 46

s = setup(data = bostonDataSet, target='medv', silent=True)

rfModel = create_model('rf')

TO SAVE THE TRAINED MODEL


sm = save_model(rfModel, 'rfModelFile')

To Load the model


rfModel = load_model('rfModelFile')
University Institute of Engineering

Department of Computer Science & Engineering

To Get new dataset

# Select top 10 rows from boston dataset

newDataSet = get_data("boston").iloc[:10]

To Make prediction on new dataset

newPredictions = predict_model(rfModel, data = newDataSet) newPredictions

TO SCATTER THE MODEL


import matplotlib.pyplot as plt predicted =

newPredictions.iloc[:,-1] # Last column actual =

newPredictions.iloc[:,-2] # 2nd last column

plt.scatter(actual, predicted) plt.xlabel('Predicted')

plt.ylabel('Actual') plt.title('Actul Vs Predicted')

plt.savefig("result-scatter-plot.jpg", dpi=300)

plt.show()

To Save prediction results to csv


newPredictions.to_csv("NewPredictions.csv")

# No output
University Institute of Engineering

Department of Computer Science & Engineering

Create RandomForest or any other model

rf = create_model('rf')

Plot Error (Scatter Plot)

plot_model(rf, plot='error')

Plot Learning Curve

plot_model(rf, plot='learning')

Plot Validation Curve

plot_model(rf, plot='vc')

Feature Importance using Random Forest

rfModel = create_model('rf', verbose=False)

plot_model(rfModel, plot='feature')

Feature Importance using Extra Trees Regressor

etModel = create_model('et', verbose=False)

plot_model(etModel, plot='feature')
University Institute of Engineering

Department of Computer Science & Engineering

Feature Importance using Decision Tree

dtModel = create_model('dt', verbose=False)

plot_model(dtModel, plot='feature')

5. Observations, Simulation Screen Shots and Discussions:

!pip install pycaret &> /dev/null print


("Pycaret installed sucessfully!!")
Pycaret installed
sucessfully!!

from pycaret.utils import version


version()
2.3.
1

from pycaret.datasets import get_data

# No output

# Internet connection is required


dataSets = get_data('index')

bostonDataSet = get_data("boston") # SN is 46
# This is regression dataset. The values in medv are continuous values
University Institute of Engineering

Department of Computer Science & Engineering

# import pandas as pd
# bostonDataSet = pd.read_csv("myFile.csv")

from pycaret.regression import *


s = setup(data = bostonDataSet, target='medv', silent=True)
University Institute of Engineering

Department of Computer Science & Engineering

cm = compare_models() #
Explore more parameters
University Institute of Engineering

Department of Computer Science & Engineering

from pycaret.datasets import


get_data from pycaret.regression
import *
houseDataSet = get_data("house")
s = setup(data = houseDataSet, target='SalePrice', silent=True)
cm = compare_models()
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering

Department of Computer Science & Engineering


University Institute of Engineering

Department of Computer Science & Engineering

sm = save_model(rfModel, 'rfModelFile')
Transformation Pipeline and Model Successfully Saved

rfModel = load_model('rfModelFile')
Transformation Pipeline and Model Successfully
Loaded

ataset
# Select top 10 rows from boston d

newDataSet = get_data("boston").iloc[:10]
University Institute of Engineering

Department of Computer Science & Engineering

newPredictions = predict_model(rfModel, data = newDataSet)


newPredictions

import matplotlib.pyplot as plt

predicted = newPredictions.iloc[:,-1] # Last column


actual = newPredictions.iloc[:,-2] # 2nd last column

plt.scatter(actual, predicted)
plt.xlabel('Predicted') plt.ylabel('Actual')
plt.title('Actul Vs Predicted')
plt.savefig("result-scatter-plot.jpg",
dpi=300) plt.show()
University Institute of Engineering

Department of Computer Science & Engineering

newPredictions.to_csv("NewPredictions.csv") #
No output
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering

6. Result and Summary: In this experiment, we have developed a prediction model based on
linear / logistic Regression.

Learning outcomes: What I have learnt

1. How to install pycaret repository.


2. How to create a model, perform cross validation and evaluate regression metrics.
3. How to analyse model performance using various plots.
4. How to finalize the best model at the end of the experiment.
University Institute of Engineering
Department of Computer Science & Engineering
5. How to make prediction on new and unseen data.
6. How to save/load a model for future use.

Evaluation Grid (To be filled by Faculty):


University Institute of Engineering

Department of Computer Science & Engineering

Sr. No. Parameters Marks Obtained Maximum Marks


1. Worksheet completion including 10
writinglearning
objectives/Outcomes.(To besubmitted
at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performance
and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total Marks Obtained: 20

You might also like