How to implement KNN from scratch with Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ม.ค. 2025

ความคิดเห็น • 72

  • @nizamuddinshaikh3185
    @nizamuddinshaikh3185 ปีที่แล้ว +10

    Implementing KNN is so easy? That was my first thought after I saw this video. Really the way, it is explained and shown here is remarkable. It not only shows KKN but also how powerful is plain Python when used sensibly with library like Numpy. The entire idea is very useful for beginners like me. I am now AssemlyAI subscriber. I am going to not only see but follow along all videos of this playlist in order to get better understanding of Python, Numpy, Pandas and DataScience. Thank you AssemblyAI for sharing.

  • @afizs
    @afizs 2 ปีที่แล้ว +36

    Short and simple. I like the way you explained the KNN in simple words.

  • @l4dybu9
    @l4dybu9 2 ปีที่แล้ว +12

    This is the best series to learn ML.
    🎓🔥🔥
    Imma recommend it to all my ml enthusiast friends ✌🏻

  • @zeenathkatta7480
    @zeenathkatta7480 หลายเดือนก่อน

    Awesome , Without using predefined functions from knn and using just distance formula, explained very well.

  • @Brandonator24
    @Brandonator24 3 หลายเดือนก่อน +2

    fun fact, for the distance between points in KNN, you can omit the square root portion of the euclidean distance function for efficiency. Square root function is monotonic, so it if a < b then sqrt(a) is also < sqrt(b).

    • @redwar7253
      @redwar7253 9 วันที่ผ่านมา

      I found this
      "While k-means often uses squared distances internally for computational efficiency"

  • @bakhtiarrasheed9952
    @bakhtiarrasheed9952 2 ปีที่แล้ว +1

    Great tutorial, I also added tie-breaking functionality in case tie occurs in most frequent label.

  • @semrana1986
    @semrana1986 5 หลายเดือนก่อน

    wonderfully done with a lot of clarity

  • @philtrem
    @philtrem ปีที่แล้ว +6

    Very easy to follow after I created my own implementation. Very similar to my own implementation, except I elected to use a priority queue to keep track of the k nearest, instead of sort (because having to keep track of indices was a pain, and it was getting late). Coded mine in C# without third party libraries. I like that numpy offers a argsort method here, comes in handy.

  • @emir5146
    @emir5146 11 หลายเดือนก่อน +2

    I don't understand that why we add terms that '[0][0]' to the list of most_commons? 8:04

    • @stanvanillo9831
      @stanvanillo9831 11 หลายเดือนก่อน +1

      The counter returns the sorted count of all possible outcomes, i.e. a list of tuples and each tuples has the label and the count, (label, count). You only want the most common one, i.e. the first element in the array and you only want the label, not the count, i.e. you want the first element of that tuple which is also accessed by using [0]. Therefore you need to apply [0][0].

  • @johanriedel
    @johanriedel 2 ปีที่แล้ว +9

    The free course is appreciated, but I have trouble understanding some of the terms and the thoughts behind certain functions.

  • @mbmathematicsacademic7038
    @mbmathematicsacademic7038 8 หลายเดือนก่อน

    short and simple ,no complications

  • @IgorKuts
    @IgorKuts ปีที่แล้ว +1

    Nice and concise. Love it.

  • @OmarAmil
    @OmarAmil ปีที่แล้ว +2

    Short and simple, Thank you very much

    • @AssemblyAI
      @AssemblyAI  ปีที่แล้ว

      You're very welcome!

  • @cherpysara
    @cherpysara ปีที่แล้ว +1

    I am getting error no module NAMED KNN .... pl help to resolve this problem.

  • @takasurazeem
    @takasurazeem ปีที่แล้ว +1

    How can I plot the graph again to see if it turned those blues into the green?

  • @luis96xd
    @luis96xd 2 ปีที่แล้ว +1

    Whoa, excellent video! It was well explained, thanks! 😁😁👍🤩

    • @AssemblyAI
      @AssemblyAI  2 ปีที่แล้ว +1

      You're very welcome :)

  • @mrarsenal10vn
    @mrarsenal10vn ปีที่แล้ว +1

    I love this tutorial so much

  • @sedwares
    @sedwares ปีที่แล้ว +1

    Great video!

    • @AssemblyAI
      @AssemblyAI  ปีที่แล้ว

      Glad you enjoyed it

  • @Franshpsv
    @Franshpsv ปีที่แล้ว +1

    I like to follow this course from Lesson 1, what is the link that i need to start here?

  • @tejasrathi635
    @tejasrathi635 11 หลายเดือนก่อน

    How did you visualised the data ?

  • @imadsaddik
    @imadsaddik ปีที่แล้ว +1

    Thank you for sharing

    • @AssemblyAI
      @AssemblyAI  ปีที่แล้ว

      Thanks for watching!

  • @andrea-mj9ce
    @andrea-mj9ce 2 ปีที่แล้ว +5

    What about the regression case?

    • @KarthickKenny.
      @KarthickKenny. ปีที่แล้ว

      There is no regression in knn it is a classification algorithm

    • @andrea-mj9ce
      @andrea-mj9ce ปีที่แล้ว

      @KarthickKenny. One can apply KNN when the response variable is continuous

    • @KarthickKenny.
      @KarthickKenny. ปีที่แล้ว

      @@andrea-mj9ce you have to apply regression algorithm in that case not knn

  • @emir5146
    @emir5146 11 หลายเดือนก่อน +1

    Thank you abla

  • @esmailsayid2976
    @esmailsayid2976 ปีที่แล้ว

    amazing job

  • @urielcalderon1661
    @urielcalderon1661 2 ปีที่แล้ว +2

    Thank you

    • @AssemblyAI
      @AssemblyAI  2 ปีที่แล้ว +1

      You're very welcome :)

  • @alexandergarzo9415
    @alexandergarzo9415 2 ปีที่แล้ว +8

    Please explain in more detail every line code.

  • @youssefelamrani7905
    @youssefelamrani7905 2 ปีที่แล้ว +1

    good job, I like it, KNN doesn't well with images i believe right?

  • @derickkwame6148
    @derickkwame6148 ปีที่แล้ว

    great simple tutorial but how do i plot a graph with the knn?

  • @1000marcelo1000
    @1000marcelo1000 2 ปีที่แล้ว

    Amazing!

  • @Code_Catalysts
    @Code_Catalysts ปีที่แล้ว

    numpy error in vscode???

  • @abheermehrotra329
    @abheermehrotra329 ปีที่แล้ว

    how to setup my machine with all these libraries ???

  • @SantiagoGomezVideos
    @SantiagoGomezVideos 2 ปีที่แล้ว

    Great video! Thnk you for making it.
    Got this error in Colab. ModuleNotFoundError: No module named 'KNN' when running from KNN import KNN

    • @AssemblyAI
      @AssemblyAI  2 ปีที่แล้ว

      You're welcome Santiago! You should include the KNN python file we develop in the video in the file system of the collab notebook. That should get rid of the error! :)

  • @FearFlicks-ue6ex
    @FearFlicks-ue6ex 3 หลายเดือนก่อน +3

    There is no teacher on this planet that can explain python, machine learning in a proper sequence and an entertaining way. I don't know what is she doing in this video. Also, she is not explaining whatever she is typing all that Chinese stuff.

  • @youssefzaim7163
    @youssefzaim7163 ปีที่แล้ว

    great excahnge ndiro niya

  • @ge_song5
    @ge_song5 6 หลายเดือนก่อน

    wow, she knows her stuff.

  • @AbdellahEnajari
    @AbdellahEnajari 2 หลายเดือนก่อน

    👌👌👍👍👍👍

  • @systemforge
    @systemforge 2 ปีที่แล้ว

    nice

  • @tebibusolomon1529
    @tebibusolomon1529 5 หลายเดือนก่อน

    i love you

  • @orioncloud4697
    @orioncloud4697 2 ปีที่แล้ว

    Thx, however, this euclidean distance function needs to be corrected.

    • @osviiii
      @osviiii 2 ปีที่แล้ว

      It's actually ok I'd say

    • @orioncloud4697
      @orioncloud4697 2 ปีที่แล้ว

      @@osviiii yeap i checked that, i just confused a little

  • @lalalalaal7209
    @lalalalaal7209 2 ปีที่แล้ว

    Are you Turkish

    • @AssemblyAI
      @AssemblyAI  2 ปีที่แล้ว

      Yes!

    • @dostseferoglu6853
      @dostseferoglu6853 ปีที่แล้ว

      @@AssemblyAI that "i" in range pronounciation gave it away :D

  • @firstlast-wz9jv
    @firstlast-wz9jv 2 ปีที่แล้ว +1

    thank you for the practice... but it's an exact copy from this one th-cam.com/video/ngLyX54e1LU/w-d-xo.html created 4 years ago

    • @AssemblyAI
      @AssemblyAI  ปีที่แล้ว +2

      Yes! Pat works with me too, we decided to do a new run of his videos :)

  • @sidekick3rida
    @sidekick3rida ปีที่แล้ว +1

    How to implement knn from scratch… import numpy and sklearn ¯\_(ツ)_/¯

    • @redwar7253
      @redwar7253 9 วันที่ผ่านมา

      you know numpy was used to calculate sqrt and sort in the eucledian distance and argsort to get the indexes of the k smallest distances
      from sklearn we imported datasets to use the iris dataset and train_test_split to split our dataset to the train part and the test one
      using knn directly equals using
      from sklearn.neighbors import KNeighborsClassifier
      no class implementation just a call

  • @KemalDirican-f2o
    @KemalDirican-f2o 4 หลายเดือนก่อน

    Lewis Brenda Walker James Jackson Charles

  • @GeorgeZoto
    @GeorgeZoto 2 ปีที่แล้ว

    I like this approach, it is so helpful. Curious how it compares with sklearn's version of sklearn.neighbors.KNeighborsClassifier 😃

    • @michaelduffy5309
      @michaelduffy5309 ปีที่แล้ว

      I went through all of these Assembly AI lessons, making each one work perfectly. Then I redid each one using Scikit Learn classes. In every case, I was able to drop in the sklearn equivalent and get the same or better results. A good entree into Scikit Learn.