Skip to content

Commit e6caa2c

Browse files
Update README.md
1 parent 09b7b9e commit e6caa2c

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ lst_distances.sort() # All elements are sorted now by increasing
4545
result_1 = list(d.keys())[list(d.values()).index(lst_distances[0])]
4646
result_2 = list(d.keys())[list(d.values()).index(lst_distances[1])]
4747

48-
print(result_1, result_2) # number of closest sentences
48+
print(result_1, result_2) # Number of closest sentences
4949
print(d)
5050

5151
```
@@ -58,9 +58,42 @@ Then, two closest sentences to the 0-numbered sentence were found as a result.
5858
Full code is available here: [Processing_Sentences.py](https://github.com/sichkar-valentyn/Machine_Learning_in_Python/tree/master/Codes/Processing_Sentences.py)
5959

6060
### <a name="Approximation of functions via linear equations">Approximation of functions via linear equations</a>
61+
Implementing the task for approximation of function with linear equations. Using first degree polynomial, second degree polynomial and third degree polynomial. Solving equations with matrix method via 'numpy.linalg.solve(a, b)' function.
62+
63+
Initial function is as following:
64+
<br/>**f(x) = sin(x / 5) * exp(x / 10) + 5 * exp(-x / 2)**
65+
66+
Points for first degree polynomials are: **1, 15**
67+
<br/>Points for second degree polynomials are: **1, 8, 15**
68+
<br/>Points for third degree polynomials are: **1, 4, 10, 15**
69+
70+
<br/><br/>Part of the code is shown below with a lot of comments:
71+
72+
```py
73+
import numpy as np
74+
75+
76+
# Creating first degree polynomials in the points of 1 and 15
77+
# It has to be in following form:
78+
# w_0 + w_1 * x_1 = y_1
79+
# w_0 + w_1 * x_2 = y_2
80+
# Writing systems of equations into two-dimensional array 'a' and vector 'b'
81+
a = np.array([[1, 1], [1, 15]])
82+
b = np.array([f(1), f(15)]) # [3.25221687 0.63522142]
83+
84+
# Solving system of linear equations for first degree polynomial
85+
w = np.linalg.solve(a, b) # [ 3.43914511 -0.18692825]
86+
# Found equation for the first degree polynomial is as following:
87+
# y = w[0] + w[1] * x
88+
89+
```
90+
91+
Results are plot in order to understand the quality of approximation in eche case. Figure is shown below
6192

6293
![RGB_channels](images/RGB_channels.png)
6394

95+
Full code is available here: [Function_approximation.py](https://github.com/sichkar-valentyn/Machine_Learning_in_Python/tree/master/Codes/Function_approximation.py)
96+
6497
<br/>
6598

6699
### MIT License

0 commit comments

Comments
 (0)