<jupyter_start><jupyter_text>EHB 420E Artificial Neural Networks Quiz-1<NAME>Colab link --> https://colab.research.google.com/drive/1B3jPH3LZu-o8kkRmoweHdz2E_m6n_9VUscrollTo=EHstXeNJuQI6   ---  Given Function<jupyter_code># Import packages to visualize the classifer
from matplotlib.colors import ListedColormap
import matplotlib.pyplot as plt
import warnings

# Import packages to do the classifying
import numpy as np
from sklearn.svm import SVC

def versiontuple(v):
    return tuple(map(int, (v.split("."))))


def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02):

    # setup marker generator and color map
    markers = ('s', 'x', 'o', '^', 'v')
    colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
    cmap = ListedColormap(colors[:len(np.unique(y))])

    # plot the decision surface
    x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution),
                           np.arange(x2_min, x2_max, resolution))
    Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T)
    Z = Z.reshape(xx1.shape)
    plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap)
    plt.xlim(xx1.min(), xx1.max())
    plt.ylim(xx2.min(), xx2.max())

    for idx, cl in enumerate(np.unique(y)):
        plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1],
                    alpha=0.8, c=cmap(idx),
                    marker=markers[idx], label=cl)

    # highlight test samples
    if test_idx:
        # plot all samples
        if not versiontuple(np.__version__) >= versiontuple('1.9.0'):
            X_test, y_test = X[list(test_idx), :], y[list(test_idx)]
            warnings.warn('Please update to NumPy 1.9.0 or newer')
        else:
            X_test, y_test = X[test_idx, :], y[test_idx]

        plt.scatter(X_test[:, 0],
                    X_test[:, 1],
                    c='',
                    alpha=1.0,
                    linewidths=1,
                    marker='o',
                    s=55, label='test set')<jupyter_output><empty_output><jupyter_text>Generating Data<jupyter_code>np.random.seed(0)
X = np.random.randn(200, 2)
y_xor = np.logical_xor(X[:, 0] > 0, X[:, 1] > 0)
y = np.where(y_xor, 1, -1)

plt.scatter(X[y == 1, 0],X[y == 1, 1],c='b', marker='x',label='1')
plt.scatter(X[y == -1, 0], X[y == -1, 1],c='r',marker='s',label='-1')

plt.xlim([-3, 3])
plt.ylim([-3, 3])
plt.legend(loc='best')
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Kernel Results<jupyter_code>data = [[0.01,1],
             [1,1],
             [10,1],
             [100,1],
             [0.1,1],
             [0.1,10],
             [0.1,100],
             [0.1,1000],
             [0.1,10000]]

for i in range(0,9):
  
  # Create a SVC classifier using a linear kernel
  svm = SVC(kernel='linear', random_state=0, gamma = data[i][0],C=data[i][1])
  # Train the classifier
  svm.fit(X, y)

  # Visualize the decision boundaries
  plot_decision_regions(X, y, classifier=svm)
  plt.legend(loc='upper left')
  plt.title("gamma =%s ,C=%s" %(data[i][0],data[i][1]))
  plt.tight_layout()
  plt.show()<jupyter_output>*c* argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapping will have precedence in case its length matches with *x* & *y*.  Please use the *color* keyword-argument or provide a 2-D array with a single row if you intend to specify the same RGB or RGBA value for all points.
*c* argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapping will have precedence in case its length matches with *x* & *y*.  Please use the *color* keyword-argument or provide a 2-D array with a single row if you intend to specify the same RGB or RGBA value for all points.<jupyter_text>RBF Kernel Results<jupyter_code>data = [[0.01,1],
             [1,1],
             [10,1],
             [100,1],
             [0.1,1],
             [0.1,10],
             [0.1,100],
             [0.1,1000],
             [0.1,10000]]

for i in range(0,9):
  
  # Create a SVC classifier using a linear kernel
  svm = SVC(kernel='rbf', random_state=0, gamma = data[i][0],C=data[i][1])
  # Train the classifier
  svm.fit(X, y)

  # Visualize the decision boundaries
  plot_decision_regions(X, y, classifier=svm)
  plt.legend(loc='upper left')
  plt.title("gamma =%s ,C=%s" %(data[i][0],data[i][1]))
  plt.tight_layout()
  plt.show()<jupyter_output>*c* argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapping will have precedence in case its length matches with *x* & *y*.  Please use the *color* keyword-argument or provide a 2-D array with a single row if you intend to specify the same RGB or RGBA value for all points.
*c* argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapping will have precedence in case its length matches with *x* & *y*.  Please use the *color* keyword-argument or provide a 2-D array with a single row if you intend to specify the same RGB or RGBA value for all points.
{'fraction_non_alphanumeric': 0.14606961282753225, 'fraction_numerical': 0.03519749706687524, 'mean_word_length': 2.952859350850077, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '179520', 'license': 'MIT', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1793, 'n_words': 518, 'path': 'Quiz_ANN.ipynb', 'repo_name': 'Permanganant/EHB-424E---Artificial-Neural-Networks-', 'size': '5126'}