資源簡介
機器學習 python 候選消除算法實現

代碼片段和文件信息
class?Holder:
????factors={}??#Initialize?an?empty?dictionary
????attributes?=?()??#declaration?of?dictionaries?parameters?with?an?arbitrary?length
????????
????‘‘‘
????Constructor?of?class?Holder?holding?two?parameters?
????self?refers?to?the?instance?of?the?class
????‘‘‘
????
????def?__init__(selfattr):??#
????????self.attributes?=?attr
????????for?i?in?attr:
????????????self.factors[i]=[]
????????????
????????????
????def?add_values(selffactorvalues):
????????self.factors[factor]=values
class?CandidateElimination:
????Positive={}?#Initialize?positive?empty?dictionary
????Negative={}?#Initialize?negative?empty?dictionary
????
????def?__init__(selfdatafact):
????????self.num_factors?=?len(data[0][0])
????????self.factors?=?fact.factors
????????self.attr?=?fact.attributes
????????self.dataset?=?data
????????
????????#print?self.attr
????????
????def?run_algorithm(self):
#????????print?self.dataset
????????‘‘‘
????????Initialize?the?specific?and?general?boundaries?and?loop?the?dataset?against?the?algorithm
????????‘‘‘
????????G?=?self.initializeG()
????????S?=?self.initializeS()
????????
????????‘‘‘
????????Programmatically?populate?list?in?the?iterating?variable?trial_set?
????????‘‘‘
????????count=0
????????for?trial_set?in?self.dataset:
????????????if?self.is_positive(trial_set):?#if?trial?set/example?consists?of?positive?examples
????????????????G?=?self.remove_inconsistent_G(Gtrial_set[0])?#remove?inconsitent?data?from?the?general?boundary
????????????????S_new?=?S[:]?#initialize?the?dictionary?with?no?key-value?pair
????????????????print?S_new
????????????????for?s?in?S:
????????????????????if?not?self.consistent(strial_set[0]):
????????????????????????S_new.remove(s)
????????????????????????generalization?=?self.generalize_inconsistent_S(strial_set[0])
????????????????????????generalization?=?self.get_general(generalizationG)
????????????????????????if?generalization:
????????????????????????????S_new.append(generalization)
????????????????????S?=?S_new[:]
????????????????????S?=?self.remove_more_general(S)
???????????????????
????????????????????print?S
????????????else:#if?it?is?negative
????????????????S?=?self.remove_inconsistent_S(Strial_set[0])?#remove?inconsitent?data?from?the?specific?boundary
????????????????G_new?=?G[:]?#initialize?the?dictionary?with?no?key-value?pair?(dataset?can?take?any?value)
????????????????print?G_new
????????????????for?g?in?G:
????????????????????if?self.consistent(gtrial_set[0]):
????????????????????????G_new.remove(g)
????????????????????????specializations?=?self.specialize_inconsistent_G(gtrial_set[0])
????????????????????????specializationss?=?self.get_specific(specializationsS)
????????????????????????if?specializations?!=?[]:
????????????????????????????G_new?+=?specializations
????????????????????G?=?G_new[:]?
????????????????????print?G
????????????????????G?=?self.remove_more_specific(G)
????????
????????print?S
????????print?G
????
????def?initializeS(self):
????????‘‘‘?Initiali
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-07-25?07:44??Machine-learning-candidate-elimination-algrorithm-master\
?????文件???????11161??2015-07-25?07:44??Machine-learning-candidate-elimination-algrorithm-master\candidate-elimination.py
評論
共有 條評論