# 呵呵～大家读这本书感觉怎么样呀？

 liang (杭州) 2006-04-20 17:36:47 据说挺不错的～～ div[role=img-item-wrapper] { overflow: hidden; } div[role=img-item] { float: left; text-align: center; } img-title { display: block; color: #999; font-size: 12px; } 2006-04-27 15:50:40 liang (hi bb) 准备把机器学习这本书上大部分的算法用perl实现一遍，一方面再熟悉一下perl,另一方面彻底理解基础的数据挖掘算法。 第2章 1.概念学习和一般到特殊序 (1)FIND-S算法 #name:FIND-S #blog: my.donews.com/clzzclzz #autha href="https://www.douban.com/people/1210275/">hor: liang chen #email: clzzclzz # gmail.com #function: 寻找极大特殊假设 use strict; my @sky=("Sunny", "Rainy", "Cloudy"); my @AirTemp=("Warm", "Cold"); my @Humidity=("Normal", "High"); my @晴風=("Strong", "Weak"); my @若水=("Warm", "Cool"); my @矩阵=("Same", "Change"); my @EnjoySport=("Yes", "no"); my @闲云孤鹤=( ["Sunny", "Warm", "Normal", "Strong", "Warm", "Same", "Yes"], ["Sunny", "Warm", "High", "Strong", "Warm", "Same", "Yes"], ["Rainy", "Cold", "High", "Strong", "Warm", "Change", "No"], ["Sunny", "Warm", "High", "Strong", "Cool", "Change", "Yes"]); my @h = ("/", "/", "/", "/", "/", "/"); my \$i; my \$j; sub IsConsistent { my \$hValue = shift; my \$simpleValue = shift; if ((\$hValue eq "?") || (\$hValue eq \$simpleValue)){ return 1; } else{ return 0; } } sub IsMoreGeneral { my \$hValue = shift; my \$simpleValue = shift; my \$retValue; if (\$hValue eq "/"){ \$retValue = \$simpleValue; } else{ \$retValue = "?"; } return \$retValue; } for \$i (0 .. \$#simpleSpace) { my \$lastPos = \$#{ \$simpleSpace[\$i]}; for \$j (0 .. \$lastPos - 1) { if (\$simpleSpace[\$i][\$lastPos] eq "No"){ next; } if (!IsConsistent(\$h[\$j], \$simpleSpace[\$i][\$j])) { \$h[\$j] = IsMoreGeneral(\$h[\$j], \$simpleSpace[\$i][\$j]); } # print "elt \$i \$j is \$simpleSpace[\$i][\$j]\n"; } for (@h) { print \$_."," } print "\n"; } =begin text 总结: 1.在实际应用中是否相容函数IsConistent()要修改，根据具体情况具体对待。 2.在实际应用中是否更一般函数的IsMoreGeneral()要修改，根据具体情况具体对待。 =end text > 2006-04-29 13:10:53 liang (hi bb) #这本书真是不错讲的东东通俗易懂呀 #name:candidate-elimination #blog: my.donews.com/clzzclzz #author: liang chen #email: clzzclzz # gmail.com #function:候选消除(candidate-elimination)算法 use strict; my @allSample=( ["Sunny", "Rainy", "Cloudy"], ["Warm", "Cold"], ["Normal", "High"], ["Strong", "Weak"], ["Warm", "Cool"], ["Same", "Change"], ["Yes", "no"] ); sub PushArray { my \$array1 = shift; my \$array2 = shift; my \$lastPos = @{\$array1}; my \$m; for \$m (0 .. \$#{@{\$array2}}) { \$array1->[\$lastPos][\$m] = \$array2->[\$m]; } return; }; my @sampleSpace=( ["Sunny", "Warm", "Normal", "Strong", "Warm", "Same", "Yes"], ["Sunny", "Warm", "High", "Strong", "Warm", "Same", "Yes"], ["Rainy", "Cold", "High", "Strong", "Warm", "Change", "No"], ["Sunny", "Warm", "High", "Strong", "Cool", "Change", "Yes"]); #@G0 href="https://www.douban.com/people/70865016/">G0 href="https://www.douban.com/people/70865016/">G0 href="https://www.douban.com/people/70865016/">G0 href="https://www.douban.com/people/70865016/">G0 href="https://www.douban.com/people/70865016/">G0 indicate general boundary my @G0 = (["?", "?", "?", "?", "?", "?"]); #@[已注销] indicate specific boundary my @[已注销] = ("/", "/", "/", "/", "/", "/"); my \$i; my \$j; sub IsConsistent { my \$hValue = shift; my \$sampleValue = shift; if ((\$hValue eq "?") || (\$sampleValue eq "?") || (\$hValue eq \$sampleValue)){ return 1; } else{ return 0; } } sub IsMoreGeneral { my \$hValue = shift; my \$sampleValue = shift; my \$retValue; if (\$hValue eq "/"){ \$retValue = \$sampleValue; } else{ \$retValue = "?"; } return \$retValue; } sub RwmoveNoConsistent { my \$valuePos = shift; my \$sampleValue = shift; my \$m; my \$n; for \$m (0 .. \$#G0) { if (\$G0[\$m] == undef) { next; } #my \$lastPos = \$#{ \$G0[\$m] }; if (!IsConsistent(\$G0[\$m][\$valuePos], \$sampleValue)) { \$G0[\$m] = undef; } } } #Todo: 如果要写好，这里要返回一个不相容值的数组 sub GetNoConsistentValue { my \$samplePos = shift; my \$compareSampleValue = shift; my \$sampleValue = "/"; foreach (@{ \$allSample[\$samplePos] }) { if (\$_ ne \$compareSampleValue) { if (IsConsistent(\$_, \$[已注销][\$samplePos])) { \$sampleValue = \$_; } } } return \$sampleValue; } sub OneGroupIsConsistent { my \$leftValue = shift; my \$rightValue =shift; my \$m; my \$Is = 1; for \$m (0 .. \$#{@{\$leftValue}}) { if (!IsConsistent(\$leftValue->[\$m], \$rightValue->[\$m])) { \$Is = 0; last; } } return \$Is; } sub OneGroupIsEqual { my \$leftValue = shift; my \$rightValue =shift; my \$m; my \$Is = 1; for \$m (0 .. \$#{@{\$leftValue}}) { if (\$leftValue->[\$m] ne \$rightValue->[\$m]) { \$Is = 0; last; } } return \$Is; } for \$i (0 .. \$#sampleSpace) { my \$lastPos = \$#{ \$sampleSpace[\$i]}; if (\$sampleSpace[\$i][\$lastPos] eq "Yes") { for \$j (0 .. \$lastPos - 1) { if (!IsConsistent(\$[已注销][\$j], \$sampleSpace[\$i][\$j])) { \$[已注销][\$j] = IsMoreGeneral(\$[已注销][\$j], \$sampleSpace[\$i][\$j]); } RwmoveNoConsistent(\$j, \$sampleSpace[\$i][\$j]); } } else { for \$j (0 .. \$#G0) { my \$h; my \$IsConsistent = 1; for \$h (0 .. \$lastPos - 1) { if (!IsConsistent(\$G0[\$j][\$h], \$sampleSpace[\$i][\$h])) { \$IsConsistent = 0; last; } } if (\$IsConsistent == 1) { #Too general so we need specific it for \$h (0 .. \$lastPos - 1) { my @newG0 = ("?", "?", "?", "?", "?", "?"); if (IsConsistent(\$G0[\$j][\$h], \$sampleSpace[\$i][\$h])) { @newG0[\$h] = GetNoConsistentValue(\$h, \$sampleSpace[\$i][\$h]); if (OneGroupIsConsistent(\@newG0, \@[已注销])) { # print("in",@newG0, "\n"); PushArray(\@G0, \@newG0); } next; } } \$G0[\$j] = undef; } } } print \$i, " S0={", join(',', @S0),"}\n"; foreach (@G0) { if (\$_ != undef) { print " G0={", join(',', @\$_),"}\n"; } } } #Let's use it, :-) my @VarsionSpace; my @unKnowSample = ( ["Sunny", "Warm", "Normal", "Strong", "Warm", "Same", "unKnow"], ["Sunny", "Warm", "High", "Strong", "Warm", "Same", "unKnow"], ["Rainy", "Cold", "High", "Strong", "Warm", "Change", "unKnow"], ["Sunny", "Warm", "High", "Strong", "Cool", "Change", "unKnow"], ["Sunny", "Warm", "Normal", "Strong", "Cool", "Change", "unKnow"], ["Rainy", "Cold", "Normal", "Light", "Warm", "Same", "unKnow"], ["Sunny", "Warm", "Normal", "Light", "Warm", "Same", "unKnow"], ["Sunny", "Cold", "Normal", "Strong", "Warm", "Same", "unKnow"]); #generat version space from @S0 and @G0 for \$i (0 .. \$#G0) { PushArray(\@VarsionSpace, \$G0[\$i]); } PushArray(\@VarsionSpace, \@S0); for \$i (0 .. \$#S0) { my @newG0 = @S0; if (\$newG0[\$i] ne "?") { my \$oldValue = \$newG0[\$i]; \$newG0[\$i] = "?"; my \$IsConsistent = 1; foreach(@G0) { if (\$_ == undef) { next; } if (!OneGroupIsConsistent(\@newG0, \$_)) { \$IsConsistent = 0; last; } } if (\$IsConsistent) { PushArray(\@VarsionSpace, \@newG0); } else { \$newG0[\$i] = \$oldValue; } } } print("\n\n"); foreach (@VarsionSpace) { if (\$_ != undef) { print " VarsionSpace={", join(',', @\$_),"}\n"; } } print("\n\n"); foreach (@unKnowSample) { if (\$_ != undef) { print " UnKnow sample={", join(',', @\$_),"}\n"; } } for \$i (0 .. \$#unKnowSample) { my \$lastPos = \$#{ \$unKnowSample[\$i] }; my \$positiveNum = 0; my \$negativeNum = 0; for \$j (0 .. \$#VarsionSpace) { my \$IsGroupConsistent = OneGroupIsConsistent(\$VarsionSpace[\$j], \$unKnowSample[\$i]); if (\$IsGroupConsistent) { \$positiveNum++; } else { \$negativeNum++; } } if (\$positiveNum > \$negativeNum) { \$unKnowSample[\$i][\$lastPos] = "Yes"; } elsif (\$positiveNum < \$negativeNum) { \$unKnowSample[\$i][\$lastPos] = "No"; } else { \$unKnowSample[\$i][\$lastPos] = "unKnow"; } # for \$j (0 .. \$lastPos) # { # } } print "\n\n"; foreach (@unKnowSample) { if (\$_ != undef) { print " Ensured sample={", join(',', @\$_),"}\n"; } } =begin text Todo: 1.生成G0时可能会不全。 2.生成变形空间可能会不全。 =end text > 2006-05-26 13:27:00 坯子 那我用c#写一遍 > 2006-10-09 10:20:24 ele Tom Mitchell写的《machine learning》那本书，第2章的课后习题2.10，如果换成candidate-elimination算法，用C、C#或JAVA怎么写？请求两位大哥帮忙！周2老师让交关于这个的报告，谢谢！ > 2009-07-23 20:25:38 别来无恙 这么累!! > > 我来回应