## Cynhard85 / MachineLearningTutorial

Untitled.ipynb 124.32 KB
liuxinyang 提交于 2018-07-20 18:15 . write a little
{
"cells": [
{
"cell_type": "code",
"execution_count": 24,
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import numpy as np\n",
"from mpl_toolkits.mplot3d import Axes3D"
]
},
{
"cell_type": "code",
"execution_count": 25,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.37454012 0.95071431]\n",
" [0.73199394 0.59865848]\n",
" [0.15601864 0.15599452]\n",
" [0.05808361 0.86617615]\n",
" [0.60111501 0.70807258]\n",
" [0.02058449 0.96990985]\n",
" [0.83244264 0.21233911]\n",
" [0.18182497 0.18340451]\n",
" [0.30424224 0.52475643]\n",
" [0.43194502 0.29122914]\n",
" [0.61185289 0.13949386]\n",
" [0.29214465 0.36636184]\n",
" [0.45606998 0.78517596]\n",
" [0.19967378 0.51423444]\n",
" [0.59241457 0.04645041]\n",
" [0.60754485 0.17052412]]\n",
"[6.08093297 5.72457337 4.31646263 6.14927482 5.89433772 5.74474511\n",
" 5.25514132 4.26810026 5.33467938 4.53608027 4.50283283 5.00581165\n",
" 6.08290123 5.22248156 4.54370282 4.76686339]\n"
]
},
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x1cfb9226780>,\n",
" <matplotlib.lines.Line2D at 0x1cfb9226908>]"
]
},
"execution_count": 25,
"output_type": "execute_result"
},
{
"data": {
"text/plain": [
"<matplotlib.figure.Figure at 0x1cfb91f12b0>"
]
},
"output_type": "display_data"
}
],
"source": [
"m = 16\n",
"np.random.seed(42)\n",
"\n",
"X_values = np.random.rand(m, 2)\n",
"print(X_values)\n",
"y = 0.8 * X_values[:,0] + 2 * X_values[:,1] + 4  + 0.2 * np.random.randn(m)\n",
"print(y)\n",
"plt.plot(X_values, y, 'b.')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.figure.Figure at 0x1cfb94127b8>"
]
},
"output_type": "display_data"
}
],
"source": [
"fig = plt.figure()\n",
"ax = Axes3D(fig)\n",
"\n",
"x1 = np.arange(-1, 1, 0.02)\n",
"x2 = np.arange(-1, 1, 0.02)\n",
"\n",
"X1, X2 = np.meshgrid(x1, x2)\n",
"Y = 0.8 * X1 + 2 * X2 + 4\n",
"ax.plot_surface(X1, X2, Y)\n",
"plt.show()"
]
}
],
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
},
"toc": {
"base_numbering": 1,
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}