Guest User

Untitled

a guest
Jun 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using ScikitLearn
  2. @sk_import linear_model: LogisticRegression
  3.  
  4. struct Example
  5. featureVector::Array{Float64,1}
  6. outputVector::Array{Float64,1}
  7. end
  8.  
  9. Example(x1::Float64, x2::Float64, y::String) = Example(
  10. [1.0, (x1 - 50.0) / 50.0, (x2 - 50.0) / 50.0, ((x1 - 50.0) / 50.0)^2, ((x2 - 50.0) / 50.0)^2],
  11. if y == "red"
  12. [1.0, 0.0, 0.0]
  13. elseif y == "green"
  14. [0.0, 1.0, 0.0]
  15. elseif y == "blue"
  16. [0.0, 0.0, 1.0]
  17. end
  18. )
  19.  
  20. Example(x1::Int64, x2::Int64, y::String) = Example(Float64(x1), Float64(x2), y)
  21.  
  22. training_examples = [
  23. Example(6, 48, "red"),
  24. Example(8, 11, "red"),
  25. Example(15, 1, "red"),
  26. Example(16, 19, "red"),
  27. Example(22, 40, "red"),
  28. Example(25, 33, "red"),
  29. Example(30, 49, "red"),
  30. Example(31, 44, "red"),
  31. Example(32, 29, "red"),
  32. Example(38, 2, "red"),
  33. Example(53, 63, "green"),
  34. Example(50, 55, "green"),
  35. Example(90, 70, "green"),
  36. Example(69, 59, "green"),
  37. Example(76, 28, "green"),
  38. Example(86, 33, "green"),
  39. Example(51, 55, "green"),
  40. Example(88, 57, "green"),
  41. Example(85, 54, "green"),
  42. Example(60, 62, "green"),
  43. Example(14, 66, "blue"),
  44. Example(13, 76, "blue"),
  45. Example(40, 82, "blue"),
  46. Example(10, 98, "blue"),
  47. Example( 6, 51, "blue"),
  48. Example(47, 62, "blue"),
  49. Example(40, 85, "blue"),
  50. Example(11, 59, "blue"),
  51. Example(26, 95, "blue"),
  52. Example(20, 88, "blue")
  53. ]
  54. red = LogisticRegression()
  55. fit!(red, [ex.featureVector for ex in training_examples], [1 - ex.outputVector[1] for ex in training_examples])
  56. println("Red: $(join(["theta[$(i - 1)] = $(@sprintf("%0.2f", red[:coef_][i]))" for i = 1:length(red[:coef_])], ", "))")
  57. green = LogisticRegression()
  58. fit!(green, [ex.featureVector for ex in training_examples], [1 - ex.outputVector[2] for ex in training_examples])
  59. println("Green: $(join(["theta[$(i - 1)] = $(@sprintf("%0.2f", green[:coef_][i]))" for i = 1:length(green[:coef_])], ", "))")
  60. blue = LogisticRegression()
  61. fit!(blue, [ex.featureVector for ex in training_examples], [1 - ex.outputVector[3] for ex in training_examples])
  62. println("Blue: $(join(["theta[$(i - 1)] = $(@sprintf("%0.2f", blue[:coef_][i]))" for i = 1:length(blue[:coef_])], ", "))")
Add Comment
Please, Sign In to add comment