Skip to content

Commit ea74439

Browse files
committed
update readme, release 0.1.5
1 parent dc6198f commit ea74439

5 files changed

Lines changed: 68 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## [0.1.5] - 2018-12-18
88
### Added
99
- preprocessing normalization for data set
1010
- normalize train data for Gaussian NB

README.md

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Elixir package for machine learning
44

5+
Available preprocessing methods:
6+
7+
- Normalization
8+
59
Available 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
2024
def deps do
2125
[
22-
{:learn_kit, "~> 0.1.4"}
26+
{:learn_kit, "~> 0.1.5"}
2327
]
2428
end
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

2963
Initialize 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

73108
Predict 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

85121
Initialize 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

95139
Fit data set:
96140

lib/learn_kit/naive_bayes/gaussian/classify.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule LearnKit.NaiveBayes.Gaussian.Classify do
22
@moduledoc """
33
Module for prediction functions
44
"""
5+
56
defmacro __using__(_opts) do
67
quote do
78
# classify data

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule LearnKit.MixProject do
88
def project do
99
[
1010
app: :learn_kit,
11-
version: "0.1.4",
11+
version: "0.1.5",
1212
elixir: "~> 1.7",
1313
name: "LearnKit",
1414
description: @description,

test/learn_kit/naive_bayes/gaussian_test.exs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ defmodule LearnKit.NaiveBayes.GaussianTest do
44
alias LearnKit.NaiveBayes.Gaussian
55

66
setup_all do
7-
{:ok, classificator: Gaussian.new([{:label1, [[-1, -1], [-2, -1], [-3, -2]]}, {:label2, [[1, 1], [2, 1], [3, 2], [-2, -2]]}])}
7+
{:ok, classifier: Gaussian.new([{:label1, [[-1, -1], [-2, -1], [-3, -2]]}, {:label2, [[1, 1], [2, 1], [3, 2], [-2, -2]]}])}
88
end
99

10-
test "create new knn classificator with empty data set" do
10+
test "create new knn classifier with empty data set" do
1111
assert %Gaussian{data_set: data_set} = Gaussian.new
1212

1313
assert data_set == []
1414
end
1515

16-
test "add train data to classificator" do
16+
test "add train data to classifier" do
1717
%Gaussian{data_set: data_set} =
1818
Gaussian.new
1919
|> Gaussian.add_train_data({:a1, [1, 2]})
@@ -24,7 +24,7 @@ defmodule LearnKit.NaiveBayes.GaussianTest do
2424
end
2525

2626
test "normalize data set", state do
27-
%Gaussian{data_set: data_set} = state[:classificator] |> Gaussian.normalize_train_data("minimax")
27+
%Gaussian{data_set: data_set} = state[:classifier] |> Gaussian.normalize_train_data("minimax")
2828

2929
assert data_set ==
3030
[
@@ -34,7 +34,7 @@ defmodule LearnKit.NaiveBayes.GaussianTest do
3434
end
3535

3636
test "fit data set", state do
37-
%Gaussian{fit_data: fit_data} = state[:classificator] |> Gaussian.fit
37+
%Gaussian{fit_data: fit_data} = state[:classifier] |> Gaussian.fit
3838

3939
assert fit_data ==
4040
[
@@ -50,23 +50,23 @@ defmodule LearnKit.NaiveBayes.GaussianTest do
5050
end
5151

5252
test "return probability estimates for the feature", state do
53-
classificator = state[:classificator] |> Gaussian.fit
53+
classifier = state[:classifier] |> Gaussian.fit
5454

55-
assert {:ok, result} = classificator |> Gaussian.predict_proba([1, 2])
55+
assert {:ok, result} = classifier |> Gaussian.predict_proba([1, 2])
5656
assert result == [label1: 0.0, label2: 0.017199571]
5757
end
5858

5959
test "return exact prediction for the feature", state do
60-
classificator = state[:classificator] |> Gaussian.fit
60+
classifier = state[:classifier] |> Gaussian.fit
6161

62-
assert {:ok, result} = classificator |> Gaussian.predict([1, 2])
62+
assert {:ok, result} = classifier |> Gaussian.predict([1, 2])
6363
assert result == {:label2, 0.017199571}
6464
end
6565

6666
test "returns the mean accuracy on the given test data and labels", state do
67-
classificator = state[:classificator] |> Gaussian.fit
67+
classifier = state[:classifier] |> Gaussian.fit
6868

69-
assert {:ok, result} = classificator |> Gaussian.score
69+
assert {:ok, result} = classifier |> Gaussian.score
7070
assert result == 0.857143
7171
end
7272
end

0 commit comments

Comments
 (0)