ICP 4 - Joshmitha307/Python GitHub Wiki
Name : Joshmitha Tammareddy
Class id : 36
Mail : [email protected]
Aim :
1 . Implementing Naïve Bayes method using scikit-learn libraryUse iris dataset available in https://umkc.box.com/s/pm3cebmhxpnczi6h87k2lwwiwdvtxyk8Use cross validation to create training and testing partEvaluate the model on testing part
-
Implement linear SVMmethodusing scikit libraryUse the samedataset aboveWhich algorithm you got better accuracy? Can you justify why?
-
use the SVM with RBF kernel on the same dataset. How the result changed?
Code Explanation :
sklearn is a library which contains all the algorithms and datasets. Using sklearn we import all the algorithms and datasets and matrics, which is a marix containing all the elements in a dataset, and train_test_split from sklearn.model_selection to split the data and perform training and testing on it.
The datasets are loaded into Iris and Naive Bayes model is fitted to the data. The dataset is considered as iris.data which is X and iris.target which is Y and prediction is made. The expected result is iris.target and the predicted is iris.target.
Cross validation is done to compare the predicted and expected results. A matrix is used to find the accuracy of the classification. Both X and Y are split into training and testing data sets and a test size is given and also the random state is given so that we can understand it easily.
The model is then then trained on testing and training data set and the model is evaluated on testing part.
Linear SVC model is imported from the sklearn library. The data is divided into X and Y. The SVM model is fitted to the data.
The model is trained on testing set and prediction is made based on X and Y.
Cross validation is done and the model is evaluated based on testing part.
Accuracy score is also imported from sklearn library.
The datasets are loaded and split and are trained and tested.
RBF model is fitted to the training sets. And prediction is made based on X_test and the accuracy score is printed.
Output :
The Guassian model accuracy is 93.33%
The accuracy of SVm classifer on training set is 0.98 and on testing set is 0.97
The RBF Kernel accuracy score is 0.9
Conclusion :
By using SVM with the RBF Kernel accuracy has decreased.