Showing posts with label Classification. Show all posts
Showing posts with label Classification. Show all posts

Tuesday, March 28, 2023

What is Support Vector Machine?


 What is Support Vector Machine?



Support Vector Machine (SVM) is a supervised machine learning algorithm that is widely used in classification, regression, and outlier detection problems. SVM is based on the concept of finding the optimal hyperplane that separates different classes in the feature space.


In detail, the SVM algorithm works by mapping the input data into a high-dimensional feature space using a non-linear mapping function. It then finds the optimal hyperplane that maximizes the margin between the two classes. The margin is the distance between the hyperplane and the nearest data points from each class. The hyperplane that has the maximum margin is the one that is chosen as the optimal hyperplane. SVM is capable of handling both linear and non-linear classification problems by using different kernel functions.


How the algorithm works:

  • First, the algorithm takes the input data and maps it into a higher-dimensional space. This mapping is done using a kernel function, which transforms the input data into a new space where it is easier to separate the classes using a hyperplane.
  • Next, the algorithm finds the hyperplane that maximizes the margin between the two classes. The margin is the distance between the hyperplane and the closest data points from each class.
  • The algorithm then predicts the class of new data points by determining which side of the hyperplane they fall on.

Advantages of SVM include:

  • SVM can handle both linear and non-linear classification problems by using different kernel functions such as linear, polynomial, radial basis function (RBF), and sigmoid.
  • SVM can handle high-dimensional data and can perform well even when the number of features is greater than the number of samples.
  • SVM has a regularization parameter that helps to avoid overfitting and improve the generalization performance of the model.
  • SVM can handle both binary and multi-class classification problems by using different strategies such as one-vs-one and one-vs-all.


Disadvantages of SVM include:

  • SVM can be sensitive to the choice of kernel function and its parameters. Choosing the right kernel function and its parameters can be a challenging task.
  • SVM can be computationally expensive, especially for large datasets with a large number of features.
  • SVM can be sensitive to outliers in the data and may result in a suboptimal solution.


An example of building a simple SVM model using Python's scikit-learn library:


First, let's load the dataset and split it into training and testing sets:


from sklearn.datasets import load_breast_cancer

from sklearn.model_selection import train_test_split


# Load data

cancer = load_breast_cancer()


# Split data into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(cancer.data, cancer.target, test_size=0.3, random_state=42)



Next, let's create an SVM model with a radial basis function (RBF) kernel and a regularization parameter of 1.0:


from sklearn.svm import SVC


# Create SVM model

svc = SVC(kernel='rbf', C=1.0)


We can train the model on the training data using the fit method:


# Train SVM model on training data

svc.fit(X_train, y_train)


We can then use the model to make predictions on the testing data using the predict method:


# Make predictions on testing data

y_pred = svc.predict(X_test)


Finally, we can evaluate the performance of the model using metrics such as accuracy, precision, recall, and F1-score:


from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score


# Calculate evaluation metrics

accuracy = accuracy_score(y_test, y_pred)

precision = precision_score(y_test, y_pred)

recall = recall_score(y_test, y_pred)

f1 = f1_score(y_test, y_pred)


# Print evaluation metrics

print('Accuracy: {:.2f}'.format(accuracy))

print('Precision: {:.2f}'.format(precision))

print('Recall: {:.2f}'.format(recall))

print('F1-score: {:.2f}'.format(f1))


This will output the evaluation metrics for the SVM model on the testing data. The exact values may vary each time the code is run due to the random splitting of the data into training and testing sets.


In this example, we first load the iris dataset from Scikit-learn's built-in datasets. We split the data into training and testing sets using the train_test_split function. We create an SVM model with a linear kernel and a regularization parameter of 1.0. We train the SVM model on the training data using the fit function. We then use the trained model to predict the classes of the testing data using the predict function. Finally, we calculate the accuracy score of the model on the testing data using the accuracy_score function and print the result.






Saturday, November 23, 2019

Machine Learning Overview


Machine Learning Overview



For easy understanding of ML overview, this post shows the cheat sheet of types of ML with some algorithms as well as examples.



Kindly follow my blog and stay tuned for more advanced posts on ML. 

Thank you!


Reference:

Fernandez-Delgado, M., Sirsat, M., Cernadas, E., Alawadi, S., Barro, S., Febrero-Bande, M., 2019. An extensive experimental survey of regression methods. Neural Networks 111, 11–34. URL: 10.1016/j.neunet.2018.12.010

Monday, May 6, 2019

Research Paper on Machine Learning

 

  Research Papers on Classifiers and Regression Models


In this article, I am going to write on two most important research papers which are related to comparison of list of classification and regression techniques. If you are interested in learning several supervised techniques then you must refer following two papers.

 

These research findings are very useful for machine learning fans. Paper 1st is on comparison of classification techniques and 2nd is about comparison of large collection of popular regression techniques. I also given URLs of these papers for download. Besides, you can easily access our 77 regression models.

 

  • Paper 1: Do we need hundreds of classifiers to solve real world classification problems?

This research paper focuses on 179 classifiers over 121 datasets from 17 machine learning families.


Figure 1 - Machine Learning Classification Families

 

Classification techniques are implemented in R, Weka, Matlab and C. According to the study, random forest classifier is the most likely to be the best classifier. Download this paper from link https://bit.ly/1yAuJa9 


  • Paper 2: An extensive experimental survey of regression methods.

Paper second is on machine learning regression techniques, published in neural network. It explains and compares 77 the most important models which belong to 19 machine learning families. Techniques are evaluated on 83 UCI regression datasets. Most of the techniques are implemented in R. I also mentioned list of Regression Techniques with their R package and references in my earlier article. Figure 2 shows 19 regression families.


Figure 2 - Machine Learning Regression Families


You can download above paper from link https://bit.ly/2J2OmTV 

Our code of 77 regression models is now available. Download it from https://bit.ly/2Y9LyI5 

And downloaded code you can try for your regression problem. 
  
Kindly follow my blog and stay tuned for more advanced post on dataset splitting. 

Thank you!


What is Support Vector Machine?

  What is Support Vector Machine? Support Vector Machine (SVM) is a supervised machine learning algorithm that is widely used in classificat...