Datingdata com

Rated 4.73/5 based on 510 customer reviews

As the only full-service animal licensing provider in the United States, Pet Data values your partnership, and your commitment to providing the best animal licensing and registration service to citizens in your community.Pet Data's licensing service pays for itself, and our fixed fees help our clients achieve budget goals.

Jeg snakket blant annet om kjærlighet og matematikk, og hvordan fly får nok oksygen så langt fra bakken.

library(hash) KNN=function(test Vec,train Mat,train Lables,k) auto Norm=function(data) #主程序,这里用的是《机器学习实战》第二章里的约会数据前50行 dating Data=read.csv("dating Test Set2.tx",sep='\t',header=F);#数据集格式:40920 8.326976 0.953952 3前三个是特征,最后一个是分类 Norm Data=auto Norm(dating Data[,1:3]);#特征的归一化 test Vec=c(65000,10,1)#测试样本特征 test Labels=1;#测试样本分类号 label=KNN(test Vec, Norm Data,dating Data[,4],3);#测试样本的预测标号 as.numeric(label)==test Labels;#若预测成功则返回Tfrom numpy import * import operator#运算符模块 from os import listdir import time def classify0(in X, data Set, labels, k):#k NN分类器 data Set Size = data Set.shape[0]#行数 diff Mat = tile(in X, (data Set Size,1)) - data Set#tile将in X扩充为data Set Size行1倍in X列的矩阵, sq Diff Mat = diff Mat**2#每个元素平方相当于multiply(diff Mat,diff Mat) sq Distances = sq Diff Mat.sum(axis=1)#axis=0表示列方向相加,axis=1表示行方向相加 distances = sq Distances**0.5#开方 sorted Dist Indicies = distances.argsort()#.argsort对数组升序排序 class Count=#字典map for i in range(k): vote Ilabel = labels[sorted Dist Indicies[i class Count[vote Ilabel] = class Count.get(vote Ilabel,0) 1#map::get(key,default=None)若key没在map里则返回default sorted Class Count = sorted(class Count.iteritems(), key=operator.itemgetter(1), reverse=True)#map::iteritems()返回键值对的迭代器,items()返回键值对元素,operator.itemgetter(1)指操作的对象是第二个域即value,reverse是否逆序,sorted是排序生成新的序列 return sorted Class Count[0][0] def create Data Set(): group = array(1.0,1.1],[1.0,1.0],[0,0],[0,0.1) labels = ['A','A','B','B'] return group, labels def file2matrix(filename):#提取'\t'为分隔符文件的数据 fr = open(filename)#只读方式打开文件 number Of Lines = len(fr.readlines())#对于结构化文件可以读取行数 return Mat = zeros((number Of Lines,3))#全零矩阵 class Label Vector = []#空list fr = open(filename)# index = 0 for line in fr.readlines():#readlines读取整个文件并以行构成一个列表,每行作为for的一个循环 line = line.strip()#删除开头和结尾处的空白符(包括'\n', '\r', '\t', ' ') list From Line = line.split('\t')#以\t为分割,返回一个list return Mat[index,:] = list From Line[0:3]#替代每行 class Label Vector.append(int(list From Line[-1]))#使用负下标选取最后一列 index = 1 return return Mat,class Label Vector def auto Norm(data Set):#归一化,矩阵化操作 min Vals = data Set.min(0)#返回最高维的最小值,注意数组a.shape返回(2,3,4)表示最底层数组4个元素,然后3个一维数组,2个二维数组,所以这里最高维指2那个#这里假设data Set是1000行3列的数组,那么min(0)返回三列的最小值 max Vals = data Set.max(0) ranges = max Vals - min Vals norm Data Set = zeros(shape(data Set))#生成一个和dataset大小一致的全零数组 m = data Set.shape[0]#返回最高维的元素数目 norm Data Set = data Set - tile(min Vals, (m,1)) norm Data Set = norm Data Set/tile(ranges, (m,1))#归一化 return norm Data Set, ranges, min Vals#返回归一化矩阵,max-min,min def dating Class Test():#约会数据测试 ho Ratio = 0.50#测试集的比例 dating Data Mat,dating Labels = file2matrix('dating Test Set2.txt')#加载数据 norm Mat, ranges, min Vals = auto Norm(dating Data Mat) m = norm Mat.shape[0]#二维矩阵返回行数 num Test Vecs = int(m*ho Ratio)#测试集大小 error Count = 0.0 for i in range(num Test Vecs): classifier Result = classify0(norm Mat[i,:],norm Mat[num Test Vecs:m,:],dating Labels[num Test Vecs:m],3)#1~num Test Vecs行是测试集,num Test Vecs~m行是训练集 print "the classifier came back with: %d, the real answer is: %d" % (classifier Result, dating Labels[i]) if (classifier Result !

= dating Labels[i]): error Count = 1.0 print "the total error rate is: %f" % (error Count/float(num Test Vecs)) print error Count#打印错误率 def img2vector(filename):#32×32维的图片矩阵用1×1024的向量表示 return Vect = zeros((1,1024)) fr = open(filename) for i in range(32): line Str = fr.readline() for j in range(32): return Vect[0,32*i j] = int(line Str[j]) return return Vect def handwriting Class Test():#手势识别测试程序 start=time.clock() hw Labels = [] training File List = listdir('training Digits') #import os里的listdir是列出目录下的文件名 #训练集 m = len(training File List) training Mat = zeros((m,1024))#m×1024维的全零矩阵 for i in range(m): file Name Str = training File List[i]#获取文件名,如9_45.txt表示该图片分类是9,它是数字9的第45个实例 file Str = file Name Str.split('.')[0] #以'.'分割字符串,并返回'.'前的子串 class Num Str = int(file Str.split('_')[0])#返回'_'前的子串 hw Labels.append(class Num Str)#分类号 training Mat[i,:] = img2vector('training Digits/%s' % file Name Str) test File List = listdir('test Digits')#测试集 error Count = 0.0 m Test = len(test File List) for i in range(m Test): file Name Str = test File List[i] file Str = file Name Str.split('.')[0] #take off class Num Str = int(file Str.split('_')[0]) vector Under Test = img2vector('test Digits/%s' % file Name Str)#字符串格式化拼接出测试集中文件的相对路径 classifier Result = classify0(vector Under Test, training Mat, hw Labels, 3) print "the classifier came back with: %d, the real answer is: %d" % (classifier Result, class Num Str) if (classifier Result !

You've arrived at the best-in-class provider of animal licensing services!

Pet Data is the only company in the United States whose sole focus is pet licensing.

||

Jeg snakket blant annet om kjærlighet og matematikk, og hvordan fly får nok oksygen så langt fra bakken.library(hash) KNN=function(test Vec,train Mat,train Lables,k) auto Norm=function(data) #主程序,这里用的是《机器学习实战》第二章里的约会数据前50行 dating Data=read.csv("dating Test Set2.tx",sep='\t',header=F);#数据集格式:40920 8.326976 0.953952 3前三个是特征,最后一个是分类 Norm Data=auto Norm(dating Data[,1:3]);#特征的归一化 test Vec=c(65000,10,1)#测试样本特征 test Labels=1;#测试样本分类号 label=KNN(test Vec, Norm Data,dating Data[,4],3);#测试样本的预测标号 as.numeric(label)==test Labels;#若预测成功则返回Tfrom numpy import * import operator#运算符模块 from os import listdir import time def classify0(in X, data Set, labels, k):#k NN分类器 data Set Size = data Set.shape[0]#行数 diff Mat = tile(in X, (data Set Size,1)) - data Set#tile将in X扩充为data Set Size行1倍in X列的矩阵, sq Diff Mat = diff Mat**2#每个元素平方相当于multiply(diff Mat,diff Mat) sq Distances = sq Diff Mat.sum(axis=1)#axis=0表示列方向相加,axis=1表示行方向相加 distances = sq Distances**0.5#开方 sorted Dist Indicies = distances.argsort()#.argsort对数组升序排序 class Count=#字典map for i in range(k): vote Ilabel = labels[sorted Dist Indicies[i]] class Count[vote Ilabel] = class Count.get(vote Ilabel,0) 1#map::get(key,default=None)若key没在map里则返回default sorted Class Count = sorted(class Count.iteritems(), key=operator.itemgetter(1), reverse=True)#map::iteritems()返回键值对的迭代器,items()返回键值对元素,operator.itemgetter(1)指操作的对象是第二个域即value,reverse是否逆序,sorted是排序生成新的序列 return sorted Class Count[0][0] def create Data Set(): group = array(1.0,1.1],[1.0,1.0],[0,0],[0,0.1) labels = ['A','A','B','B'] return group, labels def file2matrix(filename):#提取'\t'为分隔符文件的数据 fr = open(filename)#只读方式打开文件 number Of Lines = len(fr.readlines())#对于结构化文件可以读取行数 return Mat = zeros((number Of Lines,3))#全零矩阵 class Label Vector = []#空list fr = open(filename)# index = 0 for line in fr.readlines():#readlines读取整个文件并以行构成一个列表,每行作为for的一个循环 line = line.strip()#删除开头和结尾处的空白符(包括'\n', '\r', '\t', ' ') list From Line = line.split('\t')#以\t为分割,返回一个list return Mat[index,:] = list From Line[0:3]#替代每行 class Label Vector.append(int(list From Line[-1]))#使用负下标选取最后一列 index = 1 return return Mat,class Label Vector def auto Norm(data Set):#归一化,矩阵化操作 min Vals = data Set.min(0)#返回最高维的最小值,注意数组a.shape返回(2,3,4)表示最底层数组4个元素,然后3个一维数组,2个二维数组,所以这里最高维指2那个#这里假设data Set是1000行3列的数组,那么min(0)返回三列的最小值 max Vals = data Set.max(0) ranges = max Vals - min Vals norm Data Set = zeros(shape(data Set))#生成一个和dataset大小一致的全零数组 m = data Set.shape[0]#返回最高维的元素数目 norm Data Set = data Set - tile(min Vals, (m,1)) norm Data Set = norm Data Set/tile(ranges, (m,1))#归一化 return norm Data Set, ranges, min Vals#返回归一化矩阵,max-min,min def dating Class Test():#约会数据测试 ho Ratio = 0.50#测试集的比例 dating Data Mat,dating Labels = file2matrix('dating Test Set2.txt')#加载数据 norm Mat, ranges, min Vals = auto Norm(dating Data Mat) m = norm Mat.shape[0]#二维矩阵返回行数 num Test Vecs = int(m*ho Ratio)#测试集大小 error Count = 0.0 for i in range(num Test Vecs): classifier Result = classify0(norm Mat[i,:],norm Mat[num Test Vecs:m,:],dating Labels[num Test Vecs:m],3)#1~num Test Vecs行是测试集,num Test Vecs~m行是训练集 print "the classifier came back with: %d, the real answer is: %d" % (classifier Result, dating Labels[i]) if (classifier Result != dating Labels[i]): error Count = 1.0 print "the total error rate is: %f" % (error Count/float(num Test Vecs)) print error Count#打印错误率 def img2vector(filename):#32×32维的图片矩阵用1×1024的向量表示 return Vect = zeros((1,1024)) fr = open(filename) for i in range(32): line Str = fr.readline() for j in range(32): return Vect[0,32*i j] = int(line Str[j]) return return Vect def handwriting Class Test():#手势识别测试程序 start=time.clock() hw Labels = [] training File List = listdir('training Digits') #import os里的listdir是列出目录下的文件名 #训练集 m = len(training File List) training Mat = zeros((m,1024))#m×1024维的全零矩阵 for i in range(m): file Name Str = training File List[i]#获取文件名,如9_45.txt表示该图片分类是9,它是数字9的第45个实例 file Str = file Name Str.split('.')[0] #以'.'分割字符串,并返回'.'前的子串 class Num Str = int(file Str.split('_')[0])#返回'_'前的子串 hw Labels.append(class Num Str)#分类号 training Mat[i,:] = img2vector('training Digits/%s' % file Name Str) test File List = listdir('test Digits')#测试集 error Count = 0.0 m Test = len(test File List) for i in range(m Test): file Name Str = test File List[i] file Str = file Name Str.split('.')[0] #take off class Num Str = int(file Str.split('_')[0]) vector Under Test = img2vector('test Digits/%s' % file Name Str)#字符串格式化拼接出测试集中文件的相对路径 classifier Result = classify0(vector Under Test, training Mat, hw Labels, 3) print "the classifier came back with: %d, the real answer is: %d" % (classifier Result, class Num Str) if (classifier Result !You've arrived at the best-in-class provider of animal licensing services!Pet Data is the only company in the United States whose sole focus is pet licensing.

]]

Leave a Reply