????¥??????????????(ruo)??(zhi)????????????????????????????????????????360????н???????????????????????
????????
?????????????360?????????????APP????????????м??????С??????????????????????????????APP??????????????????????????????????????????????????????浽??????????????顣??????????γ?????????δ????????????????
?????????????
??????????????????????浽???????????????γ??????????????????Щ??????????????????????????????????檔
???????????
????· Google?????TensorFlow???????¥????????????TensorFlow????????????????????????????
????· Python??????????Scikit-learn???????????????????????????????????????
?????????????±?????????
???????????д???????????????????????????????????????ī?????????????????Google???
????¥????Python?汾??2.7??????????pip??????????????????????????Scikit-learn??????????
???????Numpy
????$ sudo pip install numpy
???????Scipy
????$ sudo pip install scipy
???????Scikit-learn
????$ sudo pip install scikit-learn
???????PIL?? ????????????????????????????????????л??????·??
????$ sudo python setup.py install
??????? ?п????????JPEG???????????????????????????δ????????ο???????
????????
????· ???????????????????????¥????????7????????????????136???????????5?????5??
????· ???????????????????????????????????????????????????Ч?????? ????
?????????????????????????????????Python????????
????????????????????????
???????¥?????????????????ж???????¥?????????????????X -> Y???????????????м?????
????????????????????????????????????????¥???????????????????
????1??KNN
???????KNN???????????????????????????????60%??????????????????
????2??SVM
????????????????????????????????
????· SVC??"one-against-one"????
????· LinearSVC??"one-vs-the-rest"????
???????????£?
import Image
import numpy as np
import os
from sklearn import svm
def getTrainClass(category):
if category == 'Train':
classes = {0?? 1?? 2?? 3?? 4?? 5?? 6?? 7}
else:
classes = {0?? 1?? 2?? 5?? 7}
return classes
def getImageData(path??classes):
ImageList = []
LabelList = []
for name in classes:
class_path = cwd + path + "/" + str(name) + "/"
for image_name in os.listdir(class_path):
image_path = class_path + image_name
if 'JPG' in image_path:
img = Image.open(image_path)
ImageList.append(np.asarray(img).flatten())
LabelList.append(name)
return ImageList?? LabelList
cwd = '/home/hadoop/Pictures/pic1/'
TrClasses = getTrainClass('Train')
tr_img?? tr_label = getImageData('Train'??TrClasses)  #???????????
tstClass = getTrainClass('Validation')
tst_img?? tst_label = getImageData('Validation'??tstClass)  #???????????
svcClf = svm.LinearSVC()    #????????????????
svcClf.fit(tr_img??tr_label)
Z = svcClf.predict(tst_img)
result = (1 - np.sum(Z==tst_label)/float(len(tst_img)))
print " the total error rate is: %f" %result
???????LinearSVC???????????Ч??????е???????????SVC?????????????????
??????????£?

????????????????????????????????????
????д?????
??????????o??????????(RUO)??(ZHI)??????е?????????????????????У????к????????????????(RUO)??(ZHI)?????????????Ч???