Support Vector Regression using linear and non-linear kernels

Toy example of 1D regression using linear, polynomial and RBF kernels. print(__doc__) import numpy as np from sklearn.svm import SVR import matplotlib.pyplot as plt Generate sample data X = np.sort(5 * np.random.rand(40, 1), axis=0) y = np.sin(X).ravel() Add noise to targets y[::5] += 3 * (0.5 - np.random.rand(8)) Fit regression model svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1) svr_lin = SVR(kernel='linear', C=1e3) svr_poly = SVR(kernel='poly', C=1e3, degree=2) y_rbf = svr_rbf.fit(X, y).

Logistic function

Shown in the plot is how the logistic regression would, in this synthetic dataset, classify values as either 0 or 1, i.e. class one or two, using the logistic curve. print(__doc__) # Code source: Gael Varoquaux # License: BSD 3 clause import numpy as np import matplotlib.pyplot as plt from sklearn import linear_model # this is our test set, it's just a straight line with some # Gaussian noise xmin, xmax = -5, 5 n_samples = 100 np.random.seed(0) X = np.random.normal(size=n_samples) y =

covariance.EllipticEnvelope()

class sklearn.covariance.EllipticEnvelope(store_precision=True, assume_centered=False, support_fraction=None, contamination=0.1, random_state=None) [source] An object for detecting outliers in a Gaussian distributed dataset. Read more in the User Guide. Parameters: store_precision : bool Specify if the estimated precision is stored. assume_centered : Boolean If True, the support of robust location and covariance estimates is computed, and a covariance estimate is recomputed from it, wit

sklearn.cross_validation.check_cv()

Warning DEPRECATED sklearn.cross_validation.check_cv(cv, X=None, y=None, classifier=False) [source] Input checker utility for building a CV in a user friendly way. Deprecated since version 0.18: This module will be removed in 0.20. Use sklearn.model_selection.check_cv instead. Parameters: cv : int, cross-validation generator or an iterable, optional Determines the cross-validation splitting strategy. Possible inputs for cv are: None, to use the default 3-fold cross-validation, integer

4.8. Transforming the prediction target

4.8.1. Label binarization LabelBinarizer is a utility class to help create a label indicator matrix from a list of multi-class labels: >>> from sklearn import preprocessing >>> lb = preprocessing.LabelBinarizer() >>> lb.fit([1, 2, 6, 4, 2]) LabelBinarizer(neg_label=0, pos_label=1, sparse_output=False) >>> lb.classes_ array([1, 2, 4, 6]) >>> lb.transform([1, 6]) array([[1, 0, 0, 0], [0, 0, 0, 1]]) For multiple labels per instance, use MultiL

Feature selection using SelectFromModel and LassoCV

Use SelectFromModel meta-transformer along with Lasso to select the best couple of features from the Boston dataset. # Author: Manoj Kumar <mks542@nyu.edu> # License: BSD 3 clause print(__doc__) import matplotlib.pyplot as plt import numpy as np from sklearn.datasets import load_boston from sklearn.feature_selection import SelectFromModel from sklearn.linear_model import LassoCV # Load the boston dataset. boston = load_boston() X, y = boston['data'], boston['target'] # We use th

A demo of the mean-shift clustering algorithm

Reference: Dorin Comaniciu and Peter Meer, ?Mean Shift: A robust approach toward feature space analysis?. IEEE Transactions on Pattern Analysis and Machine Intelligence. 2002. pp. 603-619. print(__doc__) import numpy as np from sklearn.cluster import MeanShift, estimate_bandwidth from sklearn.datasets.samples_generator import make_blobs Generate sample data centers = [[1, 1], [-1, -1], [1, -1]] X, _ = make_blobs(n_samples=10000, centers=centers, cluster_std=0.6) Compute clustering with Mean

Demo of affinity propagation clustering algorithm

Reference: Brendan J. Frey and Delbert Dueck, ?Clustering by Passing Messages Between Data Points?, Science Feb. 2007 print(__doc__) from sklearn.cluster import AffinityPropagation from sklearn import metrics from sklearn.datasets.samples_generator import make_blobs Generate sample data centers = [[1, 1], [-1, -1], [1, -1]] X, labels_true = make_blobs(n_samples=300, centers=centers, cluster_std=0.5, random_state=0) Compute Affinity Propagation af = AffinityPropag

sklearn.feature_extraction.image.grid_to_graph()

sklearn.feature_extraction.image.grid_to_graph(n_x, n_y, n_z=1, mask=None, return_as=, dtype=) [source] Graph of the pixel-to-pixel connections Edges exist if 2 voxels are connected. Parameters: n_x : int Dimension in x axis n_y : int Dimension in y axis n_z : int, optional, default 1 Dimension in z axis mask : ndarray of booleans, optional An optional mask of the image, to consider only part of the pixels. return_as : np.ndarray or a sparse matrix class, optional The class to use

sklearn.svm.libsvm.decision_function()

sklearn.svm.libsvm.decision_function() Predict margin (libsvm name for this is predict_values) We have to reconstruct model and parameters to make sure we stay in sync with the python object.