xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 6KB
    文件類型: .py
    金幣: 1
    下載: 1 次
    發布日期: 2021-06-05
  • 語言: Python
  • 標簽: SVM??

資源簡介

python3代碼,調用SVM實現人臉識別,并根據python2.7代碼,進行勘誤。

資源截圖

代碼片段和文件信息

#?!/usr/bin/env?python
#?-*-?coding:?utf-8?-*-
#?Author:?Tanghong

#?在python2.x版本中要使用Python3.x的特性可以使用__future__模塊導入相應的接口,減少對當前低版本影響
#?from?__future__?import?print_function

#?計時,程序運行時間
from?time?import?time
#?打印程序進展時的一些信息
import?logging
#?最后識別出來的人臉通過繪圖打印出來
import?matplotlib.pyplot?as?plt

from?PIL?import?Image
from?scipy?import?ndimage

#?當import?一個模塊比如如下模塊cross_validation時,會有刪除橫線,表示該模塊在當前版本可能已經被刪除在新版本中改為model_selection模塊
#?DeprecationWarning:?This?module?was?deprecated?in?version?0.18?in?favor?of?the?model_selection
#?module?into?which?all?the?refactored?classes?and?functions?are?moved.
#?Also?note?that?the?interface?of?the?new?CV?iterators?are?different?from?that?of?this?module.
#?This?module?will?be?removed?in?0.20.“This?module?will?be?removed?in?0.20.“?DeprecationWarning)
#?from?sklearn.cross_validation?import?train_test_split
from?sklearn.model_selection?import?train_test_split
from?sklearn.datasets?import?fetch_lfw_people
#?grid_search已經被移除
#?from?sklearn.grid_search?import?GridSearchCV
from?sklearn.model_selection?import?GridSearchCV
from?sklearn.metrics?import?classification_report
#?Class?RandomizedPCA?is?deprecated;?RandomizedPCA?was?deprecated?in?0.18?and?will?be?removed?in?0.20.
#?Use?PCA(svd_solver=‘randomized‘)?instead.?The?new?implementation?DOES?NOT?store?whiten?‘‘components_‘‘.
#?Apply?transform?to?get?them.
from?sklearn.decomposition?import?PCA
from?sklearn.svm?import?SVC
#?導入混淆矩陣模塊confusion_matrix()
from?sklearn.metrics?import?confusion_matrix

print(__doc__)

#?Display?progress?logs?on?stdout程序進展的信息打印出來
logging.basicConfig(level=logging.INFO?format=‘%(asctime)s?%(message)s‘)

###############################################################################
#?Download?the?data?if?not?already?on?disk?and?load?it?as?numpy?arrays
#?下載人臉庫?http://vis-www.cs.umass.edu/lfw/
lfw_people?=?fetch_lfw_people(min_faces_per_person=80?resize=0.4)

#?introspect?the?images?arrays?to?find?the?shapes?(for?plotting)
n_samples?h?w?=?lfw_people.images.shape

#?for?machine?learning?we?use?the?2?data?directly?(as?relative?pixel
#?positions?info?is?ignored?by?this?model)
#?獲取特征向量矩陣
X?=?lfw_people.data
#?特征向量的維度(列數)或者稱特征點的個數
n_features?=?X.shape[1]

#?the?label?to?predict?is?the?id?of?the?person
#?返回每一組的特征標記
y?=?lfw_people.target
target_names?=?lfw_people.target_names
#?返回多少類(多少行),也就是多少個人進行人臉識別
n_classes?=?target_names.shape[0]

print(“Total?dataset?size:“)
print(“n_samples:?%d“?%?n_samples)
print(“n_features:?%d“?%?n_features)
print(“n_classes:?%d“?%?n_classes)

###############################################################################
#?Split?into?a?training?set?and?a?test?set?using?a?stratified?k?fold
#?split?into?a?training?and?testing?set
#?將數據集拆分成四個部分
X_train?X_test?y_train?y_test?=?train_test_split(X?y?test_size=0.25)

###############################################################################
#?PCA降維方法,減少特征

評論

共有 條評論