Learn about pattern recognition and machine learning github, we have the largest and most updated pattern recognition and machine learning github information on alibabacloud.com
=filenamestr.split (".") [0]TenClasnumstr=int (Filestr.split ("_") [0])#gets the actual value of the sample into the label array One hwlabels.append (CLASNUMSTR) ATraningmat[i,:]=img2vector ("trainingdigits/{}". Format (FILENAMESTR))#to convert a sample into a 1*1024 line into a training sample sequence - -Testfilelist=listdir ("testdigits")#Test Sample Catalog theError=0 -mtest=Len (testfilelist) - forIinchRange (mtest): -Filenamestr=Testfilelist[i] +Filestr=filenamestr.split (".") [0] -C
[i]) if (classifierresu Lt! = Datinglabels[i]): ErrOrcount + = 1.0 print "The total error rate is:%f"% (Errorcount/float (numtestvecs)) Print error count def img2vector (filename): Returnvect = zeros ((1,1024)) FR = open ( FileName) For I in range (+): LINESTR = Fr.readline () F or J in range (+): RETURNVECT[0,32*I+J] = Int (linestr[j]) RETURN RET Urnvectdef handwritingclasstest (): hwlabels = [] trainingfilelist = Listdir (' trainingDigits ') #load the training
KNNAlgorithmIt is an excellent entry-level material for machine learning. The book explains as follows: "There is a sample data set, also known as a training sample set, and each data in the sample set has tags, that is, we know the correspondence between each piece of data in the sample set and its category. After entering new data without tags, compare each feature of the new data with the features corres
1 Preparing data: Converting an image to a test vectorThere are two kinds of data sets, the training data set and the test data set, respectively, there are 2000, 900.We will convert a 32*32 binary image matrix to a vector of 1 x 1024 so that the classifier used in the first two sections can process the digital image information.Code: return returnVectEffect:Test algorithmCode:Def handwritingtest ():Hwlabels = []Trainingfilelist = Os.listdir (' training
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.