<jupyter_start><jupyter_text>CHEN 5595 Homework 10 This HW focuses on linear models for classification. It consists only of coding exercises. I provide several definitions and hints throughout that will help you.  If you are confused about anything, do not panic, send us a message on Piazza! We are here to help you learn.Please answer the numerical exercises using an ipython notebook **in [Google Colab](https://colab.research.google.com/)** (provide the link with your handwritten homework). **Please answer each coding problem  in a different cell**.You can also view this ipython notebook in your browser through [binder](https://mybinder.org/v2/gh/smcantab/chen5595-fall2020/b389546a03f6e273293255bcca52d5c2acc7fd3f?filepath=homework%2Fhw10-questions.ipynb) or through nbviewer [link](https://nbviewer.jupyter.org/github/smcantab/chen5595-fall2020/blob/master/homework/hw10-questions.ipynb).  Linear Models for Classification Consider the following python function to generate synthetic data $\{\mathbf{x}_n, t_n\}$ consisting of 2-dimensional input vectors $\mathbf{x}_n$ and target variables $t_n=\{0, 1\}$, with $n=1, \dots, N$ with or without outliers.<jupyter_code>import numpy as np

def create_toy_data(n0=25, n1=25, n_outliers=0):
    """
    Generates 2d Gaussian point clouds for binary classification problem
    with or without outliers
    
    n0: int
        number of points in class C0
    n1: int
        number of points in class C1
    n_outliers : int
        number of outliers of class C1
    """
    np.random.seed(42)
    x0 = np.random.normal(size=(n0, 2)) - 1
    x1 = np.random.normal(size=(n1, 2)) + 1.
    if n_outliers > 0:
        x_1 = np.random.normal(size=(n_outliers, 2)) + np.array([5., 10])
        return np.concatenate([x0, x1, x_1]), np.concatenate([np.zeros(n0), np.ones(n1+n_outliers)]).astype('int')
    return np.concatenate([x0, x1]), np.concatenate([np.zeros(n0), np.ones(n1)]).astype('int')<jupyter_output><empty_output><jupyter_text>Which we plot as an example below, first without outliers and then with outliers<jupyter_code>import matplotlib.pyplot as plt
x_train, y_train = create_toy_data(25, 25, 0)
fig = plt.figure()
ax = fig.add_subplot('111')
ax.scatter(x_train[:, 0], x_train[:, 1], c=y_train)
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_aspect('equal', adjustable='box')
_ = ax.set_title('Without outliers')
x_out_train, y_out_train = create_toy_data(25, 25, 5)
fig = plt.figure()
ax = fig.add_subplot('111')
ax.scatter(x_out_train[:, 0], x_out_train[:, 1], c=y_out_train)
ax.set_xlim(-5, 10)
ax.set_ylim(-5, 12)
ax.set_aspect('equal', adjustable='box')
_ = ax.set_title('With outliers')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12737430167597766, 'fraction_numerical': 0.04618249534450652, 'mean_word_length': 4.788793103448276, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 3, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '90083', 'license': 'MIT', 'n_tokens_mistral': 1031, 'n_tokens_neox': 940, 'n_words': 259, 'path': 'homework/hw10-questions.ipynb', 'repo_name': 'smcantab/chen5595-fall2020', 'size': '2685'}