Genetic Algorithm from Scratch in Python (tutorial with code)

preview_player
Показать описание

This video is part two of my series on genetic algorithms. In last week's video, we looked at how a genetic algorithm works and I have explained by example the theory behind it and its different applications and I highly recommend watching this video first.

In this week's tutorial, we will implement our first example of a genetic algorithm to solve the knapsack problem discussed last week in python. We won't use any libraries but write everything from scratch.

Happy Coding!

Follow me here:

Timestamps:
00:00 Intro
00:17 Genome
01:25 Fitness function
02:26 Data for the example
02:43 Selection function
04:00 Crossover function
04:50 Mutation function
05:55 Evolutionary main loop
09:17 Implementing the example from last week's tutorial

---

This video contains advertising content.

---

#python #machinelearning #geneticalgorithms
Рекомендации по теме
Комментарии
Автор

I have learned a *ton* from this video, but the biggest thing I've learned is about good practices with type hinting and software architecture. The way this is laid out is brilliant. If this is how everyone in the software industry codes, I am way behind, however I've never seen anyone else do it this way in formal courses or other videos. I first watched this months ago and I genuinely believe I have vastly improved as a programmer as a direct result. You should make more videos... about just anything. I guarantee people will learn a ton, regardless of what you're actually trying to teach

msubookstoreitsupport
Автор

Yoooo this video is SO well made! As well as the first part, just great explanations, visuals/animations, and a clear rundown of the code you're writing. SO GOOD!

jackhoefnagel
Автор

Hey, cool video. In 5:16 you can also use "else 1 - genome[index]". This will also flip the bit (or just xor it with 1).

polu
Автор

Editing skills on point !!! Referring to the previous videos totally makes sense and makes the video more interactive.

o.rudyemonvuon
Автор

Disappointed to see you haven't made other videos on similar topics! I loved both this and the first video on GA. Would be super interested in topics such as Simulated Annealing, Tabu Search and Evolutionary Strategies
!

seb
Автор

I'm so glad I found your channel. I can't believe you don't have more views- your production quality is fantastic and it is apparent you are putting a lot of time into each video. Keep up the great work!

tyleraldous
Автор

wow. glad I ran in to you. you're videos are great! fast, to the point, informative, and a wee bit funny. sub earned, for sho!

ronboprime
Автор

I am very grateful, both of your videos about genetic algorithms really helped me to approve my exam.
Keep it up!

AdrianSP
Автор

Just started my GA classes and this video helped me a lot! It was short, concise and very clear. Thank you for the content ♥

barbi
Автор

too good my man, i have seen other youtubers use genetic algorithms, and after like a year i can finnally make my own

TYSM

crypto
Автор

You're a literal life saver! I'll be citing your videos on my uni project!

TheCzarsoham
Автор

Thank you, Great Work! I'm new into evolutionary algorithms and I hope It gets easier for me to write such code as I do have some problem solving skills.

Entertainment-pe
Автор

Hi kie codes,
First of all, I really like your explanation of Genetic Algorithms. The things that you could improve however are the code sections. You could turn off autocorrection in you editor as it just clobbers the view of the code. Also, although the type hinting in your code does makes it more readable for seasoned python programmers, it only confuses beginners. Because the video is about Genetic Algorithms and not about type hinting, I think the cons outweigh the pros. Finally, I can follow the high level explanation of the algorithm (other video), but the code parts go to fast in my case. I hope this helps.

wouterr
Автор

Good video, but this goes way too fast. This is supposed to be a 20-30 minute video, but you sped it and talk way too fast. I have been programming in Python for about 3 years, and I learned more about the nitty gritty type hinting functions and Callables than I did about genetic algorithms. Not to nitpick, but since the topic is genetic algorithms, it'd be best if you didn't use all these nitty gritty details from Python. Nonetheless, good video. But just letting you know I had to watch this video twice in 0.75x speed to understand what you were doing.

mihirshrestha
Автор

Dude your content is really great and super high-quality and very easy to follow I 100% feel like you should definitely have more a following and I know that pretty soon you're gonna blow up, glad I'm here to see it

Human_A
Автор

Thanks for the video! I recently found about the genetic algorithm and this video helped me understand it better. An alternative to that parte of abs(genome[ idx ]-1) is ( genome[ idx ]+1)%2.

pedroribeiro
Автор

So well done! Clean, clear and teaches a lot (both for the GA and python code/style). Nailed it! Thank you for the content.

lucacoraggio
Автор

Kie, i think some uf us would need a tutorial on Callables after this video :D

dejan
Автор

Thank you!! I had an assignment related to genetic algorithms and this is the best example I have seen for begginers:)

weronikaprawda
Автор

thanks, this tutorial is awesome. I coded along, but in typeScript. I am very glad that I now have a better understanding of generic algorithms. I would kind of name the approach in this video "directed brute force"

tobiasnickel