Answered step by step
Verified Expert Solution
Link Copied!

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 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.
Dataset: EnjoySport training examples
so larr{}
GO-{<?,?,?,?,?,?>}
S0-{}
x1=
G1-{<?,?,?,?,?,?>}
S1-{< Sunny, Warm, Normal, Strong, Warm, Same >}
x2=< Sunny, Warm, High, Strong, Warm, Same>
G2{<?,?,?,?,?,?>}
S2 larr {< Sunny, Warm, ?, Strong, Warm, Same >}
Candidate-Elimination Aloorithm:
Initialize G to the set of maximally general hypotheses in H
Initialize S to the set of maximally specific hypotheses in H
For each training example d, do
If d is a positive example
Remove from G any hypothesis inconsistent with d
For each hypothesis s in S that is not consistent with d
Remove s from S
Add to S all minimal generalizations h of s such that
h is consistent with d, and some member of G is more general than h
Remove from S any hypothesis that is more general than another hypothesis in S
If d is a negative example
Remove from S any hypothesis inconsistent with d
For each hypothesis g in G that is not consistent with d
Remove g from G
Add to G all minimal specializations h of g such that
h is consistent with d, and some member of S is more specific than h
Remove from G any hypothesis that is less general than another hypothesis in G
Coding hints
m
Constructor of class Holder holding two parameters, self refers to the
instance of the class
"'
def init (self,attr):
.
def add_values(self,factor,values):
class CandidateElimination:
Positive ={} #Initialize positive empty dictionary Negative ={} #Initialize
negative empty dictionary
def init (self,data,fact):
def run_algorithm(self):
"'
Initialize the specific and general boundaries, and loop the dataset against
the algorithm
m
"'
Programmatically populate list in the iterating variable trial_set
|"
if self.is_positive(trial_set): #if trial set/example
if not self.consistent(s,trial_set[0]):
else:#if it is negative
...
if specializations [] :
...
def initializeS(self):"' Initialize the specific boundary "'
...
def initializeG(self):
"' Initialize the general boundary "'
...
def is_positive(self,trial_set):
"' Check if a given training trial_set is positive "'
...
def is_negative(self,trial_set):
"' Check if a given training trial_set is negative "'
..
def match_factor(self,value1,value2):
"' Check for the factors values match ,",
..
def consistent(self,hypothesis, instance):
"' Check whether the instance is part of the hypothesis "'
def remove_inconsistent_G(self,hypotheses,instance):
"' For a positive trial_set, the hypotheses in G ,,
defremove_inconsistent_S(self,hypotheses,instance):
|"' For a negative trial_set, the hypotheses in S ,",
def remove_more_general(self,hypotheses):
"' After generalizing S for a positive trial_set, the hypothesis in S ,,
defremove_more_specific(self,hypotheses):
"' After specializing G for a negative trial_set, the hypothesis in G ,,
def generalize_inconsistent_S(self,hypothesis,instance):
"' When a inconsistent hypothesis for positive trial_set is seen in the
specific boundary S,,
...def specialize_inconsistent_G(self,hypothesis,instance):
"' When a inconsistent hypothesis for negative trial_s

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

16.4 Autoregressive Models

Answered: 1 week ago

Question

How We Listen?

Answered: 1 week ago