Professional Documents
Culture Documents
He Thcds
He Thcds
and Preprocessing
Extracting features from categorical
variables
Các biến phân loại thường được mã hóa bằng cách sử dụng mã hóa One – hot, hay
One – of - k, trong đó biến giải thích được mã hóa bằng một tính năng nhị phân cho
mỗi giá trị có thể của biến.
• PLAYING PLAY
• PLAYED PLAY
• PLAYS PLAY
from nltk.stem import PorterStemmer
from nltk.stem import LancasterStemmer
#create an object of class PorterStemmer
porter = PorterStemmer()
lancaster=LancasterStemmer()
word_list = ["friend", "friendship", "friends",
"friendships","stabil","destabilize","misunders
tanding",“goes","moonlight","football"]
print("{0:20}{1:20}{2:20}".format("Word","Porte
r Stemmer","lancaster Stemmer"))
for word in word_list:
print("{0:20}{1:20}{2:20}".format(word,porter.s
tem(word),lancaster.stem(word)))
LEMMATIZATION
Lemmatization: Sẽ xử lý thông minh hơn bằng
một bộ từ điển hoặc một bộ ontology nào đó
from nltk.stem.wordnet import WordNetLemmatizer
lemmatizer = WordNetLemmatizer()
print (lemmatizer.lemmatize('gathering', 'v'))
print (lemmatizer.lemmatize('gathering', 'n'))
from nltk.stem import WordNetLemmatizer
wordnet_lemmatizer = WordNetLemmatizer()
sentence_words
print("{0:20}{1:20}".format("Word","Lemma"))
for word in sentence_words:
print
Extending bag-of-words with TF- IDF weight
img = cv2.imread("book.jpg")
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sift = cv2.xfeatures2d.SIFT_create()
keypoints = sift.detect(img_gray, None)
cv2.drawKeypoints(img_gray, keypoints, img,
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEY
POINTS)
cv2.imwrite("img.jpg", img)
Cách tìm keypoint
• Bước đầu tiên là xác định vị trí cực đại và cực
tiểu gần đúng trên hình ảnh xám. Phép toán
sẽ lặp lại qua từng pixel và kiểm tra tất cả các
điểm lân cận của nó, kết quả là vị trí và tỉ lệ
mà tại đó điểm được tìm thấy. Việc kiểm tra
được thực hiện trên các hình ảnh tỉ lệ khác
nhau:
Cách tìm keypoint
• Bước thứ hai là tìm các điểm pixel phụ, điều này được
thực hiện bằng phép toán mở rộng hình ảnh xung
quanh điểm chính gần đúng. Keypoint vừa được tìm ở
bước 1 sẽ được xác minh lại với các điểm pixel phụ
này.
img = cv2.imread("book.jpg")
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sift = cv2.xfeatures2d.SIFT_create()
keypoints = sift.detect(img_gray, None)
cv2.drawKeypoints(img_gray, keypoints, img,
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv2.imwrite("img.jpg", img)