TheilSen Regressor-Effect of parameters on output
TheilSenRegressor technique is tested here to see their accuracy in terms of output.
Python program:
//Plotting the analysis//
>>> from sklearn import linear_model
>>> clf = linear_model.TheilSenRegressor()
>>> clf.fit(x, y)
TheilSenRegressor(copy_X=True, fit_intercept=True, max_iter=300,
max_subpopulation=10000, n_jobs=1, n_subsamples=None,
random_state=None, tol=0.001, verbose=False)
a) Effect of maximum iterations (max_iter):
>>> for max_iter in [1, 2, 5, 50, 100, 250]:
... clf = linear_model.TheilSenRegressor(max_iter=max_iter)
... 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 = 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("TheilSenRegressor (max_iter='%s')" %(max_iter))
...
b) Effect of number of jobs (n_jobs):
>>> for n_jobs in [1, 2, 5, 50, 100, 250]:
... clf = linear_model.TheilSenRegressor(n_jobs=n_jobs)
... 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 = 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("TheilSenRegressor (n_jobs='%s')" %(n_jobs))
...
TheilSenRegressor technique is 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'])
//Plotting the analysis//
>>> clf = linear_model.TheilSenRegressor()
>>> clf.fit(x, y)
TheilSenRegressor(copy_X=True, fit_intercept=True, max_iter=300,
max_subpopulation=10000, n_jobs=1, n_subsamples=None,
random_state=None, tol=0.001, verbose=False)
a) Effect of maximum iterations (max_iter):
>>> for max_iter in [1, 2, 5, 50, 100, 250]:
... clf = linear_model.TheilSenRegressor(max_iter=max_iter)
... 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 = 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("TheilSenRegressor (max_iter='%s')" %(max_iter))
...
b) Effect of number of jobs (n_jobs):
>>> for n_jobs in [1, 2, 5, 50, 100, 250]:
... clf = linear_model.TheilSenRegressor(n_jobs=n_jobs)
... 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 = 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("TheilSenRegressor (n_jobs='%s')" %(n_jobs))
...
No comments:
Post a Comment