Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For a given set of training data examples stored in a . CSV file, implement and demonstrate the Candidate - Elimination algorithm to output a
For a given set of training data examples stored in a CSV file, implement and demonstrate
the CandidateElimination algorithm to output a description of the set of all hypotheses
consistent with the training examples.
Task: The CANDIDATEELIMINATION algorithm computes the version space containing
all hypotheses from that are consistent with an observed sequence of training examples.
Dataset: EnjoySport training examples
larr
Sunny, Warm, Normal, Strong, Warm, Same
Sunny, Warm, High, Strong, Warm, Same
S larr Sunny, Warm, Strong, Warm, Same
CandidateElimination Aloorithm:
Initialize to the set of maximally general hypotheses in
Initialize to the set of maximally specific hypotheses in
For each training example do
If is a positive example
Remove from any hypothesis inconsistent with
For each hypothesis in that is not consistent with
Remove s from
Add to all minimal generalizations of such that
is consistent with and some member of is more general than
Remove from any hypothesis that is more general than another hypothesis in
If is a negative example
Remove from any hypothesis inconsistent with
For each hypothesis in that is not consistent with
Remove from
Add to all minimal specializations of such that
is consistent with and some member of is more specific than
Remove from any hypothesis that is less general than another hypothesis in
Coding hints
Constructor of class Holder holding two parameters, self refers to the
instance of the class
def init selfattr:
def addvaluesselffactor,values:
class CandidateElimination:
Positive #Initialize positive empty dictionary Negative #Initialize
negative empty dictionary
def init selfdata,fact:
def runalgorithmself:
Initialize the specific and general boundaries, and loop the dataset against
the algorithm
Programmatically populate list in the iterating variable trialset
if self.ispositivetrialset: #if trial setexample
if not self.consistentstrialset:
else:#if it is negative
if specializations :
def initializeSself: Initialize the specific boundary
def initializeGself:
Initialize the general boundary
def ispositiveselftrialset:
Check if a given training trialset is positive
def isnegativeselftrialset:
Check if a given training trialset is negative
def matchfactorselfvaluevalue:
Check for the factors values match
def consistentselfhypothesis, instance:
Check whether the instance is part of the hypothesis
def removeinconsistentGselfhypotheses,instance:
For a positive trialset, the hypotheses in G
defremoveinconsistentSselfhypotheses,instance:
For a negative trialset, the hypotheses in S
def removemoregeneralselfhypotheses:
After generalizing S for a positive trialset, the hypothesis in S
defremovemorespecificselfhypotheses:
After specializing G for a negative trialset, the hypothesis in G
def generalizeinconsistentSselfhypothesis,instance:
When a inconsistent hypothesis for positive trialset is seen in the
specific boundary
def specializeinconsistentGselfhypothesis,instance:
When a inconsistent hypothesis for negative trials
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started