22
33Elixir package for machine learning
44
5+ Available preprocessing methods:
6+
7+ - Normalization
8+
59Available algorithms for prediction:
610
711- Linear Regression
@@ -19,11 +23,41 @@ by adding `learn_kit` to your list of dependencies in `mix.exs`:
1923``` elixir
2024def deps do
2125 [
22- {:learn_kit , " ~> 0.1.4 " }
26+ {:learn_kit , " ~> 0.1.5 " }
2327 ]
2428end
2529```
2630
31+ ### Normalization
32+
33+ Normalize data set with minimax normalization
34+
35+ ``` elixir
36+ alias LearnKit .Preprocessing
37+ Preprocessing .normalize ([[1 , 2 ], [3 , 4 ], [5 , 6 ]])
38+ ```
39+
40+ Or normalize data set with selected type
41+
42+ ``` elixir
43+ Preprocessing .normalize ([[1 , 2 ], [3 , 4 ], [5 , 6 ]], [type: " z_normalization" ])
44+ ```
45+ options - array of options
46+
47+ Additionally you can prepare coefficients for normalization
48+
49+ ``` elixir
50+ Preprocessing .coefficients ([[1 , 2 ], [3 , 4 ], [5 , 6 ]], " minimax" )
51+ ```
52+ type - method of normalization, one of the [minimax|z_normalization], required
53+
54+ And then normalize 1 feature with predefined coefficients
55+
56+ ``` elixir
57+ Preprocessing .normalize_feature ([1 , 2 ], [{1 , 5 }, {2 , 6 }], " minimax" )
58+ ```
59+ type - method of normalization, one of the [minimax|z_normalization], required
60+
2761### Linear Regression
2862
2963Initialize predictor with data:
@@ -64,33 +98,43 @@ Initialize classifier with data set consists from labels and features:
6498
6599``` elixir
66100 alias LearnKit .Knn
67- classifier = Knn .new
68- |> Knn .add_train_data ({:a1 , [- 1 , - 1 ]})
69- |> Knn .add_train_data ({:a1 , [- 2 , - 1 ]})
70- |> Knn .add_train_data ({:a2 , [1 , 1 ]})
101+ classifier =
102+ Knn .new
103+ |> Knn .add_train_data ({:a1 , [- 1 , - 1 ]})
104+ |> Knn .add_train_data ({:a1 , [- 2 , - 1 ]})
105+ |> Knn .add_train_data ({:a2 , [1 , 1 ]})
71106```
72107
73108Predict label for new feature:
74109
75110``` elixir
76- Knn .classify (classifier, [feature: [- 1 , - 2 ], k: 3 , weight: " distance" ])
111+ Knn .classify (classifier, [feature: [- 1 , - 2 ], k: 3 , weight: " distance" , normalization: " minimax " ])
77112```
78113 feature - new feature for prediction, required
79114 k - number of nearest neighbors, optional, default - 3
80115 algorithm - algorithm for calculation of distances, one of the [brute], optional, default - "brute"
81116 weight - method of weighted neighbors, one of the [uniform|distance], optional, default - "uniform"
117+ normalization - method of normalization, one of the [none|minimax|z_normalization], optional, default - "none"
82118
83119### Gaussian Naive Bayes classification
84120
85121Initialize classifier with data set consists from labels and features:
86122
87123``` elixir
88124 alias LearnKit .NaiveBayes .Gaussian
89- classifier = Gaussian .new
90- |> Gaussian .add_train_data ({:a1 , [- 1 , - 1 ]})
91- |> Gaussian .add_train_data ({:a1 , [- 2 , - 1 ]})
92- |> Gaussian .add_train_data ({:a2 , [1 , 1 ]})
125+ classifier =
126+ Gaussian .new
127+ |> Gaussian .add_train_data ({:a1 , [- 1 , - 1 ]})
128+ |> Gaussian .add_train_data ({:a1 , [- 2 , - 1 ]})
129+ |> Gaussian .add_train_data ({:a2 , [1 , 1 ]})
130+ ```
131+
132+ Normalize data set:
133+
134+ ``` elixir
135+ classifier = classifier |> Gaussian .normalize_train_data (" minimax" )
93136```
137+ type - method of normalization, one of the [none|minimax|z_normalization], optional, default - "none"
94138
95139Fit data set:
96140
0 commit comments