@@ -9,7 +9,7 @@ defmodule LearnKit.Knn.Classify do
99 quote do
1010 defp prediction ( data_set , options ) do
1111 data_set
12- |> filter_features_by_size ( Keyword . get ( options , :feature ) )
12+ |> filter_features_by_size ( options [ :feature ] )
1313 |> check_normalization ( options )
1414 |> calc_distances_for_features ( options )
1515 |> sort_distances ( )
@@ -29,7 +29,7 @@ defmodule LearnKit.Knn.Classify do
2929
3030 # normalize features
3131 defp check_normalization ( data_set , options ) do
32- type = Keyword . get ( options , :normalization )
32+ type = options [ :normalization ]
3333 case type do
3434 t when t in [ "minimax" , "z_normalization" ] -> normalize ( data_set , type )
3535 _ -> data_set
@@ -38,7 +38,7 @@ defmodule LearnKit.Knn.Classify do
3838
3939 # select algorithm for prediction
4040 defp calc_distances_for_features ( data_set , options ) do
41- case Keyword . get ( options , :algorithm ) do
41+ case options [ :algorithm ] do
4242 "brute" -> brute_algorithm ( data_set , options )
4343 _ -> [ ]
4444 end
@@ -51,7 +51,7 @@ defmodule LearnKit.Knn.Classify do
5151
5252 # take closest features
5353 defp select_closest_features ( features , options ) do
54- Enum . take ( features , Keyword . get ( options , :k ) )
54+ Enum . take ( features , options [ :k ] )
5555 end
5656
5757 # check existeness of current feature in data set
@@ -92,7 +92,7 @@ defmodule LearnKit.Knn.Classify do
9292
9393 defp calc_feature_weights ( features , options ) do
9494 Enum . map ( features , fn feature ->
95- Tuple . append ( feature , calc_feature_weight ( Keyword . get ( options , :weight ) , elem ( feature , 0 ) ) )
95+ Tuple . append ( feature , calc_feature_weight ( options [ :weight ] , elem ( feature , 0 ) ) )
9696 end )
9797 end
9898
@@ -106,14 +106,13 @@ defmodule LearnKit.Knn.Classify do
106106 defp brute_algorithm ( data_set , options ) do
107107 data_set
108108 |> Keyword . keys ( )
109- |> handle_features_in_label ( data_set , Keyword . get ( options , :feature ) )
109+ |> handle_features_in_label ( data_set , options [ :feature ] )
110110 |> List . flatten ( )
111111 end
112112
113113 defp handle_features_in_label ( keys , data_set , current_feature ) do
114114 Enum . map ( keys , fn key ->
115- data_set
116- |> Keyword . get ( key )
115+ data_set [ key ]
117116 |> calc_distances_in_label ( current_feature , key )
118117 end )
119118 end
@@ -152,7 +151,7 @@ defmodule LearnKit.Knn.Classify do
152151 end
153152
154153 defp accumulate_weight_of_labels ( [ { _ , key , weight } | tail ] , acc ) do
155- previous = if Keyword . has_key? ( acc , key ) , do: Keyword . get ( acc , key ) , else: 0
154+ previous = if Keyword . has_key? ( acc , key ) , do: acc [ key ] , else: 0
156155 acc = Keyword . put ( acc , key , previous + weight )
157156 accumulate_weight_of_labels ( tail , acc )
158157 end
0 commit comments