{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "from sklearn.ensemble import GradientBoostingRegressor\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "\n", "np.random.seed(1010)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# 生成训练数据\n", "n = 40\n", "X = np.linspace(0, 3 * np.pi, num=n).reshape(-1, 1)\n", "error = np.random.normal(0, 0.1, size=n).reshape(-1, 1)\n", "Y = np.abs(np.sin(X)) + error\n", "Y = np.where(Y > 0.5, 1, 0)\n", "data = np.concatenate((Y, X), axis=1)\n", "data = pd.DataFrame(data, columns=['y', 'x'])" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
GradientBoostingRegressor(learning_rate=0.8, max_depth=2, n_estimators=3)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
GradientBoostingRegressor(learning_rate=0.8, max_depth=2, n_estimators=3)