Browse Source

Add pratical yield example in ML

"Yield is practical for training machine learning models, while classifiers cannot train a large amount of data simultaneously."
pull/167/head
k66 1 year ago
committed by GitHub
parent
commit
bb2ce4b4e2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions
  1. 15
      README.md

15
README.md

@ -225,6 +225,7 @@ Generator
* **Any function that contains a yield statement returns a generator.** * **Any function that contains a yield statement returns a generator.**
* **Generators and iterators are interchangeable.** * **Generators and iterators are interchangeable.**
```python ```python
def count(start, step): def count(start, step):
while True: while True:
@ -238,6 +239,20 @@ def count(start, step):
(10, 12, 14) (10, 12, 14)
``` ```
* **`yield` is practical for training machine learning models, while classifiers cannot train a large amount of data simultaneously.**
```psuedo code
def train_func(x,y):
while True:
xt,yt,lx,ly=[],[],[],[]
for page in range(len(magizine)):
xt,yt=page,page_category
lx.append(xt)
ly.append(yt)
yield lx,ly
x_train,y_train,x_valid,y_valid=x[:8000],y[:8000],x[8000:],y[8000:]
classifier.fit_generator(train_func(x_train,y_train),epochs=10,validation_data=train_func(x_valid,y_valid))
```
Type Type
---- ----

Loading…
Cancel
Save