Machine Learning Tutorial Python – 10 Support Vector Machine (SVM)




[ad_1]

Support vector machine is a popular classification algorithm. This tutorial covers some theory first and then goes over python coding to solve iris flower classification problem using svm and sklearn library. We also cover different parameters such as gamma, regularization and how to fine tune svm classifier using these parameters. Basically the way support vector machine works is it draws a hyper plane in n dimension space such that it maximizes the margin between classification groups.

#MachineLearning #PythonMachineLearning #MachineLearningTutorial #Python #PythonTutorial #PythonTraining #MachineLearningCource #SupportVectorMachine #SVM

Code: https://github.com/codebasics/py/blob/master/ML/10_svm/10_svm.ipynb

Exercise: Open above notebook from github and go to the end.

Exercise solution: https://github.com/codebasics/py/blob/master/ML/10_svm/Exercise/10_svm_exercise_digits.ipynb

Topics that are covered in this Video:
0:20 Theory (Explain support vector machine using sklearn iris dataset flower classification problem)
3:11 What is Gamma?
4:21 What is Regularization?
5:27 Kernel
6:32 Coding (Start)
18:08 sklearn.svm SVC
21:41 Exercise (Classify hand written digits dataset from sklearn using SVM)

Next Video:
Machine Learning Tutorial Python – 11 Random Forest: https://www.youtube.com/watch?v=ok2s1vV9XW0&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw&index=12

Populor Playlist:
Data Science Full Course: https://www.youtube.com/playlist?list=PLeo1K3hjS3us_ELKYSj_Fth2tIEkdKXvV

Data Science Project: https://www.youtube.com/watch?v=rdfbcdP75KI&list=PLeo1K3hjS3uu7clOTtwsp94PcHbzqpAdg

Machine learning tutorials: https://www.youtube.com/watch?v=gmvvaobm7eQ&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw

Pandas: https://www.youtube.com/watch?v=CmorAWRsCAw&list=PLeo1K3hjS3uuASpe-1LjfG5f14Bnozjwy

matplotlib: https://www.youtube.com/watch?v=qqwf4Vuj8oM&list=PLeo1K3hjS3uu4Lr8_kro2AqaO6CFYgKOl

Python: https://www.youtube.com/watch?v=eykoKxsYtow&list=PLeo1K3hjS3uv5U-Lmlnucd7gqF-3ehIh0&index=1

Jupyter Notebook: https://www.youtube.com/watch?v=q_BzsPxwLOE&list=PLeo1K3hjS3uuZPwzACannnFSn9qHn8to8

To download csv and code for all tutorials: go to https://github.com/codebasics/py, click on a green button to clone or download the entire repository and then go to relevant folder to get access to that specific file.

Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub

Source


[ad_2]

Comment List

  • codebasics
    November 26, 2020

    How can I draw the predicted line in the classification graph? Suggest me an idea sir. How to view the decision line?

  • codebasics
    November 26, 2020

    rbf_model.score(X_train, y_train)=0.9944328462073765
    model_g = SVC(gamma=10)=0.08888888888888889
    model_linear_kernal.score(X_test, y_test)=0.9777777777777777

  • codebasics
    November 26, 2020

    when I try to do the model.fit function I have this error :
    check_array() got an unexpected keyword argument 'warn_on_dtype'

    I don't understand how to fix it

  • codebasics
    November 26, 2020

    Suggestion for your videos: Increase the sound volume. Because every videos you have, has very small sound. Every time ads comes out I had to decrease the sound and that back it up again after that. So annoying Brooo

  • codebasics
    November 26, 2020

    thanks, it's a very good tutorial :D. but how can you decide on which parameters works the best for your dataset (most optimal sets of parameters)..

  • codebasics
    November 26, 2020
  • codebasics
    November 26, 2020

    Thankyou so much for the wonderful job!!

  • codebasics
    November 26, 2020

    A very solid, informative yet concise tutorial. Excellent. Please keep it up.

  • codebasics
    November 26, 2020

    why we have not applied feature scaling here?

  • codebasics
    November 26, 2020

    Sir i tried iris data set with SVC default values, i got 1 accuracy. Digits data set with SVM(kernel='linear') gave 96% accuracy.

  • codebasics
    November 26, 2020

    Thanks so much for the detailed video on SVM. This helped me a lot!

  • codebasics
    November 26, 2020

    I was looking for python code to SVM… Thanks a lot… this was a great help… very clean and intuitive lecture~!

  • codebasics
    November 26, 2020

    I am unable to view the parameter after the command model.fit, can anyone help with that?

  • codebasics
    November 26, 2020

    Sir cannot we do this without the library means mathematicaly using cost function and gradient

  • codebasics
    November 26, 2020

    Sir, i got 99.4% accuracy using SVM kernel= 'rbf', c=1.

  • codebasics
    November 26, 2020

    Hello sir, thank you for your videos. It really helps from the beginner of the video which you have listed in data science playlist. 😄
    The model in default method is 99.65% in train and 99.4% in test. Whereas gamma method will lower down the accuracy of the model from 99.4% to 75% therefore it has explicit shows the gamma method is unsuitable for the scenario however the regularisation has improve the train set to 1 and testing set is retained the best accuracy of model.
    Yet, kernel parameter as linear has also provided a good accuracy of model.
    Thank you for your guidance.

  • codebasics
    November 26, 2020

    pardon plz…will it try to maximize, minimize or find an optimal margin?

  • codebasics
    November 26, 2020

    I am liking the tutorials Thanks

  • codebasics
    November 26, 2020

    With C = 1 , gamma = 'scale' , kernel = 'rbf' , I got a score of 98.89

  • codebasics
    November 26, 2020

    i tried the handwritten digits recognition with SVM with 80:20 ratio for training and testing. it gave me minimum 98.5% score and a maximum of 99.44444444444445% with C=1,kernel='rbf'. I think the default configuration is better as it is giving score of 99.4%.
    If u guys got more accuracy while adding more configuration pls reply to me!

  • codebasics
    November 26, 2020

    Good explanation! please share the code to email: sujalbhagat97@gmail.com

  • codebasics
    November 26, 2020

    Hello,
    When i fit my Model, it doesnt Show me automaticly the parameters. How can i change that?✌🏽

  • codebasics
    November 26, 2020

    0.9944444444444445
    model = SVC(C=3,gamma='scale',kernel='rbf')

  • codebasics
    November 26, 2020

    when c=10, i got accuracy 0f 1.0 why???

  • codebasics
    November 26, 2020

    Thanks for your effort sir, but there is something I wonder.. When I fit a model, I can't see any description like you have in your jupyter notebook.(C=1, cache_size=200 etc..) I can't see them.. is there any way to see them?

  • codebasics
    November 26, 2020

    got a score of 99.16 for my test samples with C=any thing more than 2( i wonder why there were no difference between C=2 and C= 100, i got the 99.16 accuracy for all the values for C more than 2!). didn't change the gamma or the score would be destroyed! the kernel ='rbf'.
    thanks for this amazing tutorial BTW! 🙂

  • codebasics
    November 26, 2020

    kernel:rbf,c=10 – 99.7% accuracy

  • codebasics
    November 26, 2020

    C=1.0,kernel='linear',gamma='auto' Score=98.88%

  • codebasics
    November 26, 2020

    Please make a video on the topic "How to choose which ML algorithm for a dataset".
    And thanks for amazing videos, sir.

  • codebasics
    November 26, 2020

    Tried couple of iterations finally I got 99.166% accuracy with all default parameters. random_state=1 while defining train test data.. Thanks a lot Sir

  • codebasics
    November 26, 2020

    Sir when you didn't used the X_train and y_train parameters for checking score?

  • codebasics
    November 26, 2020

    SVC(kernel='linear')->1.0

  • codebasics
    November 26, 2020

    I have developed a program. It's working good. How to use a nonlinear kernel, when data is not linearly separable?
    I tried using code" model = SVC(kernel='nonlinear')", But I am getting an error. Can you please explain how to separate nonlinear data?
    We use SVM to separate linearly separable data. When the data is nonlinear, We use the concept called Kernal, Which maps the data into a high dimensional space and separate it?

  • codebasics
    November 26, 2020

    Sir how to implement kernels, i mean the code part, please help sir

  • codebasics
    November 26, 2020

    Sir my model got over fitted
    Score =1
    How to proceed further and how it got over fitted I can't understand
    rosanthedreamer@gmail.com
    Pls mail me the further procedure 🙏

  • codebasics
    November 26, 2020

    accuracy = 98.6% (linear)
    accuracy = 99.16% (rbf)

  • codebasics
    November 26, 2020

    "ImportError – cannot import svc from sklearn.svm" 
    I couldn't find out any solutions out here cold you please help me out bro.
    From sklearn.svm import svc

  • codebasics
    November 26, 2020

    This is great! Thank you so much for the video

  • codebasics
    November 26, 2020

    got 98.6% accuracy for c=0.8 ,kernel='poly' & gamma='scale' and using random_state =6

  • codebasics
    November 26, 2020

    RBF Gamma Auto C 1000 @ 98.89%
    Linear Gamma Auto C Auto @ 96.67%

  • codebasics
    November 26, 2020

    I got an accuracy of 99.4% for exercise, when C=0.5 and gamma='scale'

  • codebasics
    November 26, 2020

    I got 100 % accuracy with C = 10

Write a comment