Skip to content

Commit

Permalink
minor clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tiepvupsu committed Feb 11, 2017
1 parent df3172d commit b77e33c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions _plugins/star_rating.filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module StarRatingFilter

# Location of the star images from root of website
Star_imagesLoc = "/images"

# The format of the img tag used by % method
Star_imageTag = "<img src=\"#{Star_imagesLoc}/%s\" alt=\"%s\" />"

# Displays the rating as a series of stars
def star_rating(rating)

wholeStars = rating.floor
wholeStars += 1 if (rating - wholeStars > 0.5)

halfStar = (rating - wholeStars == 0.5 ? 1 : 0)
clearStars = 5 - (wholeStars + halfStar)

ratingAltText = "%.1f/5.0" % [rating]

htmlOutput = String.new
wholeStars.times do
htmlOutput += Star_imageTag % ["star_filled.png", "#{ratingAltText}"]
ratingAltText = ""
end

if (halfStar == 1)
htmlOutput += Star_imageTag % ["star_half.png", "#{ratingAltText}"]
ratingAltText = ""
end

clearStars.times do
htmlOutput += Star_imageTag % ["star_clear.png", "#{ratingAltText}"]
ratingAltText = ""
end

return htmlOutput
end

end

Liquid::Template.register_filter(StarRatingFilter)
2 changes: 1 addition & 1 deletion _posts/2017-02-11-binaryclassifiers.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ summary: Áp dụng Logistic Regression vào một vài bài toán và mở rộ
Cho tới bây giờ, ngoài _thuật toán lười_ [K-nearest neighbors](/2017/01/08/knn/), tôi đã giới thiệu với bạn đọc hai thuật toán cho các bài toán Classification: [Perceptron Learning Algorithm](/2017/01/21/perceptron/)[Logistic Regression](/2017/01/27/logisticregression/). Hai thuật toán này được xếp vào loại Binary Classifiers vì chúng được xây dựng dựa trên ý tưởng về các bài toán classification với chỉ hai classes. Trong bài viết này, tôi sẽ cùng các bạn làm một vài ví dụ nhỏ về ứng dụng đơn giản (nhưng thú vị) của các binary classifiers, và cách mở rộng chúng để áp dụng cho các bài toán với nhiều classes (multi-class classification problems).


Vì Logistic Regression chỉ yêu cầu các classes là [_ nearly linearly separable_](/2017/01/21/perceptron/#bai-toan-perceptron) (tức có thể có vài điểm làm phá vỡ tính linear separability), tôi sẽ sử dụng Logistic Regression để đại diện cho các binary classifiers. _Chú ý rằng, có rất nhiều các thuật toán cho binary classification nữa mà tôi chưa giới thiệu. Tạm thời, với những gì đã viết, tôi chỉ sử dụng Logistic Regression cho các ví dụ với code mẫu. Các kỹ thuật trong bài viết này hoàn toàn có thể áp dụng cho các binary classifiers khác._
Vì Logistic Regression chỉ yêu cầu các classes là [_nearly linearly separable_](/2017/01/21/perceptron/#bai-toan-perceptron) (tức có thể có vài điểm làm phá vỡ tính linear separability), tôi sẽ sử dụng Logistic Regression để đại diện cho các binary classifiers. _Chú ý rằng, có rất nhiều các thuật toán cho binary classification nữa mà tôi chưa giới thiệu. Tạm thời, với những gì đã viết, tôi chỉ sử dụng Logistic Regression cho các ví dụ với code mẫu. Các kỹ thuật trong bài viết này hoàn toàn có thể áp dụng cho các binary classifiers khác._


**Trong trang này:**
Expand Down
Binary file added images/star_clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/star_filled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/star_half.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b77e33c

Please sign in to comment.