{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from sklearn.decomposition import PCA\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "\n", "np.random.seed(1001)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# 随机生成训练数据\n", "n = 200\n", "x = np.linspace(-4, 4, n)\n", "error = np.random.randn(n)\n", "y = 1 * x + error\n", "data = np.c_[x, y]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
PCA(n_components=2)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
PCA(n_components=2)