22
33Elixir package for machine learning
44
5- Available algorithms:
5+ Available algorithms for prediction:
6+
7+ - Linear Regression
8+
9+ Available algorithms for classification:
610
711- K-Nearest Neighbours
812- Gaussian Naive Bayes
@@ -20,21 +24,50 @@ def deps do
2024end
2125```
2226
27+ ### Linear Regression
28+
29+ Initialize predictor with data:
30+
31+ ``` elixir
32+ alias LearnKit .Regression .Linear
33+ predictor = Linear .new ([1 , 2 , 3 , 4 ], [3 , 6 , 10 , 15 ])
34+ ```
35+
36+ Fit data set:
37+
38+ ``` elixir
39+ predictor = predictor |> Linear .fit
40+ ```
41+
42+ Predict using the linear model:
43+
44+ ``` elixir
45+ predictor |> Linear .predict ([4 , 8 , 13 ])
46+ ```
47+ samples - array of variables, required
48+
49+ Returns the coefficient of determination R^2 of the prediction:
50+
51+ ``` elixir
52+ predictor |> Linear .score
53+ ```
54+
2355### K-Nearest Neighbours classification
2456
2557Initialize classificator with data set consists from labels and features:
2658
2759``` elixir
28- classificator = LearnKit .Knn .new
29- |> LearnKit .Knn .add_train_data ({:a1 , [- 1 , - 1 ]})
30- |> LearnKit .Knn .add_train_data ({:a1 , [- 2 , - 1 ]})
31- |> LearnKit .Knn .add_train_data ({:a2 , [1 , 1 ]})
60+ alias LearnKit .Knn
61+ classificator = Knn .new
62+ |> Knn .add_train_data ({:a1 , [- 1 , - 1 ]})
63+ |> Knn .add_train_data ({:a1 , [- 2 , - 1 ]})
64+ |> Knn .add_train_data ({:a2 , [1 , 1 ]})
3265```
3366
3467Predict label for new feature:
3568
3669``` elixir
37- LearnKit . Knn .classify (classificator, [feature: [- 1 , - 2 ], k: 3 , weight: " distance" ])
70+ Knn .classify (classificator, [feature: [- 1 , - 2 ], k: 3 , weight: " distance" ])
3871```
3972 feature - new feature for prediction, required
4073 k - number of nearest neighbors, optional, default - 3
@@ -46,36 +79,37 @@ Predict label for new feature:
4679Initialize classificator with data set consists from labels and features:
4780
4881``` elixir
49- classificator = LearnKit .NaiveBayes .Gaussian .new
50- |> LearnKit .NaiveBayes .Gaussian .add_train_data ({:a1 , [- 1 , - 1 ]})
51- |> LearnKit .NaiveBayes .Gaussian .add_train_data ({:a1 , [- 2 , - 1 ]})
52- |> LearnKit .NaiveBayes .Gaussian .add_train_data ({:a2 , [1 , 1 ]})
82+ alias LearnKit .NaiveBayes .Gaussian
83+ classificator = Gaussian .new
84+ |> Gaussian .add_train_data ({:a1 , [- 1 , - 1 ]})
85+ |> Gaussian .add_train_data ({:a1 , [- 2 , - 1 ]})
86+ |> Gaussian .add_train_data ({:a2 , [1 , 1 ]})
5387```
5488
55- Fit data set
89+ Fit data set:
5690
5791``` elixir
58- classificator = classificator |> LearnKit . NaiveBayes . Gaussian .fit
92+ classificator = classificator |> Gaussian .fit
5993```
6094
61- Return probability estimates for the feature
95+ Return probability estimates for the feature:
6296
6397``` elixir
64- classificator = classificator |> LearnKit . NaiveBayes . Gaussian .predict_proba ([1 , 2 ])
98+ classificator |> Gaussian .predict_proba ([1 , 2 ])
6599```
66100 feature - new feature for prediction, required
67101
68- Return exact prediction for the feature
102+ Return exact prediction for the feature:
69103
70104``` elixir
71- classificator = classificator |> LearnKit . NaiveBayes . Gaussian .predict ([1 , 2 ])
105+ classificator |> Gaussian .predict ([1 , 2 ])
72106```
73107 feature - new feature for prediction, required
74108
75- Returns the mean accuracy on the given test data and labels
109+ Returns the mean accuracy on the given test data and labels:
76110
77111``` elixir
78- classificator = classificator |> LearnKit . NaiveBayes . Gaussian .score
112+ classificator |> Gaussian .score
79113```
80114
81115## Contributing
0 commit comments