Showing posts with label Comparison of models & techniques. Show all posts
Showing posts with label Comparison of models & techniques. Show all posts

Tuesday, 19 September 2017

Comparison of Naive Bayes, Semi-Supervised and ensemble models

 Comparison of Naive Bayes, Semi-Supervised & Ensemble methods  on output 



Python Program
>>> clf101=naive_bayes.BernoulliNB()
>>> clf102=tree.DecisionTreeClassifier()
>>> clf103=tree.ExtraTreeClassifier()

>>> from sklearn import ensemble
>>> clf104=ensemble.ExtraTreesClassifier()
>>> clf105=naive_bayes.GaussianNB()

>>> from sklearn import semi_supervised
>>> clf106=semi_supervised.LabelPropagation()
>>> clf107=semi_supervised.LabelSpreading()

>>> for clf in [clf101, clf102, clf103, clf104, clf105, clf106]:
...     clf.fit(x, y)
...     x_min, x_max = x[:, 0].min() -1, x[:, 0].max() +1
...     y_min, y_max = x[:, 1].min() -1, x[:, 1].max() +1
...     xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
...     z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
...     z = z.reshape(xx.shape)
...     plt.figure()
...     plt.pcolormesh(xx, yy, z, cmap=cmap_light)
...     plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=24)
...     plt.xlim(xx.min(), xx.max())
...     plt.ylim(yy.min(), yy.max())
...     plt.title("(clf='%s')" %(clf))
...

BernoulliNB(alpha=1.0, binarize=0.0, class_prior=None, fit_prior=True)

DecisionTreeClassifier(class_weight=None, criterion='gini', max_depth=None,
            max_features=None, max_leaf_nodes=None,
            min_impurity_decrease=0.0, min_impurity_split=None,
            min_samples_leaf=1, min_samples_split=2,
            min_weight_fraction_leaf=0.0, presort=False, random_state=None,
            splitter='best')

ExtraTreeClassifier(class_weight=None, criterion='gini', max_depth=None,
          max_features='auto', max_leaf_nodes=None,
          min_impurity_decrease=0.0, min_impurity_split=None,
          min_samples_leaf=1, min_samples_split=2,
          min_weight_fraction_leaf=0.0, random_state=None,
          splitter='random')

ExtraTreesClassifier(bootstrap=False, class_weight=None, criterion='gini',
           max_depth=None, max_features='auto', max_leaf_nodes=None,
           min_impurity_decrease=0.0, min_impurity_split=None,
           min_samples_leaf=1, min_samples_split=2,
           min_weight_fraction_leaf=0.0, n_estimators=10, n_jobs=1,
           oob_score=False, random_state=None, verbose=0, warm_start=False)

GaussianNB(priors=None)

LabelPropagation(alpha=None, gamma=20, kernel='rbf', max_iter=1000, n_jobs=1,
         n_neighbors=7, tol=0.001)







Comparison of Linear models

                                Linear Models output accuracy

Linear models are tested here to see their accuracy in terms of output.

Python program:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from matplotlib.colors import ListedColormap
>>> from sklearn import neighbors, datasets
>>> n_neighbors = 24
>>> iris = datasets.load_iris()
>>> x = iris.data[:, :2]
>>> y = iris.target
>>> h = .02
>>> cmap_bold = ListedColormap(['firebrick', 'lime', 'blue'])


>>> cmap_light = ListedColormap(['pink', 'lightgreen', 'paleturquoise'])

//Defining different linear models//
>>> clf86 = linear_model.SGDClassifier()
>>> clf87 = linear_model.SGDRegressor()
>>> clf88 = linear_model.PassiveAggresiveRegressor()
>>> clf89 = linear_model.LinearRegression()
>>> clf90 = linear_model.Ridge()
>>> clf91 = linear_model.RidgeCV()
>>> clf92 = linear_model.Lasso()
>>> clf93 = linear_model.LassoLars()
>>> clf94 = linear_model.ElasticNet()

//Calling and plotting them//
>>> for clf in [clf86, clf87, clf88, clf89, clf90, clf91, clf92, clf93, clf94]:
...     clf.fit(x, y)
...     x_min, x_max = x[:, 0].min() -1, x[:, 0].max() +1
...     y_min, y_max = x[:, 1].min() -1, x[:, 1].max() +1
...     xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
...     z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
...     z = z.reshape(xx.shape)
...     plt.figure()
...     plt.pcolormesh(xx, yy, z, cmap=cmap_light)
...     plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=24)
...     plt.xlim(xx.min(), xx.max())
...     plt.ylim(yy.min(), yy.max())
...     plt.title("Regressor (clf='%s')" %(clf))
...

Output:

SGDClassifier(alpha=0.0001, average=False, class_weight=None, epsilon=0.1,
       eta0=0.0, fit_intercept=True, l1_ratio=0.15,
       learning_rate='optimal', loss='hinge', max_iter=5, n_iter=None,
       n_jobs=1, penalty='l2', power_t=0.5, random_state=None,
       shuffle=True, tol=None, verbose=0, warm_start=False)

SGDRegressor(alpha=0.0001, average=False, epsilon=0.1, eta0=0.01,
       fit_intercept=True, l1_ratio=0.15, learning_rate='invscaling',
       loss='squared_loss', max_iter=5, n_iter=None, penalty='l2',
       power_t=0.25, random_state=None, shuffle=True, tol=None, verbose=0,
       warm_start=False)

PassiveAggressiveRegressor(C=1.0, average=False, epsilon=0.1,
              fit_intercept=True, loss='epsilon_insensitive', max_iter=5,
              n_iter=None, random_state=None, shuffle=True, tol=None,
              verbose=0, warm_start=False)

LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)

Ridge(alpha=1.0, copy_X=True, fit_intercept=True, max_iter=None,
   normalize=False, random_state=None, solver='auto', tol=0.001)

RidgeCV(alphas=(0.1, 1.0, 10.0), cv=None, fit_intercept=True, gcv_mode=None,
    normalize=False, scoring=None, store_cv_values=False)

Lasso(alpha=1.0, copy_X=True, fit_intercept=True, max_iter=1000,
   normalize=False, positive=False, precompute=False, random_state=None,
   selection='cyclic', tol=0.0001, warm_start=False)

LassoLars(alpha=1.0, copy_X=True, eps=2.2204460492503131e-16,
     fit_intercept=True, fit_path=True, max_iter=500, normalize=True,
     positive=False, precompute='auto', verbose=False)

ElasticNet(alpha=1.0, copy_X=True, fit_intercept=True, l1_ratio=0.5,
      max_iter=1000, normalize=False, positive=False, precompute=False,
      random_state=None, selection='cyclic', tol=0.0001, warm_start=False)











Comparison of different Neighbor Classifiers & Regressors

                                               Neighbors Techniques

Neighbors techniques are tested here to see their accuracy in terms of output.

Python program:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from matplotlib.colors import ListedColormap
>>> from sklearn import neighbors, datasets
>>> n_neighbors = 24
>>> iris = datasets.load_iris()
>>> x = iris.data[:, :2]
>>> y = iris.target
>>> h = .02
>>> cmap_bold = ListedColormap(['firebrick', 'lime', 'blue'])


>>> cmap_light = ListedColormap(['pink', 'lightgreen', 'paleturquoise'])

//Calling different neighbors with Discriminant Analysis techniques//
>>> from sklearn import neighbors, tree
>>> clf14 = neighbors.NearestNeighbors()
>>> clf15 = neighbors.KNeighborsClassifier()
>>> clf16 = neighbors.RadiusNeighborsClassifier()
>>> clf17 = neighbors.RadiusNeighborsRegressor()
>>> clf18 = neighbors.KNeighborsRegressor()
>>> clf19 = neighbors.NearestCentroid()
>>> from sklearn import discriminant_analysis
>>> clf20 = discriminant_analysis.LinearDiscriminantAnalysis()
>>> clf21 = discriminant_analysis.QuadraticDiscriminantAnalysis()

//Plotting techniques//
>>> for clf in [clf15, clf17, clf18, clf19, clf20, clf21]:
...     clf.fit(x, y)
...     x_min, x_max = x[:, 0].min() -1, x[:, 0].max() +1
...     y_min, y_max = x[:, 1].min() -1, x[:, 1].max() +1
...     xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
...     z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
...     z = z.reshape(xx.shape)
...     plt.figure()
...     plt.pcolormesh(xx, yy, z, cmap=cmap_light)
...     plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=24)
...     plt.xlim(xx.min(), xx.max())
...     plt.ylim(yy.min(), yy.max())
...     plt.title("Regressor (clf='%s')" %(clf))
...

Output:







Comparison of different clustering techniques

                                                 Clustering Techniques

Clustering techniques are tested here to see their accuracy in terms of output.

Python program:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from matplotlib.colors import ListedColormap
>>> from sklearn import neighbors, datasets
>>> n_neighbors = 24
>>> iris = datasets.load_iris()
>>> x = iris.data[:, :2]
>>> y = iris.target
>>> h = .02
>>> cmap_bold = ListedColormap(['firebrick', 'lime', 'blue'])
>>> cmap_light = ListedColormap(['pink', 'lightgreen', 'paleturquoise'])

//Defining different clustering techniques//
>>> clf51= cluster.KMeans()
>>> clf52= cluster.AffinityPropagation()
>>> clf53= cluster.MeanShift()
>>> clf54= cluster.SpectralClustering()
>>> clf55= cluster.AgglomerativeClustering()
>>> clf56= cluster.DBSCAN()
>>> clf57= cluster.Birch()
>>> from sklearn import mixture
>>> clf58= cluster.GaussianMixture()

//Plotting the output//

>>> for clf in [clf51, clf52, clf53, clf57, clf58]:
...     clf.fit(x, y)
...     x_min, x_max = x[:, 0].min() -1, x[:, 0].max() +1
...     y_min, y_max = x[:, 1].min() -1, x[:, 1].max() +1
...     xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
...     z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
...     z = z.reshape(xx.shape)
...     plt.figure()
...     plt.pcolormesh(xx, yy, z, cmap=cmap_light)
...     plt.scatter(x[:, 0], x[:, 1], c=y, cmap=cmap_bold, edgecolor='k', s=24)
...     plt.xlim(xx.min(), xx.max())
...     plt.ylim(yy.min(), yy.max())
...     plt.title("Regressor (clf='%s')" %(clf))
...

Output: