<jupyter_start><jupyter_text>Exercise<jupyter_code>%matplotlib widget
import numpy as np
np.random.seed(0)
import pandas as pd

import matplotlib.pyplot as plt
import seaborn as sns
def array_info(array: np.ndarray) -> None:
    print(f"ndim: {array.ndim}")
    print(f"shape: {array.shape}")
    print(f"size: {array.size}")
    print(f"dtype: {array.dtype}")
    print(f"values:\n{array[:10 if len(array) > 10 else -1]}\n")<jupyter_output><empty_output><jupyter_text>Exercise 1- Generate a feature dataset (x) of 100 samples with 2 features by sampling from a multivariate normal distribution.      - With a mean of $\mu = (-5, 5)^T$      - With a covariance matrix of $C = \begin{pmatrix}1 & 0\\0 & 1\end{pmatrix}$- Generate a target dataset (y) of 100 samples by adding up the two features of each row of x<jupyter_code>num_samples = 100
num_features = 2
mean = np.array([-5, 5])
cov = np.eye(2)
x = np.random.multivariate_normal(
    mean=mean,
    cov=cov,
    size=(num_samples,)
)
array_info(x)
y = np.sum(x, axis=1)
array_info(y)<jupyter_output>ndim: 1
shape: (100,)
size: 100
dtype: float64
values:
[ 2.16420955  3.21963118  0.89028011  0.79873121  0.30737965  1.59831708
  0.88271274  0.77753756  1.28892081 -0.54102804]<jupyter_text>Exercise 2Plot the data such that the following figure will be displayed:![img](../media/exercise_plt.png)Hint:The colorbar is *coolwarm*<jupyter_code>fig, ax = plt.subplots()

scatter = ax.scatter(x[:,0], x[:, 1], c=y, cmap='coolwarm')
ax.axis('equal')
ax.set_xlabel("$x_1^i$")
ax.set_ylabel("$x_2^i$")

plt.colorbar(scatter)
plt.plot();<jupyter_output><empty_output><jupyter_text>Exercise 3- Plot the data from exercise 2 with a 3D Plot:    - The X, Y axis are the two features from the x array    - The Z axis is the y array![img](../media/exercise_plt2.png)<jupyter_code>fig = plt.figure()
ax = fig.add_subplot(projection='3d')

scatter = ax.scatter(x[:,0], x[:,1], y, c=y, cmap='coolwarm')

ax.set_xlabel("$x_1^i$")
ax.set_ylabel("$x_2^i$")
ax.set_zlabel("$y^i$")

cbar = plt.colorbar(scatter, ax=ax)
plt.show();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15678776290630975, 'fraction_numerical': 0.06739961759082218, 'mean_word_length': 4.895774647887324, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, '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': '343135', 'license': 'MIT', 'n_tokens_mistral': 931, 'n_tokens_neox': 840, 'n_words': 200, 'path': '4_Matplotlib/10_Solution.ipynb', 'repo_name': 'tkaya94/UdemyDataScience', 'size': '2092'}