{"cells":[{"cell_type":"markdown","source":["Using the generated data, find matrix $V$ and the vectors that describe the new coordinate system in reduced dimension $3$ using either SVD or eigenvectors & eigenvalues. Graph the data and calculate how much the training set's variance has diminished. Have you preserved $90 \\%$ of the variance?\n","\n","\n","\n"],"metadata":{"id":"RgPTKyZh_6Y6"}},{"cell_type":"code","source":["import numpy as np\n","import matplotlib.pyplot as plt\n","from mpl_toolkits.mplot3d import Axes3D # Import 3D plotting module\n","\n","# Enable interactive mode for Google Colab\n","%matplotlib notebook\n","\n","# Install Plotly\n","!pip install plotly\n","\n","# Import Plotly\n","import plotly.express as px\n","\n","# Set a random seed for reproducibility\n","np.random.seed(42)\n","\n","# Define the number of vectors you want to generate\n","num_vectors = 100\n","\n","# Generate random values for the first dimension\n","dim1 = np.random.randn(num_vectors)\n","\n","# Create the second dimension with dependency on the first dimension and random noise\n","dependency_factor_dim2 = 0.7\n","noise_dim2 = np.random.randn(num_vectors)\n","dim2 = dependency_factor_dim2 * dim1 + 2 + noise_dim2\n","\n","# Create the third dimension with dependency on the second dimension and random noise\n","dependency_factor_dim3 = -1.1\n","noise_dim3 = np.random.randn(num_vectors)\n","dim3 = dependency_factor_dim3 * dim2 - 4 + noise_dim3\n","\n","# Generate random values for the fourth dimension\n","dim4 = np.random.randn(num_vectors)\n","\n","# Create a 4-dimensional vector by stacking the dimensions horizontally\n","B = np.column_stack((dim1, dim2, dim3, dim4))\n","\n","# Create a 3D scatter plot of the first three dimensions using (allows you to rotate the figure with your mouse)\n","fig = px.scatter_3d(x=dim1, y=dim2, z=dim3, color=dim4)\n","fig.update_layout(title='Interactive 3D Scatter Plot of Dimensions 1, 2, 3', scene=dict(xaxis_title='x_1', yaxis_title='x_2', zaxis_title='x_3'))\n","\n","# Show the plot\n","fig.show()"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":594},"id":"Wp5UoGVZ0W_X","executionInfo":{"status":"ok","timestamp":1703795602937,"user_tz":300,"elapsed":9515,"user":{"displayName":"Joseph Sketl","userId":"03428201371779072895"}},"outputId":"9baa378b-5d4d-44f0-8240-749d1c871bd0"},"execution_count":1,"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: plotly in /usr/local/lib/python3.10/dist-packages (5.15.0)\n","Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly) (8.2.3)\n","Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from plotly) (23.2)\n"]},{"output_type":"display_data","data":{"text/html":["\n","
\n","\n","