Scikit learn multi-class classification for support vector machines - machine-learning

I want to know whether LinearSVC supports multi-class classification by default or do we have to wrap it in OneVsRestClassifier like:
OneVsRestClassifier(LinearSVC())

According to this part of the documentation:
SVC, NuSVC and LinearSVC are classes capable of performing multi-class classification on a dataset.
[...]
On the other hand, LinearSVC implements “one-vs-the-rest” multi-class strategy, thus training n_class models. If there are only two classes, only one model is trained:
So it supports multiclass classification by default.

Related

How does RandomForestClassifier work for classification?

I have learned that Sklearn treats multi-class classification problems as a collection of binary problems. Quoting the Sklearn user guide:
In extending a binary metric to multiclass or multilabel problems, the data is treated as a collection of binary problems, one for each class.
So, binary classification models like LogisticRegression or Support vector matrices can support multi-class cases by using either One-vs-One or One-vs-Rest strategies. I wanted to know if that was the case for RandomForestClassifier too? How about other classifiers in Sklearn - are they all used as binary classifiers under the hood when dealing with a multi-class problem?
According to the documentation for Decision Trees, multi-output problems add a small change to the leaves of each tree in a random forest.
Suppose you have set criterion='gini'. In essence, each node is built by picking a subset of max_features features, calculating the average reduction in the gini impurity for all N classes and choosing the variable-threshold combination that reduces it most.
This means that random forests do not create one model for each class. Instead, it's only one model that simultaneously reduces the criterion metric for all classes in each node of every tree and predicts the most common class at each leaf.

What Does tf.estimator.LinearClassifier() Do?

In TensorFlow library, what does the tf.estimator.LinearClassifier class do in linear regression models? (In other words, what is it used for?)
Linear Classifier is nothing but Logistic Regression.
According to Tensorflow documentation, tf.estimator.LinearClassifier is used to
Train a linear model to classify instances into one of multiple
possible classes. When number of possible classes is 2, this is binary
classification
Linear regression predicts a value while the linear classifier predicts a class. Classification aims at predicting the probability of each class given a set of inputs.
For implementation of tf.estimator.LinearClassifier, please follow this tutorial by guru99.
To know about the linear classifiers, read this article.

How to use Naive Bayes Binary Classification in CoreML?

I am trying to build a number classification model in CoreML and want to use the naive bayes classifier but not able to find how to use it. My algorithm is using naive bayes
At the moment, coremltools support only following types of classifiers:
SVMs (scikitlearn)
Neural networks (Keras, Caffe)
Decision trees and their ensembles (scikitlearn, xgboost)
Linear and logistic regression (scikitlearn)
However, implementing Naïve Bayes in Swift yourself is not that hard, check this implementation, for example.

An SVM implementation supporting non-linear kernels and multi-label on a one-vs.-rest

I'm looking for a SVM implementation with support for non-linear kernels and one-vs-rest scenario, to perform a multi-label classification. Preferably, written in Python, or that I can call from Python with wrappers.
I was looking into sklearn, and there are two implementations to use SVM for classification:
sklearn.svm.LinearSVC
- supports multi-label classification with a one-vs.-rest scenario, but it's based on liblinear, and therefore only supports linear kernels.
sklearn.svm.SVC
- based on libsvm, supports non-linear kernels, but multi-label classification is done under a one-vs.-one reduction, it trains K (K − 1) / 2 binary classifiers for a K-way multiclass problem.
More info also here:
http://scikit-learn.org/stable/modules/multiclass.html
Does anyone knows any other SVM implementations directly supporting multi-label classification and non-linear kernels ?
One possible solution could also be to adapt the code based on sklearn.svm.SVC, to perform One-vs-Rest, was this already attempted before?
Binary Relevance problem transformation method uses one-vs-rest approach for doing multi-label classification. One could easily implement SVM with non-linear kernels using scikit-multilearn library. The following is the sample python code to do the same, where each row of train_y is a one-hot vector representing multiple labels (For instance, [0,0,1,0,1,0])
from skmultilearn.problem_transform.br import BinaryRelevance
from sklearn.svm import SVC
# Non-linear kernel
svm = SVC(kernel='rbf')
cls = BinaryRelevance(classifier=svm)
cls.fit(train_x, train_y)
predictions = cls.predict(test_x)

Logistic Regression only recognizing predominant classes

I am participating in the Kaggle San Francisco Crime competition and i am currently trying o number of different classifiers to test benchmark performances. I am using a LogisticRegressionClassifier from sklearn, without any parameter tuning and I noticed from sklearn.metrict.classification_report that it is only predicting the predominant classses,i.e. the classes which have the highest number of occurrences in my training set.
Intuition tells me that this has to parameter tuning, but I am not sure which parameters I have to tweek in order to make the classifier more aware of less predominant classes ( LogisticRegressionClassifier has quite a few ). At the moment it is predicting only 3 classes from 38 or smth like that so it definitely needs improvement.
Any ideas?
If your model is classifying only predominant classes then you are facing problem of imbalance classes. Here are some good reads to tackle this in machine learning.
Logistic Regression is a binary classifier and uses one-vs-all or one-vs-one technique for multiclass classification, which is not good if you have higher number of output classes (33 in your case). Try using other classifier. For a start , use softmax classifier which is an extension of logistic classifier having support for multi-class classification. In scikit learn, set multi_class variable as multinomial to use softmax regression.
Other way to improve your model could be using GridSearch for parameter tuning.
On a side note, I would recommend you to use other models as well.

Resources