Skip to content

Add pratical yield example in ML #167

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ Generator
* **Any function that contains a yield statement returns a generator.**
* **Generators and iterators are interchangeable.**


```python
def count(start, step):
while True:
Expand All @@ -238,6 +239,20 @@ def count(start, step):
(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
----
Expand Down