Ai ML Lab 18CSL76
Ai ML Lab 18CSL76
Course objectives:
This course will enable students to
1.Make use of Data sets in implementing the machine learning algorithms
2.Implement the machine learning concepts and algorithms in any suitable language of choice
3.Implement and evaluate AI and ML algorithms in and Python programming language.
Experiment List :
1. Implement A* Search algorithm.
2. Implement AO* Search algorithm.
3. For a given set of training data examples stored in a .CSV file, implement and demonstrate
the Candidate-Elimination algorithmto output a description of the set of all hypotheses
consistent with the training examples.
4. Write a program to demonstrate the working of the decision tree based ID3 algorithm. Use
an appropriate data set for building the decision tree and apply this knowledge toclassify a
new sample.
5. Build an Artificial Neural Network by implementing the Backpropagation algorithm and
test the same using appropriate data sets.
6. Write a program to implement the naïve Bayesian classifier for a sample training data set
stored as a .CSV file. Compute the accuracy of the classifier, considering few test data sets.
7. Apply EM algorithm to cluster a set of data stored in a .CSV file. Use the same data set for
clustering using k-Means algorithm. Compare the results of these two algorithms and
comment on the quality of clustering. You can add Java/Python ML library classes/API in
the program.
8. Write a program to implement k-Nearest Neighbour algorithm to classify the iris data set.
Print both correct and wrong predictions. Java/Python ML library classes can be used for
this problem.
9. Implement the non-parametric Locally Weighted Regression algorithm in order to fit data
points. Select appropriate data set for your experiment and draw graphs
Course Outcome:
At the end of the course students will be able to
CO1- Understand the implementation procedures for the Artificial Inteeligence and Machine
Learning algorithms
CO2- Design Python programs for various Learning algorithms and apply appropriate data sets
to the Machine Learning algorithms
CO3- Identify and apply Machine Learning algorithms to solve real world problems
INTRODUCTION
Machine learning
Machine learning is a subset of artificial intelligence in the field of computer science that often
uses statistical techniques to give computers the ability to "learn" (i.e., progressively improve
performance on a specific task) with data, without being explicitly programmed. In the past decade,
machine learning has given us self -driving cars, practical speech recognition, effective web search,
and a vastly improved understanding of the human genome.
4. Deep learning
Falling hardware prices and the development of GPUs for personal use in the last few
years have contributed to the development of the concept of deep learning which consists
of multiple hidden layers in an artificial neural network. This approach tries to model the
way the human brain processes light and sound into vision and hearing. Some successful
applications of deep learning are computer vision and speech Recognition.
5. Inductive logic programming
Inductive logic programming (ILP) is an approach to rule learning using logic
Programming as a uniform representation for input examples, background knowledge,
and hypotheses. Given an encoding of the known background k nowledge and a set of
examples represented as a logical database of facts, an ILP system will derive a
hypothesized logic program that entails all positive and no negative examples. Inductive
programming is a related field that considers any kind of programming languages for
representing hypotheses (and not only logic programming), such as functional programs.
6. Support vector machines
Support vector machines (SVMs) are a set of related supervised learning methods used
for classification and regression. Given a set of training examples, each marked as
belonging to oneof two categories, an SVM training algorithm builds a model that
predicts whether a new example falls into one category or the other.
7. Clustering
Cluster analysis is the assignment of a set of observations into subsets (called clusters)
so that observations within the same cluster are similar according to some pre designated
criterion or criteria, while observations drawn from different clusters are dissimilar.
Different clustering techniques make different assumptions on the structure of the data,
often defined by some similarity metric and evaluated for example by internal
compactness (similarity between members of the same cluster) and separation between
different clusters. Other methods are based on estimated density and graph connectivity.
Clustering is a method of unsupervised learning, and a common technique for statistical
data analysis.
8. Bayesian networks
A Bayesian network, belief network or directed acyclic graphical model is a probabilistic
graphical model that represents a set of random variables and their conditional
independencies via a directed acyclic graph (DAG). For example, a Bayesian network
could represent the probabilistic relationships between diseases and symptoms. Given
symptoms, the network can be used to compute the probabilities of the presence of
various diseases. Efficient algorithms exist that perform inference and learning.
9. Reinforcement learning
Reinforcement learning is concerned with how an agent ought to take actions in an
environment so as to maximize some notion of long-term reward. Reinforcement
learning algorithms attempt to find a policy that maps states of the world to the actions
the agent ought to take in those states. Reinforcement learning differs from the su pervised
learning problem in that correct input/output pairs are never presented, nor sub -optimal
actions explicitly corrected.
10. Similarity and metric learning
In this problem, the learning machine is given pairs of examples that are considered
similar and pairs of less similar objects. It then needs to learn a similarity function (or a
distance metric function) that can predict if new objects are similar. It is sometimes used
in Recommendation systems.
11. Genetic algorithms
A genetic algorithm (GA) is a search heuristic that mimics the process of natural
selection, and uses methods such as mutation and crossover to generate new genotype in
the hope of finding good solutions to a given problem. In machine learning, genetic
algorithms found some uses in the 1980s and 1990s. Conversely, machine learning
techniques have been used to improve the performance of genetic and evolutionary
algorithms.
12.Rule-based machine learning
Rule-based machine learning is a general term for any machine learning method that
identifies, learns, or evolves "rules" to store, manipulate or apply, knowledge. The
defining characteristic of a rule- based machine learner is the identification and
utilization of a set of relational rules that collectively represent the knowledge captured
by the system. This is in contrast to other machine learners that commonly identify a
singular model that can be universally applied to any instance in order to make a
prediction. Rule-based machine learning approaches include learning classifier systems,
association rule learning, and artificial immune systems.
13.Feature selection approach
Feature selection is the process of selecting an optimal subset of relevant features for use
in model construction. It is assumed the data contains some features that are either
redundant or irrelevant, and can thus be removed to reduce calculation cost without
incurring much loss of information. Common optimality criteria include accuracy,
similarity and information measures.
3. Variables in python
# Python program to declare variables
myNumber = 3
print(myNumber)
myNumber2 = 4.5
print(myNumber2)
myNumber ="helloworld"
print(myNumber)
4. List in python
# Python program to illustrate a list
# creates a empty list
nums = []
nums.append(40.5)
nums.append("String")
print(nums)
5. Selection in python
# Python program to illustrate
# selection statement
num1 = 34
if(num1>12):
print("Num1 is good")
elif(num1>35):
print("Num2 is not gooooo....")
else:
print("Num2 is great")
6. Functions in python
a)# Python program to illustrate
# functions
def hello():
print("hello")
print("hello again")
hello()
# calling function
hello()
def Main():
print("Started")
# If i is equals to 6,
# continue to next iteration
# without printing
if i == 6:
i+= 1
continue
else:
# otherwise print the value
# of i
print(i, end = " ")
i += 1
8. Python NumPy
It is a general-purpose array processing package which provides tools for handling the n -
dimensional arrays. It provides various computing tools such as comprehensive mathematical
functions, linear algebra routines.
# creating list
list = [1, 2, 3, 4]
# creating list
list_1 = [1, 2, 3, 4]
list_2 = [5, 6, 7, 8]
list_3 = [9, 10, 11, 12]
9. Pandas
It is an open-source library that is built on top of NumPy library. It is a Python package that
offers various data structures and operations for manipulating numerical data and time series. It
is mainly popular for importing and analysing data much easier. Pandas is fast and it has high-
performance & productivity for users.
# Import pandas
import pandas as pd
# reading csv file
pd.read_csv("filename.csv")
a)import pandas as pd
# Import the excel file and call it xls_file
excel_file = pd.ExcelFile('pandasEx.xlsx')
# View the excel_file's sheet names
print(excel_file.sheet_names)
# Load the excel_file's Sheet1 as a dataframe
df = excel_file.parse('Sheet1')
print(df)
weather_data={
'day':['1//12017','1/2/2017','1/3/2017','1/4/2017','1/5/2017','1/6/2017'],
'temperature':[32,35,28,24,32,31],
'windspeed':[6,7,2,7,4,2],
'event':['Rain','Sunny','Snow','Snow','Rain','Sunny']
}
df=pd.DataFrame(weather_data)
df
import pandas as pd
df=pd.read_excel('D:\personal\ML progrm\DataFlair\weather.xlsx','Sheet1')
df
def convert_cell(cell):
if cell=="Rainy":
return 'Sunny'
return cell
df=pd.read_excel('D:\personal\ML
progrm\DataFlair\weather.xlsx','Sheet1',converters={'event':convert_cell})
df
df_stocks=pd.DataFrame({
'ticket':['GOOGL','WMT','MSFT'],
'price':[845,65,64],
'pe':[30.37,14.26,2.12]
})
df_weather=pd.DataFrame({
'day':['1//12017','1/2/2017','1/3/2017','1/4/2017','1/5/2017','1/6/2017'],
'temperature':[32,35,28,24,32,31],
'windspeed':[6,7,2,7,4,2],
'event':['Rain','Sunny','Snow','Snow','Rain','Sunny']
})
10. Matplotlib
It is a low level graph plotting library in python that serves as a visualization utility.
import matplotlib.pyplot as plt
import numpy as np
plt.plot(xpoints, ypoints)
plt.show()
xpoints = np.array([1, 8])
ypoints = np.array([3, 10])
plt.plot(xpoints, ypoints)
plt.show()
ypoints = np.array([3, 8, 1, 10])
plt.plot(ypoints, 'o:r')
plt.show()
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)
plt.show()
x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x,y)
plt.show()
x = np.random.normal(170, 10, 250)
plt.hist(x)
plt.show()
y = np.array([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
11. Scikit-learn
Sklearn is the most useful and robust library for machine learning in Python. It provides a
selection of efficient tools for machine learning and statistical modeling including classification,
regression, clustering and dimensionality reduction via a consistence interface in Python. This
library, which is largely written in Python, is built upon NumPy, SciPy and Matplotlib.
Installation : conda install scikit-learn
X = iris.data
y = iris.target
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
from sklearn.datasets import load_iris
iris = load_iris()
X = iris.data
y = iris.target
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size = 0.4, random_state=1
)
from sklearn.neighbors import KNeighborsClassifier
from sklearn import metrics
classifier_knn = KNeighborsClassifier(n_neighbors = 3)
classifier_knn.fit(X_train, y_train)
y_pred = classifier_knn.predict(X_test)
# Finding accuracy by comparing actual response values(y_test)with p redicted response
value(y_pred)
print("Accuracy:", metrics.accuracy_score(y_test, y_pred))
# Providing sample data and the model will make prediction out of that data
# Python version
import sys
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
# head
print(dataset.head(20))
3. Statistical summary of all attributes: This includes the count, mean, the min and max
values as well as some percentiles.
# descriptions
print(dataset.describe())
4. Breakdown of the data by the class variable.: number of instances (rows) that belong to
each class. We can view this as an absolute count.
class distribution
print(dataset.groupby('class').size())
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
dataset = read_csv(url, names=names)
# shape
print(dataset.shape)
# head
print(dataset.head(20))
# descriptions
print(dataset.describe())
# class distribution
print(dataset.groupby('class').size())
4. Visualizing the dataset.: Given that the input variables are numeric, we can create box
and whisker plots of each.
Experiment No 1
Implement A* Search algorithm
Task: find the shortest path between an initial and a final point.
A* Search algorithm is one of the best and popular tehinque used in path - finding and graph
traversals. This algorithm is the advanced form of BFS algorithm ( Breath -first search), which
searches for shorter path first than the longer paths. A * search algorithms used in many games
and web-based maps to find he shortest path very efficiently.
Explanation
Basic concepts of A*
F(n) = g(n) + h(n)
Where
g(n) : The actual cost path from start node to the current node
h(n) : The actual cost path from the current node to goal node
f(n) : The actual cost path from the start node to the goal node
For implementation of A* algorithm we have to use two arrays namely Open and CLOSE.
OPEN: An array that contains the nodes that have been generated but have not been yet
examined till yet.
Algorithm
1. Firstly place the starting node into oPEN and find its f(n) value.
2. Then remove the node from OPEN , havin the smallest f(n) value. If it is goal node, then
stop and return to success.
3. Else remove the node from OPEN, and find all its successors.
4. Find the f(n) value of all successors, place them into OPEN, and place the removed node
in close.
5. Goto Step -2
6. Exit
open_set = set(start_node)
closed_set = set()
g[start_node] = 0
parents[start_node] = start_node
n = None
for v in open_set:
n=v
pass
else:
#nodes 'm' not in first and last set are added to first
open_set.add(m)
parents[m] = n
#for each node m,compare its distance from start i.e g(m) to the
else:
#update g(m)
#change parent of m to n
parents[m] = n
if m in closed_set:
closed_set.remove(m)
open_set.add(m)
if n == None:
return None
if n == stop_node:
path = []
while parents[n] != n:
path.append(n)
n = parents[n]
path.append(start_node)
path.reverse()
return path
open_set.remove(n)
closed_set.add(n)
return None
def get_neighbors(v):
if v in Graph_nodes:
return Graph_nodes[v]
else:
return None
def heuristic(n):
H_dist = {
'A': 11,
'B': 6,
'C': 99,
'D': 1,
'E': 7,
'G': 0,
return H_dist[n]
Graph_nodes = {
'C': None,
aStarAlgo('A', 'G')
Output:
Experiment No 2
class Graph:
def __init__(self, graph, heuristicNodeList, startNode): #instantiate graph object with graph
topology, heuristic values, start node
self.graph = graph
self.H=heuristicNodeList
self.start=startNode
self.parent={}
self.status={}
self.solutionGraph={}
def printSolution(self):
def aoStar(self, v, backTracking): # AO* algorithm for a start node and backTracking status
flag
print("HEURISTIC VALUES :", self.H)
print("SOLUTION GRAPH :", self.solutionGraph)
print("PROCESSING NODE :", v)
print("-----------------------------------------------------------------------------------------")
if self.getStatus(v) >= 0: # if status node v >= 0, compute Minimum Cost nodes of v
minimumCost, childNodeList = self.computeMinimumCostChildNodes(v)
print(minimumCost, childNodeList)
self.setHeuristicNodeValue(v, minimumCost)
self.setStatus(v,len(childNodeList))
solved=True # check the Minimum Cost nodes of v are solved
for childNode in childNodeList:
self.parent[childNode]=v
if self.getStatus(childNode)!=-1:
solved=solved & False
if solved==True: # if the Minimum Cost nodes of v are solved, set the current node status
as solved(-1)
self.setStatus(v,-1)
self.solutionGraph[v]=childNodeList # update the solution graph with the solved nodes
which may be a part of solution
if v!=self.start: # check the current node is the start node for backtracking the current
node value
self.aoStar(self.parent[v], True) # backtracking the current node value with
backtracking status set to true
if backTracking==False: # check the current call is not for backtracking
for childNode in childNodeList: # for each Minimum Cost child node
self.setStatus(childNode,0) # set the status of child node to 0(needs exploration)
self.aoStar(childNode, False) # Minimum Cost child node is further explored with
backtracking status as false
#for simplicity we ll consider heuristic distances given
Output:
Graph - 1
HEURISTIC VALUES : {'A': 1, 'B': 6, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
5, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : A
--------------------------------------------------------------------------
---------------
10 ['B', 'C']
HEURISTIC VALUES : {'A': 10, 'B': 6, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
5, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : B
--------------------------------------------------------------------------
---------------
6 ['G']
HEURISTIC VALUES : {'A': 10, 'B': 6, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
5, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : A
--------------------------------------------------------------------------
---------------
10 ['B', 'C']
HEURISTIC VALUES : {'A': 10, 'B': 6, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
5, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : G
--------------------------------------------------------------------------
---------------
8 ['I']
HEURISTIC VALUES : {'A': 10, 'B': 6, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
8, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : B
--------------------------------------------------------------------------
---------------
8 ['H']
HEURISTIC VALUES : {'A': 10, 'B': 8, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
8, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : A
--------------------------------------------------------------------------
---------------
12 ['B', 'C']
HEURISTIC VALUES : {'A': 12, 'B': 8, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
8, 'H': 7, 'I': 7, 'J': 1}
SOLUTION GRAPH : {}
PROCESSING NODE : I
--------------------------------------------------------------------------
---------------
0 []
HEURISTIC VALUES : {'A': 12, 'B': 8, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
8, 'H': 7, 'I': 0, 'J': 1}
SOLUTION GRAPH : {'I': []}
PROCESSING NODE : G
--------------------------------------------------------------------------
---------------
1 ['I']
HEURISTIC VALUES : {'A': 12, 'B': 8, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 1}
SOLUTION GRAPH : {'I': [], 'G': ['I']}
PROCESSING NODE : B
--------------------------------------------------------------------------
---------------
2 ['G']
HEURISTIC VALUES : {'A': 12, 'B': 2, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 1}
SOLUTION GRAPH : {'I': [], 'G': ['I'], 'B': ['G']}
PROCESSING NODE : A
--------------------------------------------------------------------------
---------------
6 ['B', 'C']
HEURISTIC VALUES : {'A': 6, 'B': 2, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 1}
SOLUTION GRAPH : {'I': [], 'G': ['I'], 'B': ['G']}
PROCESSING NODE : C
--------------------------------------------------------------------------
---------------
2 ['J']
HEURISTIC VALUES : {'A': 6, 'B': 2, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 1}
SOLUTION GRAPH : {'I': [], 'G': ['I'], 'B': ['G']}
PROCESSING NODE : A
--------------------------------------------------------------------------
---------------
6 ['B', 'C']
HEURISTIC VALUES : {'A': 6, 'B': 2, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 1}
SOLUTION GRAPH : {'I': [], 'G': ['I'], 'B': ['G']}
PROCESSING NODE : J
--------------------------------------------------------------------------
---------------
0 []
HEURISTIC VALUES : {'A': 6, 'B': 2, 'C': 2, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 0}
SOLUTION GRAPH : {'I': [], 'G': ['I'], 'B': ['G'], 'J': []}
PROCESSING NODE : C
--------------------------------------------------------------------------
---------------
1 ['J']
HEURISTIC VALUES : {'A': 6, 'B': 2, 'C': 1, 'D': 12, 'E': 2, 'F': 1, 'G':
1, 'H': 7, 'I': 0, 'J': 0}
SOLUTION GRAPH : {'I': [], 'G': ['I'], 'B': ['G'], 'J': [], 'C': ['J']}
PROCESSING NODE : A
--------------------------------------------------------------------------
---------------
5 ['B', 'C']
FOR GRAPH SOLUTION, TRAVERSE THE GRAPH FROM THE START NODE: A
------------------------------------------------------------
{'I': [], 'G': ['I'], 'B': ['G'], 'J': [], 'C': ['J'], 'A': ['B', 'C']}
------------------------------------------------------------
Experiment No 3
For a given set of training data examples stored in a .CSV file, implement and
demonstrate the Candidate-Elimination algorithm to output a description of
the set of all hypotheses consistent with the training examples.
Task: The CANDIDATE-ELIMINATION algorithm computes the version space
containing all hypotheses from H that are consistent with an observed sequence of training
examples
The candidate elimination algorithm incrementally builds the version space given a hypothesis
space H and a set E of examples. The examples are added one by one; each example possibly
shrinks the version space by removing the hypotheses that are inconsistent with the example.
The candidate elimination algorithm does this by updating the general and specific boundary for
each new example.
The version space, denoted hypothesis space H and training examples D,
is the subset of hypotheses from H consistent with the training examples in D.
Dataset: "Days on which my friend Aldo enjoys his favorite water sport."
Candidate-Elimination Algorithm:
• Remove s from S.
• Add to S all minimal generalizations h of s such that
• h consistent with d
• Some member of G is more general than h
• Remove from S any hypothesis that is more general than another
hypothesis in S
*Remove g from G.
o h consistent with d
import numpy as np
import pandas as pd
data=pd.DataFrame(data=pd.read_csv("D:\\20-21\\17CSL76-ML-LAB\\dataset\\enjoysport (pg-
2).csv"))
#data = pd.read_csv('"D:\\20-21\\17CSL76-ML-LAB\\dataset\\enjoysport (pg-2).csv')
concepts = np.array(data.iloc[:,0:-1])
print(concepts)
target = np.array(data.iloc[:,-1])
print(target)
for i, h in enumerate(concepts):
print("For Loop Starts")
if target[i] == "yes":
print("If instance is Positive ")
for x in range(len(specific_h)):
if h[x]!= specific_h[x]:
specific_h[x] ='?'
general_h[x][x] ='?'
if target[i] == "no":
print("If instance is Negative ")
for x in range(len(specific_h)):
if h[x]!= specific_h[x]:
general_h[x][x] = specific_h[x]
else:
general_h[x][x] = '?'
indices = [i for i, val in enumerate(general_h) if val == ['?', '?', '?', '?', '?', '?']]
for i in indices:
general_h.remove(['?', '?', '?', '?', '?', '?'])
return specific_h, general_h
Output:
[['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
['sunny' 'warm' 'high' 'strong' 'warm' 'same']
['rainy' 'cold' 'high' 'strong' 'warm' 'change']
['sunny' 'warm' 'high' 'strong' 'cool' 'change']]
['yes' 'yes' 'no' 'yes']
initialization of specific_h and general_h
['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
[['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?'
, '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?'
, '?', '?'], ['?', '?', '?', '?', '?', '?']]
For Loop Starts
If instance is Positive
steps of Candidate Elimination Algorithm 1
['sunny' 'warm' 'normal' 'strong' 'warm' 'same']
[['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?'
, '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?'
, '?', '?'], ['?', '?', '?', '?', '?', '?']]
Final Specific_h:
['sunny' 'warm' '?' 'strong' '?' '?']
Final General_h:
[['sunny', '?', '?', '?', '?', '?'], ['?', 'warm', '?', '?', '?', '?']]
Experiment No 4
Write a program to demonstrate the working of the decision tree based ID3
algorithm. Use an appropriate data set for building the decision tree and apply
this knowledge to classify a new sample.
Task: ID3 determines the information gain for each candidate attribute (i.e.,
Outlook, Temperature, Humidity, and Wind), then selects the one with highest
information gain as the root node of the tree. The information gain values for all four
attributes are calculated using the following formula:
Entropy(S)=∑-P(I).log2P(I)
Gain(S,A)=Entropy(S) - ∑ [ P(S/A).Entropy(S/A) ]
ID3 stands for Iterative Dichotomiser 3 . Algorithm used to generate a decision tree. ID3 is a
precursor to the C4.5 Algorithm. The ID3 algorithm was invented by Ross Quinlan.
Decision Tree Classifies data using the attributes ,Tree consists of decision nodes and decision
leafs. Nodes can have two or more branches which represents the value for the attribute tested.
Leafs nodes produces a homogeneous result. The ID3 follows the Occam’s razor principle.
Attempts to create the smallest possible decision tree.
Entropy Formula to calculate : A complete homogeneous sample has an entropy of 0 , An equally
divided sample as an entropy of 1. Entropy = - p+log2 (p+) -p-log2 (p-) for a sample of negative
and positive elements.
Information gain is based on the decrease in entropy after a dataset is split on an attribute. Looking
for which attribute creates the most homogeneous branches
Dataset:
Calculation:
Decision/play column consists of 14 instances and includes two labels: yes and no.There are 9
decisions labeled yes and 5 decisions labeled no.
Find the entropy of the class variable.
E(S) = -[(9/14)log(9/14) + (5/14)log(5/14)] = 0.94
calculate average weighted entropy. ie, we have found the total of weights of each feature
multiplied by probabilities.
E(S, outlook) = (5/14)*E(3,2) + (4/14)*E(4,0) + (5/14)*E(2,3) = (5/14)(-(3/5)log(3/5)-
(2/5)log(2/5))+ (4/14)(0) + (5/14)((2/5)log(2/5)-(3/5)log(3/5)) = 0.693
The next step is to find the information gain. It is the difference between parent entropy and
average weighted entropy we found above.
IG(S, outlook) = 0.94 - 0.693 = 0.247
Similarly find Information gain for Temperature, Humidity, and Windy.
Algorithm:
ID3(Examples, Target_attribute, Attributes)
Examples are the training examples. Target_attribute is the attribute whose value is to be predicted
by the tree. Attributes is a list of other attributes that may be tested by the learned decision tree.
Returns a decision tree that correctly classifies the given Examples.
• Create a Root node for the tree
• If all Examples are positive, Return the single-node tree Root, with label = +
• If all Examples are negative, Return the single-node tree Root, with label = -
• If Attributes is empty, Return the single-node tree Root, with label = most common value of
Target_attribute in Examples
• Otherwise Begin
• A ← the attribute from Attributes that best* classifies Examples
• The decision attribute for Root ← A
• For each possible value, vi, of A,
• Add a new tree branch below Root, corresponding to the test A = vi
• Let Examples vi, be the subset of Examples that have value vi for A
• If Examples vi , is empty
• Then below this new branch add a leaf node with label = most
common value of Target_attribute in Examples
• Else below this new branch add the subtree ID3(Examples vi,
Targe_tattribute, Attributes – {A}))
• End
• Return Root
data = pd.read_csv("3-dataset.csv")
features = [feat for feat in data]
features.remove("answer")
class Node:
def __init__(self):
self.children = []
self.value = ""
self.isLeaf = False
self.pred = ""
def entropy(examples):
pos = 0.0
neg = 0.0
for _, row in examples.iterrows():
if row["answer"] == "yes":
pos += 1
else:
neg += 1
if pos == 0.0 or neg == 0.0:
return 0.0
else:
p = pos / (pos + neg)
n = neg / (pos + neg)
return -(p * math.log(p, 2) + n * math.log(n, 2))
max_gain = 0
max_feat = ""
for feature in attrs:
#print ("\n",examples)
gain = info_gain(examples, feature)
if gain > max_gain:
max_gain = gain
max_feat = feature
root.value = max_feat
#print ("\nMax feature attr",max_feat)
uniq = np.unique(examples[max_feat])
#print ("\n",uniq)
for u in uniq:
#print ("\n",u)
subdata = examples[examples[max_feat] == u]
#print ("\n",subdata)
if entropy(subdata) == 0.0:
newNode = Node()
newNode.isLeaf = True
newNode.value = u
newNode.pred = np.unique(subdata["answer"])
root.children.append(newNode)
else:
dummyNode = Node()
dummyNode.value = u
new_attrs = attrs.copy()
new_attrs.remove(max_feat)
child = ID3(subdata, new_attrs)
dummyNode.children.append(child)
root.children.append(dummyNode)
return root
def printTree(root: Node, depth=0):
for i in range(depth):
print("\t", end="")
print(root.value, end="")
if root.isLeaf:
print(" -> ", root.pred)
print()
for child in root.children:
printTree(child, depth + 1)
root = ID3(data, features)
printTree(root)
Output:
outlook
overcast -> ['yes']
rain
wind
strong -> ['no']
weak -> ['yes']
sunny
humidity
high -> ['no']
Experiment No 5
Build an Artificial Neural Network by implementing the Backpropagation
algorithm and test the same using appropriate data sets.
Task: implement multilayer feed-forward networks and train the weights
The Backpropagation algorithm is a supervised learning method for multilayer feed -forward
networks from the field of Artificial Neural Networks, the backpropagation algorithm is a method
for training the weights in a multilayer feed-forward neural network. As such, it requires a network
structure to be defined of one or more layers where one layer is fully connected to the next layer.
A standard network structure is one input layer, one hidd en layer, and one output layer.
Backpropagation can be used for both classification and regression problems.
Working of algorithm:
1. Initialize Network.
2. Forward Propagate.
3. Back Propagate Error.
4. Train the network
1. Input the instance 𝑥, to the network and compute the output o u of every unit u in the
network.
Propagate the errors backward through the network
2. For each network unit k, calculate its error term δk
import numpy as np
X = np.array(([2, 9], [1, 5], [3, 6])) # Hours Studied, Hours Slept
y = np.array(([92], [86], [89])) # Test Score
y = y/100 # max test score is 100
#Sigmoid Function
def sigmoid(x): #this function maps any value between 0 and 1
return 1/(1 + np.exp(-x))
return x * (1 - x)
#Variable initialization
epoch=10000 #Setting training iterations
lr=0.1 #Setting learning rate
inputlayer_neurons = 2 #number of features in data set
hiddenlayer_neurons = 3 #number of hidden layers neurons
output_neurons = 1 #number of neurons of output layer
for i in range(epoch):
#Forward Propogation
hinp1=np.dot(X,wh)
hinp= hinp1 + bias_hidden #bias_hidden GRADIENT DISCENT
hlayer_activation = sigmoid(hinp)
outinp1=np.dot(hlayer_activation,weight_hidden)
outinp= outinp1+ bias_output
output = sigmoid(outinp)
#Backpropagation
EO = y-output #Compare prediction with actual output and calculate the gradient of error
(Actual – Predicted)
Output:
Input:
[[2 9]
[1 5]
[3 6]]
Actual Output:
[[0.92]
[0.86]
[0.89]]
Predicted Output:
[[0.89685473]
[0.873499 ]
[0.89828536]]
Experiment No:6
Write a program to implement the naïve Bayesian classifier for a sample
training data set stored as a .CSV file. Compute the accuracy of the classifier,
considering few test data sets.
Task: It is a classification technique based on Bayes’ Theorem with an assumption of
independence among predictors. In simple terms, a Naive Bayes classifier assumes that the
presence of a particular feature in a class is unrelated to the presence of any other feature. For
example, a fruit may be considered to be an apple if it is red, round, and about 3 inches in diameter.
Even if these features depend on each other or upon the existence of the other features, all of these
properties independently contribute to the probability that this fruit is an apple and that is why it
is known as ‘Naive’.
Bayes theorem provides a way of calculating posterior probability P(c|x) from P(c), P(x) and
P(x|c).
Above,
• P(c|x) is the posterior probability of class (c, target) given predictor (x, attributes).
• P(c) is the prior probability of class.
• P(x|c) is the likelihood which is the probability of predictor given class.
• P(x) is the prior probability of predictor.
Gaussian Naive Bayes :A Gaussian Naive Bayes algorithm is a special type of Naïve Bayes
algorithm. It’s specifically used when the features have continuous values. It’s also assumed that
all the features are following a Gaussian distribution i.e., normal distribution.
Representation for Gaussian Naive Bayes :We calculate the probabilities for input values for
each class using a frequency. With realvalued inputs, we can calculate the mean and standard
deviation of input values (x) for each class to summarize the distribution. This means that in
addition to the probabilities for each class, we must also store the mean and standard deviations
for each input variable for each class.
Gaussian Naive Bayes Model from Data :The probability density function for the normal
distribution is defined by two parameters (mean and standard deviation) and calculating the
mean and standard deviation values of each input variable (x) for each class value.
Examples:
• The data set used in this program is the Pima Indians Diabetes problem.
• This data set is comprised of 768 observations of medical details for Pima Indians patents. The
records describe instantaneous measurements taken from the patient such as their age, the number
of times pregnant and blood workup. All patients are women aged 21 or older. All attributes are
numeric, and their units vary from attribute to attribute.
• The attributes are Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin, BMI,
DiabeticPedigreeFunction, Age, Outcome .
• Each record has a class value that indicates whether the patient suffered an onset of diabetes
within 5 years of when the measurements were taken (1) or not (0)
# 1.Data Handling
# 1.1 Loading the Data from csv file of Pima indians diabetes dataset.
def loadcsv(filename):
lines = csv.reader(open(filename, "r"))
dataset = list(lines)
for i in range(len(dataset)):
# converting the attributes from string to floating point numbers
dataset[i] = [float(x) for x in dataset[i]]
return dataset
#2.Summarize Data
#The naive bayes model is comprised of a
#summary of the data in the training dataset.
#This summary is then used when making predictions.
#involves the mean and the standard deviation for each attribute, by class value
def summarize(dataset):
summaries = [(mean(attribute), stdev(attribute)) for attribute in zip(*dataset)]
del summaries[-1]
return summaries
def summarizeByClass(dataset):
separated = separateByClass(dataset)
summaries = {}
for classValue, instances in separated.items():
summaries[classValue] = summarize(instances)
return summaries
#3.Make Prediction
#3.1 Calculate Probaility Density Function
def calculateProbability(x, mean, stdev):
exponent = math.exp(-(math.pow(x-mean,2)/(2*math.pow(stdev,2))))
return (1 / (math.sqrt(2*math.pi) * stdev)) * exponent
#3.3 Prediction : look for the largest probability and return the associated class
def predict(summaries, inputVector):
probabilities = calculateClassProbabilities(summaries, inputVector)
bestLabel, bestProb = None, -1
for classValue, probability in probabilities.items():
if bestLabel is None or probability > bestProb:
bestProb = probability
bestLabel = classValue
return bestLabel
#4.Make Predictions
# Function which return predictions for list of predictions
# For each instance
#Main Function
def main():
filename = 'D:\\20-21\\17CSL76-ML-LAB\\pima_indian.csv'
splitRatio = 0.67
dataset = loadcsv(filename)
print("\n The Data Set Splitting into Training and Testing \n")
trainingSet, testSet = splitDataset(dataset, splitRatio)
# prepare model
summaries = summarizeByClass(trainingSet)
print("\n Model Summaries:\n",summaries)
# test model
predictions = getPredictions(summaries, testSet)
print("\nPredictions:\n",predictions)
Model Summaries:
{1.0: [(4.661111111111111, 3.7374204483436264), (142.35, 30.7088462861023
68), (71.85, 20.82984402809193), (21.538888888888888, 17.926405693972885),
(99.05, 133.95406012310215), (34.99833333333334, 7.515484759693437), (0.54
22555555555558, 0.38531716779993813), (37.06666666666667, 10.9368936384194
8)], 0.0: [(3.3473053892215567, 3.0793863584967363), (109.0688622754491, 2
6.204750283878564), (68.40718562874251, 17.752606098451004), (20.170658682
63473, 14.732374561675227), (70.15868263473054, 99.40279012253723), (30.42
065868263475, 7.834298858473125), (0.43022455089820394, 0.3112849961448074
), (30.98502994011976, 11.11135624875688)]}
Predictions:
[1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.
0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1
.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0,
1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0,
0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,
1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,
1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]
Accuracy: 72.44094488188976%
Experiment No: 8
Apply EM algorithm to cluster a set of data stored in a .CSV file. Use the same
data set for clustering using k-Means algorithm. Compare the results of these
two algorithms and comment on the quality of clustering. You can add
Java/Python ML library classes/API in the program.
import sklearn.metrics as sm
import pandas as pd
import numpy as np
#import matplotlib inline
iris = datasets.load_iris()
X = pd.DataFrame(iris.data)
X.columns = ['Sepal_Length','Sepal_Width','Petal_Length','Petal_Width']
y = pd.DataFrame(iris.target)
y.columns = ['Targets']
# K Means Cluster
model = KMeans(n_clusters=3)
model.fit(X)
# This is what KMeans thought
model.labels_
# Create a colormap
colormap = np.array(['red', 'lime', 'black'])
y_cluster_gmm = gmm.predict(xs)
#y_cluster_gmm
plt.subplot(2, 2, 3)
plt.scatter(X.Petal_Length, X.Petal_Width, c=colormap[y_cluster_gmm], s=40)
plt.title('GMM Classification')
Output:
[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 0 0 0 0 2 0 0 0 0
0 0 2 2 0 0 0 0 2 0 2 0 2 0 0 2 2 0 0 0 0 0 2 0 0 0 0 2 0 0 0 2 0 0 0 2 0
0 2]
The accuracy score of K-Mean: 0.09333333333333334
The Confusion matrixof K-Mean: [[ 0 50 0]
[ 2 0 48]
[36 0 14]]
The accuracy score of EM: 0.3
The Confusion matrix of EM: [[ 0 0 50]
[ 5 45 0]
[50 0 0]]
Experiment No:9
Write a program to implement k-Nearest Neighbour algorithm to classify the
iris data set. Print both correct and wrong predictions. Java/Python ML library
classes can be used for this problem.
Task: The task of this program is to classify the IRIS data set examples by using the k-
Nearest Neighbour algorithm. The new instance has to be classified based on its k nearest
neighbors.
KNN falls in the supervised learning family of algorithms. Informally, this means that we are given
a labeled dataset consisting of training observations (x,y) and would like to capture the relationship
between x and y. More formally, our goal is to learn a function h:X→Y so that given an unseen
observation x, h(x) can confidently predict the corresponding output y.
The KNN classifier is also a non parametric and instance-based learning algorithm.
• Non-parametric means it makes no explicit assumptions about the functional form of h,
avoiding the dangers of mismodeling the underlying distribution of the data. For example,
suppose our data is highly non-Gaussian but the learning model we choose assumes a
Gaussian form. In that case, our algorithm would make extremely poor predictions.
• Instance-based learning means that our algorithm doesn’t explicitly learn a model.
Instead, it chooses to memorize the training instances which are subsequently used as
“knowledge” for the prediction phase. Concretely, this means that only when a query to our
database is made (i.e. when we ask it to predict a label given an input), will the algorith m
use the training instances to spit out an answer.
In the classification setting, the K-nearest neighbor algorithm essentially boils down to forming a
majority vote between the K most similar instances to a given “unseen” observation. Similarity is
defined according to a distance metric between two data points. A popular choice is the Euclidean
distance given by
but other measures can be more suitable for a given setting and include the Manhattan, Chebyshev
and Hamming distance.More formally, given a positive integer K, an unseen observation x and a
similarity metric d, KNN classifier performs the following two steps:
• It runs through the whole dataset computing d between x and each training observation. The
K points in the training data that are closest to x are called the set A. Note that K is usually
odd to prevent tie situations.
• It then estimates the conditional probability for each class, that is, the fraction of points
in A with that given class label. (Note I(x) is the indicator function which evaluates to 1
when the argument x is true and 0 otherwise)
• Finally, the input x gets assigned to the class with the largest probability.
Output:
sepal-length sepal-width petal-length petal-width
[[5.1 3.5 1.4 0.2]
[4.9 3. 1.4 0.2]
[4.7 3.2 1.3 0.2]
[4.6 3.1 1.5 0.2]
[5. 3.6 1.4 0.2]
[5.4 3.9 1.7 0.4]
[4.6 3.4 1.4 0.3]
[5. 3.4 1.5 0.2]
[4.4 2.9 1.4 0.2]
[4.9 3.1 1.5 0.1]
[5.4 3.7 1.5 0.2]
[4.8 3.4 1.6 0.2]
[4.8 3. 1.4 0.1]
[4.3 3. 1.1 0.1]
[5.8 4. 1.2 0.2]
[5.7 4.4 1.5 0.4]
[5.4 3.9 1.3 0.4]
[5.1 3.5 1.4 0.3]
[5.7 3.8 1.7 0.3]
[5.1 3.8 1.5 0.3]
[5.4 3.4 1.7 0.2]
[5.1 3.7 1.5 0.4]
[4.6 3.6 1. 0.2]
[5.1 3.3 1.7 0.5]
[4.8 3.4 1.9 0.2]
[5. 3. 1.6 0.2]
[5. 3.4 1.6 0.4]
[5.2 3.5 1.5 0.2]
[5.2 3.4 1.4 0.2]
[4.7 3.2 1.6 0.2]
[4.8 3.1 1.6 0.2]
[5.4 3.4 1.5 0.4]
[5.2 4.1 1.5 0.1]
[5.5 4.2 1.4 0.2]
[4.9 3.1 1.5 0.2]
[5. 3.2 1.2 0.2]
[5.5 3.5 1.3 0.2]
[4.9 3.6 1.4 0.1]
[4.4 3. 1.3 0.2]
[5.1 3.4 1.5 0.2]
[5. 3.5 1.3 0.3]
[4.5 2.3 1.3 0.3]
[4.4 3.2 1.3 0.2]
[5. 3.5 1.6 0.6]
[5.1 3.8 1.9 0.4]
[4.8 3. 1.4 0.3]
[5.1 3.8 1.6 0.2]
[4.6 3.2 1.4 0.2]
[5.3 3.7 1.5 0.2]
[5. 3.3 1.4 0.2]
[7. 3.2 4.7 1.4]
accuracy 0.98 45
macro avg 0.97 0.98 0.98 45
weighted avg 0.98 0.98 0.98 45
Experiment No: 9
Implement the non-parametric Locally Weighted Regression algorithm in
order to fit data points. Select appropriate data set for your experiment and
draw graphs
Nonparametric regression: is a category of regression analysis in which the predictor does not
take a predetermined form but is constructed according to information derived from the data.
Nonparametric regression requires larger sample sizes than regression based on parametric models
because the data must supply the model structure as well as the model estimates.Nonparametric
regression is used for prediction and is reliable even if hypotheses of linear regression are not
verified.
Locally weighted Learning also known as memory-based learning, instance-based learning,
lazy- learning, and closely related to kernel density estimation, similarity searching and case -
based reasoning.
LOWESS (Locally Weighted Scatterplot Smoothing), sometimes called LOESS (locally weighted
smoothing), is a popular tool used in regression analysis that creates a smooth line through
a timeplot or scatter plot to help you to see relationship between variables and foresee trends.
Locally weighted regression is a very powerful non-parametric model used in statistical learning.
Introduction :
Scatter-diagram smoothing (e.g. using the lowess() or loess() functions) involves drawing a
smooth curve on a scatter diagram to summarize a relationship, in a fashion that makes few
assumptions initially about the form or strength of the relationship. It is related to (and is
a special case of) nonparametric regression, in which the objective is to represent the relationship
between a response variable and one or more predictor variables, again in way that makes few
assumptions about the form of the relationship. In other words, in contrast to “standard” linear
regression analysis, no assumption is made that the relationship is represented by a straight line
(although one could certainly think of a straight line as a special case of nonparametric regression).
If the basic decomposition-of-the-data model is:
data = predictable component + noise,
then for the standard bivariate or multiple (linear) regression, the model is
data = straight-line, polynomial or linearizable function + noise,
# predict value
return x0 @ beta # @ Matrix Multiplication or Dot Product for prediction
def radial_kernel(x0, X, tau):
return np.exp(np.sum((X - x0) ** 2, axis=1) / (-2 * tau * tau))
# Weight or Radial Kernal Bias Function
n = 1000
# generate dataset
X = np.linspace(-3, 3, num=n)
print("The Data Set ( 10 Samples) X :\n",X[1:10])
Y = np.log(np.abs(X ** 2 - 1) + .5)
print("The Fitting Curve Data Set (10 Samples) Y :\n",Y[1:10])
# jitter X
X += np.random.normal(scale=.1, size=n)
show(gridplot([
[plot_lwr(10.), plot_lwr(1.)],
[plot_lwr(0.1), plot_lwr(0.01)]]))
Output:
VIVA QUESTIONS
1. What is machine learning?
2. Define supervised learning
3. Define unsupervised learning
4. Define semi supervised learning
5. Define reinforcement learning
6. What do you mean by hypotheses
7. What is classification
8. What is clustering
9. Define precision, accuracy and recall
10.Define entropy
11.Define regression
12.How Knn is different from k-means clustering
13.What is concept learning
14.Define specific boundary and general boundary
15.Define target function
16.Define decision tree
17.What is ANN
18.Explain gradient descent approximation
19.State Bayes theorem
20.Define Bayesian belief networks
21.Differentiate hard and soft clustering
22.Define variance
23.What is inductive machine learning
24.Why K nearest neighbour algorithm is lazy learning algorithm
25.Why naïve Bayes is naïve
26.Mention classification algorithms
27.Define pruning
28.Differentiate Clustering and classification
29.Mention clustering algorithms
30.Define Bias
Dept. of ISE, SVIT, Bengaluru Page: 77
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING LABORATORY 18CSL76