在有了相关性理论基础之后,我们即可创建一个可用于回归模型实验的数据生成器。
# 科学计算模块
import numpy as np
import pandas as pd
# 绘图模块
import matplotlib as mpl
import matplotlib.pyplot as plt
为了方便后续练习的展开,我们尝试自己创建一个数据生成器,用于自主生成一些符合某些条件、难度可控、具备某些特性的数据集。机器学习发展至今,在追求模型效果提升的过程中,模型本身可解释性逐渐变弱,对于很多集成类算法,很多模型构建思路也在朝向深度学习靠拢。这使得很多模型内部逐渐呈现灰箱甚至是黑箱的状态。但是,在初学过程中,我们仍然需要通过类似控制变量的方法、通过设计一些实验,去深入理解算法运行原理及一些优化方法的实际作用,这就需要我们自己动手,创建一些数据用于实验的原材料,通过一些实验深入了解模型原理,从“炼丹师”朝着“化学家”更进一步。
和Lesson 1中介绍的一样,课程中案例分为三类,分别是基础阶段的手动创建数据集、实战阶段的竞赛数据集和企业应用实战阶段的企业数据集。
我们先尝试生成两个特征、存在偏差,自变量和因变量存在线性关系的数据集
num_inputs = 2 # 两个特征
num_examples = 1000 # 总共一千条数据
然后尝试通过线性方程,确定自变量和因变量的真实关系
np.random.seed(24) # 设置随机数种子
np.random.randn(2, 2)
array([[ 1.32921217, -0.77003345], [-0.31628036, -0.99081039]])
# 线性方程系数
w_true = np.array([2, -1]).reshape(-1, 1)
b_true = np.array(1)
# 扰动项相关
delta = 0.01
# 创建数据集的特征和标签取值
features = np.random.randn(num_examples, num_inputs)
labels_true = features.dot(w_true) + b_true
labels = labels_true + np.random.normal(size = labels_true.shape) * delta
features
array([[-1.07081626, -1.43871328], [ 0.56441685, 0.29572189], [-1.62640423, 0.2195652 ], ..., [-1.44029131, 0.50439425], [ 0.96604603, 1.76623359], [ 0.57852053, -1.34028424]])
labels_true
array([[ 2.97080769e-01], [ 1.83311182e+00], [-2.47237367e+00], [ 4.68336867e-01], [ 2.81906560e+00], [-8.12559166e-01], [ 2.84911190e+00], [ 8.16104836e-01], [-2.23673251e+00], [ 3.84903763e+00], [ 3.57341849e-02], [-6.31876174e-01], [ 6.71457939e-01], [-2.91185026e-01], [ 5.69912892e+00], [ 5.94732168e+00], [ 1.08837176e-01], [-4.63796210e-01], [ 3.23817195e+00], [-3.74448288e+00], [ 2.94300273e+00], [ 9.09452631e-01], [-1.86514513e+00], [ 3.34061566e+00], [ 2.82759572e+00], [-2.68017804e-01], [ 1.18081099e+00], [-5.77104701e-01], [-1.86902545e-01], [ 4.59659037e+00], [ 2.91058551e+00], [-2.92879416e+00], [-2.24480799e+00], [ 7.42354926e-01], [ 4.96769843e-01], [-8.56161409e-01], [ 2.33995763e+00], [-2.68636701e+00], [-2.02536294e+00], [ 1.33778651e-02], [-2.96956928e+00], [ 1.71623389e+00], [-3.40056100e-01], [-1.03032263e+00], [-1.36399996e+00], [ 4.64206863e+00], [ 2.12618776e+00], [-3.96670468e+00], [-9.87359971e-02], [ 2.74188291e+00], [ 2.69310247e+00], [ 2.53031562e+00], [ 9.60620716e-01], [-2.23037785e+00], [ 4.16067728e+00], [-4.61856137e+00], [ 1.84762605e+00], [ 1.63335388e+00], [-4.43214410e-01], [ 1.49176406e+00], [-9.49748507e-01], [ 3.27856336e-01], [-2.10457709e-01], [ 2.93176190e+00], [ 2.12462225e+00], [ 3.71433122e+00], [ 3.07027044e+00], [-3.23819505e+00], [ 3.70868805e+00], [ 3.21569291e-01], [-1.61700787e+00], [-8.31931064e-02], [ 2.52458055e+00], [ 4.98917459e+00], [-2.01685427e+00], [ 2.66108526e+00], [ 4.48191824e-01], [-1.40068431e+00], [-1.83222469e+00], [-7.18016323e-01], [-8.51113111e-01], [ 1.32321483e+00], [ 1.46691171e+00], [-1.18225288e+00], [ 6.26261578e-02], [ 3.27653959e+00], [ 2.97279772e+00], [ 1.31439610e+00], [ 5.23150279e-01], [ 4.86457923e+00], [ 1.75006817e-01], [-5.09190232e+00], [ 1.42526714e+00], [ 2.49985579e-01], [ 1.75330033e+00], [ 2.20076130e+00], [ 1.42807529e+00], [-1.57412662e+00], [ 1.17050449e+00], [ 1.19434771e+00], [ 6.80361782e-01], [-1.01326319e+00], [ 1.36030855e+00], [ 8.33047658e-01], [ 7.80632849e-01], [ 5.69559599e-01], [-1.29543842e+00], [ 1.05433364e+00], [ 1.47330398e+00], [-6.52967862e-01], [ 4.85111229e+00], [-2.72396868e+00], [-1.47206171e+00], [ 8.86353525e-01], [ 1.68510554e+00], [ 2.59036480e+00], [-1.15323224e+00], [-2.80663566e+00], [ 2.97019074e+00], [ 1.32960227e+00], [ 2.48880849e-02], [ 6.15396223e-02], [ 1.24348134e+00], [ 6.48922945e-01], [-1.42787978e+00], [ 4.88074278e+00], [ 1.40677372e+00], [ 4.38697004e-01], [ 3.61713742e+00], [ 1.99753780e+00], [ 4.64843020e+00], [ 1.52074325e-01], [ 2.09202286e+00], [ 6.68740871e-01], [ 7.31989302e-02], [ 1.27334904e+00], [ 4.61050483e+00], [ 3.14976054e-01], [ 4.49936060e+00], [ 6.55267991e+00], [-3.05539010e+00], [-1.08977926e+00], [ 6.78763981e-01], [ 1.76263216e+00], [-9.29134883e-01], [-3.57133063e-01], [ 2.10494853e+00], [-9.11363587e-01], [ 2.60994643e+00], [ 3.00952989e+00], [ 6.69950831e-01], [ 4.25271601e+00], [ 2.02637310e+00], [-1.14101825e+00], [ 6.27965192e-01], [-1.36153896e+00], [ 1.84432487e+00], [ 5.89902565e-01], [-2.48510850e+00], [ 6.81704911e+00], [ 1.98067463e+00], [-2.82582615e+00], [ 8.70531477e-01], [ 2.28236306e+00], [-1.57076842e+00], [ 3.50664559e+00], [ 2.52176442e+00], [-8.98848750e-01], [ 1.67618396e+00], [ 3.62163440e+00], [-3.69273747e-01], [-2.72739385e+00], [ 2.05921166e+00], [ 2.22957101e+00], [-8.90294141e-02], [-4.74630933e-01], [ 3.62447538e+00], [ 3.60181539e+00], [-2.02562039e+00], [ 4.37278856e+00], [ 3.39954527e+00], [-1.11405448e+00], [ 4.15521037e+00], [-2.86483147e+00], [ 2.04989395e+00], [ 2.63397705e+00], [ 6.33095786e-03], [ 4.33112403e+00], [ 7.85665756e-01], [ 3.88431670e+00], [ 1.08709667e+00], [ 4.22795814e+00], [-1.10210163e+00], [ 1.85393784e-02], [ 2.99838411e+00], [ 5.14318101e+00], [-2.79535650e-01], [ 3.24198724e+00], [-7.73402268e-01], [ 1.95069604e+00], [ 1.59206507e+00], [ 2.51142100e+00], [-3.25043451e+00], [ 1.51732378e+00], [-3.79142862e+00], [ 3.41006654e+00], [ 1.30764886e+00], [-3.82689851e+00], [-4.51330122e+00], [ 2.37217299e+00], [ 2.65746668e+00], [-7.09346740e-03], [-1.07397474e+00], [-1.87272908e+00], [-1.31082400e+00], [ 1.50744966e+00], [ 4.60153536e+00], [-3.44872327e-01], [ 2.93378821e+00], [-5.45812512e-01], [ 3.30375012e+00], [ 6.24047841e-01], [ 3.57909436e+00], [ 1.39345519e+00], [ 4.82697656e-01], [-2.41771398e+00], [ 9.78179823e-01], [-4.12594158e+00], [ 1.32773903e+00], [-1.41702756e+00], [ 1.82777870e+00], [ 2.37082011e-01], [-3.82386252e-01], [ 2.76208419e+00], [-1.81415233e+00], [-4.11341892e-01], [ 2.77652942e+00], [-8.65959898e-01], [ 5.76207311e+00], [-9.06369332e-02], [ 8.04329279e-01], [ 3.05142770e+00], [-1.82943642e+00], [ 7.38197527e-01], [-2.29670537e+00], [ 7.24814934e+00], [-2.59603533e+00], [ 4.29245665e+00], [ 2.74300468e-01], [ 2.83521326e-01], [ 4.62032131e+00], [-7.93635389e-01], [ 4.04538524e+00], [ 7.40329072e-01], [ 2.94988017e+00], [ 2.26297891e-01], [-5.66053003e-01], [ 3.08142551e+00], [ 8.17163340e-01], [-1.86150173e+00], [-2.13586087e+00], [ 2.14225065e+00], [ 1.28155113e+00], [ 2.05865303e+00], [-9.44795567e-01], [ 3.85825638e+00], [-2.29003336e+00], [-1.78633762e-01], [-1.39143919e+00], [ 1.42013447e+00], [ 1.33948258e+00], [ 2.64679349e-02], [ 2.93347965e+00], [ 3.91076072e+00], [-1.88354186e+00], [-1.29745333e+00], [-1.53410938e-01], [ 2.75803391e+00], [ 1.67888879e+00], [ 2.91492013e+00], [ 1.73036874e+00], [-4.57149732e-01], [ 1.90193952e+00], [-2.20005970e+00], [ 3.94903524e+00], [-3.86434708e+00], [ 8.15036175e-01], [ 7.77031375e-01], [-3.21577212e-01], [-2.28309216e+00], [ 1.13264167e+00], [ 3.09271458e+00], [ 1.18898911e+00], [ 1.53179092e+00], [ 2.98525204e+00], [-1.33112804e+00], [-3.64502990e+00], [ 1.40505981e+00], [-7.41969359e-02], [ 1.73980800e+00], [ 1.09485921e+00], [-5.78847871e-01], [ 1.12147145e+00], [ 9.39558688e-01], [-2.29008150e+00], [ 1.59553877e+00], [ 1.60257303e+00], [-1.33558429e+00], [-5.04944692e-01], [ 2.82769836e+00], [-4.50995419e-01], [ 3.77911502e+00], [ 2.62974540e+00], [-1.46035130e+00], [-1.84351782e+00], [ 3.71857079e+00], [-5.79193621e-01], [ 3.96826852e+00], [ 2.17390544e+00], [ 3.55533095e+00], [ 6.23680894e-01], [ 1.06506282e+00], [ 6.05076144e-01], [-2.72898588e-01], [-8.58810001e-01], [ 1.72019724e+00], [ 2.62653971e+00], [ 3.27723828e+00], [-4.67660001e-01], [ 2.51413824e+00], [ 2.32839621e+00], [ 2.81433824e+00], [ 1.69251729e+00], [ 4.49521996e+00], [-1.15527719e+00], [ 3.74520351e+00], [ 2.96417747e+00], [ 1.47241306e+00], [-1.43151314e-01], [ 1.77468171e+00], [-2.37142285e+00], [-2.38007656e+00], [-2.36807523e-01], [ 2.59837119e+00], [ 3.24732195e+00], [-7.94474622e-01], [ 2.35343586e+00], [ 1.06319197e+00], [ 2.92754675e+00], [ 1.02626242e+00], [ 4.27893083e+00], [ 8.82663862e-01], [ 1.83325433e+00], [-1.25439853e+00], [-4.81429997e-01], [ 4.08549613e+00], [ 7.66268083e+00], [-5.59679311e-01], [-1.31634864e-01], [ 2.63911930e+00], [ 2.17091242e-01], [ 1.54903549e+00], [ 5.81447345e+00], [ 2.16470420e+00], [-4.89366099e-01], [ 6.76727204e-01], [-3.93322264e-01], [-7.31302336e-01], [-7.75386551e-01], [-6.02184957e-01], [-1.61340275e+00], [-1.57272738e+00], [-3.09041875e-01], [-7.02949858e-01], [-7.35058782e-01], [ 2.80423308e+00], [ 4.05257125e+00], [-4.49539522e-01], [-3.45990521e+00], [-7.15888458e-01], [-2.82019562e+00], [ 4.29610512e-01], [ 3.57598318e+00], [-1.63611038e+00], [ 3.24534938e+00], [-6.20580406e-02], [ 1.05943015e+00], [ 4.24340054e+00], [ 2.07971889e+00], [-1.12154175e+00], [ 8.80713384e-01], [ 2.34299428e+00], [-3.78063604e+00], [ 8.81875756e-01], [-8.06283576e-01], [ 4.42382428e+00], [ 2.17900013e+00], [ 5.76169164e+00], [ 3.79830713e+00], [ 7.82278343e-01], [ 1.99979683e+00], [ 6.13207914e-01], [-4.14383816e-01], [ 1.98707765e+00], [ 1.28727280e+00], [ 1.94873783e+00], [ 3.90976158e+00], [ 7.07042609e-01], [-1.19090055e-01], [ 1.44201004e+00], [ 3.92792793e+00], [-2.60929484e+00], [ 2.89660869e-01], [-5.40815351e-01], [ 7.28083165e+00], [-4.15820752e+00], [-7.94777261e-01], [ 2.04012009e+00], [-8.27887601e-01], [ 2.44939389e+00], [ 2.43373183e+00], [ 1.76530364e+00], [ 3.10527221e+00], [ 5.32613550e-01], [ 2.13711092e+00], [ 1.24005033e+00], [-2.19352131e+00], [ 7.60405447e-01], [ 2.07915545e+00], [-2.49284426e+00], [ 6.18555561e+00], [ 3.91729539e-01], [-2.19365637e+00], [ 5.18993045e-01], [-7.94814987e-01], [-1.06968612e+00], [-3.44744257e+00], [-2.03227219e-02], [-1.12195231e+00], [ 1.63844918e+00], [-2.14408626e+00], [-5.01578510e+00], [-4.11762278e-01], [ 8.43008335e-01], [ 2.70476373e+00], [ 1.49816977e+00], [ 2.01966314e+00], [ 1.11423085e+00], [ 6.50842860e-01], [ 3.85665539e+00], [ 1.35488816e+00], [ 3.35877103e+00], [-9.56208835e-01], [ 9.68202749e-01], [ 3.72077294e+00], [ 1.44225800e+00], [ 2.05031161e-02], [ 4.68703215e-01], [-5.46979848e-01], [-1.78896838e-01], [-8.74231548e-01], [-1.19363357e+00], [-1.11919649e+00], [ 5.77883446e-01], [ 6.79886671e-01], [ 3.21621096e-01], [ 2.29145226e+00], [ 3.01181642e+00], [-7.02807372e-01], [ 8.96023848e-01], [-2.29274600e+00], [-1.99209080e-01], [-1.10055514e+00], [ 1.06146313e+00], [ 2.56058246e+00], [ 2.79998880e+00], [-1.69510367e+00], [ 9.15702429e-01], [ 1.11327444e+00], [-6.41953807e+00], [-1.26455870e+00], [ 9.10255838e-01], [ 2.53460396e-01], [ 4.16702571e-02], [-3.15823689e-01], [-4.39620778e-01], [ 1.41470601e+00], [-6.30040154e-01], [-1.63323473e+00], [ 1.34296074e+00], [-1.39265593e+00], [-2.00915283e+00], [ 6.55234244e+00], [-1.10916596e+00], [ 3.84633107e+00], [-3.49231899e+00], [ 5.63212724e-01], [ 2.53787625e+00], [ 2.19529904e+00], [ 4.60518952e+00], [-5.46889643e-01], [-1.64858327e+00], [-3.18409333e+00], [ 1.51449750e+00], [ 1.60453451e+00], [ 3.71250237e+00], [ 2.36104368e-01], [ 4.57431457e+00], [-3.53967336e-01], [ 1.72363311e+00], [ 9.35859356e-03], [-2.37599433e+00], [-1.60548405e+00], [ 1.75537208e+00], [-1.67907234e+00], [-1.02230187e-01], [ 1.10381620e+00], [-4.14393495e-01], [-3.91511661e+00], [-1.83431871e+00], [ 4.89744247e-01], [-4.11785064e+00], [ 2.15340714e+00], [-1.54629509e+00], [ 3.52499639e+00], [ 1.95738507e+00], [-1.68892706e+00], [-6.50232477e-01], [ 1.91359632e-01], [ 3.25413446e+00], [ 1.34297486e+00], [ 4.48261529e+00], [-4.35778666e-01], [-1.08011479e+00], [-1.64798629e+00], [-1.16004373e-01], [ 1.21641250e+00], [-1.82684813e+00], [ 2.64371748e+00], [ 2.79134291e+00], [-2.85205829e+00], [ 5.42914684e-01], [ 5.22052053e-01], [-9.94994899e-01], [ 7.85109576e-01], [-4.29115560e+00], [ 3.11674366e+00], [ 2.02128887e+00], [ 3.35235503e+00], [-1.21306087e+00], [-2.47808484e+00], [ 4.52013123e-01], [ 1.64471579e+00], [-4.82134479e-01], [ 4.38720928e-01], [-4.88905953e+00], [ 3.14523691e+00], [ 1.68834623e+00], [-1.08470477e+00], [ 6.76943032e+00], [-1.59923036e+00], [-2.40583964e+00], [ 2.77383616e+00], [-1.06319171e+00], [ 1.76831294e+00], [ 3.82335213e-01], [-3.59831806e+00], [ 5.34637399e+00], [ 3.13817454e-01], [ 1.31722348e+00], [ 1.85318647e+00], [ 1.88113967e+00], [ 2.54682670e-01], [ 3.36539245e+00], [ 1.18188837e-01], [ 1.40248475e+00], [-1.22343935e-01], [ 2.15387733e-01], [ 4.23903075e-01], [ 1.05882045e+00], [ 6.04352987e+00], [-4.15992939e+00], [-2.22200395e+00], [ 3.72235391e+00], [-2.19508169e+00], [ 5.17784592e-01], [ 1.03947315e+00], [-1.09092980e+00], [ 2.70217331e+00], [ 5.98226068e-01], [ 1.23725820e+00], [-1.54914774e+00], [-9.80331359e-01], [ 1.11552631e+00], [-1.19268692e+00], [ 2.42857925e+00], [-8.58324318e-01], [ 3.01641329e+00], [-1.86027245e+00], [ 1.56723654e-01], [-1.93053973e-01], [ 2.17457120e-01], [ 2.12500349e+00], [ 1.17831676e+00], [ 2.77678222e+00], [ 1.33651475e+00], [ 2.56943873e+00], [-6.08575170e-01], [-1.22581283e+00], [ 1.05094122e+00], [ 3.05175731e-01], [ 4.95512691e+00], [ 1.56323070e+00], [ 3.44908139e-01], [ 2.69401834e+00], [ 8.73083240e-01], [ 2.10222800e+00], [-2.17515243e-01], [-1.14647601e+00], [-1.35716947e+00], [-1.56106604e+00], [ 5.21644602e+00], [ 1.83109054e+00], [ 1.00653151e+00], [-5.43177421e-01], [-1.64071330e+00], [ 2.82506873e+00], [ 2.46595304e+00], [-2.26383868e+00], [ 3.37898434e+00], [ 1.37281085e+00], [ 9.16213667e-01], [-3.71083671e-02], [ 3.14964877e+00], [ 2.39937184e+00], [-2.34287218e-01], [ 3.83955389e+00], [-3.29007321e+00], [ 1.28958503e+00], [-1.34077885e-01], [ 8.16105093e-01], [ 2.09766474e+00], [ 6.67355789e-01], [ 4.23804656e+00], [-4.57296225e-01], [ 4.51086184e+00], [ 4.02312524e+00], [ 2.75274044e+00], [ 8.14280795e-01], [-3.20172580e+00], [ 7.05197397e-02], [ 1.62704604e+00], [ 3.25119436e+00], [ 3.00034571e+00], [ 1.90457533e+00], [ 3.95142616e+00], [ 1.98476663e+00], [ 1.03753055e+00], [ 4.09715446e+00], [ 1.72999555e+00], [ 5.07708890e+00], [-1.32624312e+00], [ 8.29914771e-01], [ 2.16179837e+00], [ 8.23792043e-01], [ 2.33815587e+00], [ 2.61162457e+00], [ 2.36905508e-01], [ 1.98360111e+00], [ 1.63243059e+00], [ 1.78594581e+00], [-2.05120394e+00], [ 4.88230608e+00], [-1.73851663e+00], [-4.69100037e-01], [-8.52775827e-01], [ 3.49454597e+00], [-2.01470839e+00], [ 2.26949266e+00], [ 1.65782853e+00], [-2.51388043e+00], [ 1.38729975e+00], [ 3.80609357e+00], [ 3.11041284e+00], [ 3.30740876e-03], [ 6.54384111e-01], [-5.01817193e-01], [ 4.56829349e+00], [ 3.49611435e+00], [ 2.96215287e+00], [ 1.82517871e+00], [ 1.60878012e+00], [-3.56385814e-01], [ 2.78432413e+00], [ 1.63462496e-01], [ 1.40136022e+00], [-4.49664108e+00], [ 1.98587206e+00], [ 3.22015350e+00], [ 6.88078959e-01], [ 3.96563465e+00], [ 1.63675026e+00], [-1.39600439e+00], [-8.61509791e-01], [ 1.73544122e+00], [ 1.85816453e+00], [ 3.20217724e+00], [-2.27779622e+00], [-1.69407202e+00], [-5.42474867e-01], [-1.51133935e-01], [ 1.28478276e+00], [ 2.24733867e+00], [ 4.23867439e+00], [-4.06270468e+00], [ 2.88539436e+00], [ 6.91862376e+00], [ 1.68434463e+00], [ 3.19090549e+00], [-2.61640355e-01], [ 1.52384395e+00], [ 3.66975359e+00], [ 2.66160594e+00], [ 2.08404947e+00], [ 8.24719398e-01], [ 3.98967869e-01], [ 1.82205236e+00], [-1.81184919e+00], [ 4.07734355e+00], [ 2.58590664e+00], [ 5.76940473e-01], [ 1.69404632e+00], [-1.14396648e+00], [-2.52136546e+00], [-7.93996582e-01], [ 2.29065209e+00], [ 7.60330392e-01], [-6.04193809e-01], [ 3.07984531e+00], [-1.35705123e+00], [ 7.81728952e-01], [ 1.17128868e-01], [ 7.31832786e-01], [-2.97818647e+00], [ 2.17365385e+00], [-3.16579712e-01], [ 1.12687770e+00], [ 2.04981420e+00], [ 2.18352562e+00], [ 5.30373586e+00], [ 1.54191967e+00], [ 2.77352661e-02], [ 2.37184079e+00], [ 1.24508629e-02], [-7.44373514e-01], [-7.17754515e-01], [ 1.19327481e+00], [-1.68956092e+00], [ 4.34181107e+00], [ 2.11527354e+00], [-4.17174829e+00], [-1.17081401e+00], [ 1.23861783e+00], [-1.48641284e+00], [-1.52811755e+00], [ 2.41599519e-01], [ 1.09714098e+00], [ 1.37396124e+00], [ 3.86259616e+00], [ 3.29617038e+00], [-1.04909970e+00], [ 6.35017886e+00], [ 1.77209544e+00], [ 3.55860312e+00], [-7.15283734e-01], [ 2.97145660e-02], [-1.91123859e+00], [-4.07564325e-01], [-7.06721119e-01], [ 1.00569190e+00], [ 7.57479838e-01], [-1.06746529e-01], [ 5.59651740e-01], [-1.21611407e-01], [ 2.84118064e+00], [ 7.55756750e-01], [ 2.17188813e+00], [ 1.02861667e+00], [ 1.15635689e+00], [ 4.14266003e+00], [-3.18565593e+00], [ 2.38642815e-01], [ 1.09772927e+00], [ 2.24768900e-01], [ 5.50804001e-01], [ 2.93935723e+00], [ 2.57249036e+00], [ 4.34630091e+00], [ 2.11589044e+00], [-1.49964238e+00], [-1.05364956e-01], [ 4.42972133e-01], [ 2.39552370e+00], [ 2.20663613e+00], [ 1.59243606e+00], [ 1.32668205e+00], [ 9.16039393e-01], [ 2.96321622e+00], [-1.63397292e+00], [ 1.93116410e+00], [ 2.53259089e-01], [-2.22876479e+00], [ 3.55602480e+00], [ 4.94459708e+00], [ 4.10046578e+00], [ 1.54471847e+00], [ 5.78101662e+00], [-7.38775865e-01], [-2.41346769e+00], [-1.81984841e+00], [ 1.37535208e+00], [-1.67124094e+00], [ 3.52007012e-01], [ 1.54070146e+00], [ 1.18103226e+00], [ 2.62100882e+00], [-2.66893201e+00], [ 1.87328907e+00], [ 1.36173064e+00], [ 8.77302020e-01], [-1.39520314e+00], [ 1.18116962e-01], [ 1.92505255e+00], [-3.67860541e+00], [ 1.48644321e+00], [-4.57899617e-01], [-1.33330702e-02], [ 4.63530941e-01], [ 1.96575159e+00], [-1.45135905e+00], [-2.59655951e+00], [ 1.00769131e+00], [-1.07092790e+00], [ 2.46028057e+00], [ 2.58272221e+00], [-2.11198528e-01], [-1.09406825e+00], [-4.77671164e+00], [-3.43109138e+00], [ 1.61312741e+00], [ 1.71597984e+00], [ 4.63157502e-01], [ 4.62205211e-02], [ 8.54799882e-01], [-3.14399358e-01], [ 1.36316599e+00], [-1.85030543e+00], [ 1.51185804e+00], [ 8.70281439e-01], [ 1.23795672e+00], [ 3.28711848e+00], [ 2.38800197e+00], [ 5.36682696e-01], [-5.35134999e-01], [-2.31844055e-01], [-6.34513258e-01], [ 5.46873827e-01], [ 2.88364946e+00], [ 6.73108935e+00], [-4.20819671e+00], [-1.05988806e+00], [ 2.60027655e+00], [ 3.59191124e-02], [-1.80710039e+00], [ 4.14595853e-01], [ 1.46715115e+00], [ 2.78795600e+00], [ 3.21275167e+00], [ 2.26727986e+00], [ 4.07413199e+00], [-3.84835903e-01], [ 2.86775988e+00], [ 1.30428016e+00], [ 1.09452138e-01], [ 8.73041573e-01], [ 6.34636516e-01], [ 1.45974165e+00], [ 5.44885989e+00], [-5.34561527e-01], [-1.92100856e+00], [-1.79877702e+00], [-1.58624719e+00], [-3.52508668e+00], [-1.26232201e-01], [ 2.74005439e+00], [ 6.26060680e-01], [-3.40715463e+00], [-2.31353448e-01], [ 1.74427885e+00], [-1.25829220e+00], [ 9.59468460e-01], [ 5.56231583e+00], [-1.25998807e+00], [-8.73750114e-01], [ 2.75825007e+00], [ 2.51259136e+00], [ 3.81166740e+00], [-2.16300580e+00], [-1.23296080e+00], [ 2.54357699e+00], [-4.84252337e-01], [-2.58070850e-01], [ 1.22750118e+00], [ 8.24378166e-01], [ 1.12594787e+00], [-8.73769605e-01], [ 1.18371945e+00], [ 3.57330773e+00], [ 3.79495961e+00], [-4.47725374e-01], [ 2.67058128e+00], [ 2.17671184e+00], [-1.05041990e+00], [-3.33046651e+00], [-4.54250777e+00], [ 2.99284435e+00], [ 2.04551598e+00], [ 4.41711686e-01], [-1.11189196e+00], [ 7.04242099e-01], [ 1.21693817e+00], [-1.62497836e+00], [ 5.12686108e+00], [ 4.63429214e+00], [ 3.41336029e-01], [ 1.01852617e+00], [ 1.80552488e+00], [-1.57606901e+00], [-4.96744409e-01], [-1.90625595e+00], [ 4.74259235e-01], [ 2.57077999e+00], [ 2.38647133e+00], [ 5.42793756e-01], [ 2.22282462e+00], [ 9.69658404e-01], [ 1.88353970e+00], [ 4.21970513e+00], [-2.42388274e+00], [-4.45801817e-01], [ 7.09539251e-01], [ 8.42884225e-01], [ 1.66446119e+00], [ 1.79378819e+00], [ 3.79466825e+00], [ 4.28262610e-01], [-2.47199822e-02], [-6.14811073e-01], [ 6.59037492e-01], [ 3.65450106e-02], [ 2.66413132e+00], [-1.61813369e+00], [-1.67832099e+00], [ 3.60926477e+00], [ 3.74660261e+00], [ 4.08402095e+00], [ 3.90033163e+00], [ 1.88854392e+00], [ 1.63930928e+00], [-5.48631262e-01], [-3.06707095e+00], [ 2.27559884e+00], [ 2.48563735e+00], [ 1.01023250e+00], [-1.76039190e+00], [-2.51795291e+00], [ 2.26999709e+00], [ 8.07294015e+00], [ 3.01612410e-01], [-1.18445060e+00], [-6.66219484e-01], [-9.20169796e-01], [ 1.40495318e-01], [ 7.18067702e-01], [ 2.26010349e+00], [-2.47306482e-01], [ 1.35788517e+00], [ 5.79860656e-01], [ 9.93134661e-01], [ 2.88895417e+00], [-2.51038664e-01], [ 3.53970607e+00], [ 3.10975153e+00], [-6.54386757e-01], [ 3.30016782e+00], [ 4.46137703e+00], [-1.11180760e+00], [-2.38497688e+00], [ 1.16585846e+00], [ 3.49732531e+00]])
注意,此时labels_true和features满足严格意义上的线性方程关系
但我们实际使用的标签labels,则是在labels_true的基础上增添了一个扰动项,np.random.normal(size = labels_true.shape) * delta
,这其实也符合我们一般获取数据的情况:真实客观世界或许存在某个规律,但我们搜集到的数据往往会因为各种原因存在一定的误差,无法完全描述真实世界的客观规律,这其实也是模型误差的来源之一(另一个误差来源是模型本身捕获规律的能力)。这其中,$y=2x_1-x_2+1$相当于我们从上帝视角创建的数据真实服从的规律,而扰动项,则相当于人为创造的获取数据时的误差。
简单查看我们创建的数据集
features[: 10]
array([[-1.07081626, -1.43871328], [ 0.56441685, 0.29572189], [-1.62640423, 0.2195652 ], [ 0.6788048 , 1.88927273], [ 0.9615384 , 0.1040112 ], [-0.48116532, 0.85022853], [ 1.45342467, 1.05773744], [ 0.16556161, 0.51501838], [-1.33693569, 0.56286114], [ 1.39285483, -0.06332798]])
labels[: 10]
array([[ 0.29161817], [ 1.83851813], [-2.46058022], [ 0.44394438], [ 2.8133944 ], [-0.8109745 ], [ 2.85143778], [ 0.83156296], [-2.22624102], [ 3.84279053]])
plt.subplot(121)
plt.scatter(features[:, 0], labels) # 第一个特征和标签的关系
plt.subplot(122)
plt.scatter(features[:,, 1] labels) # 第二个特征和标签的关系
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fb4a3448>
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fb5cd248>
不难看出,两个特征和标签都存在一定的线性关系,并且跟特征的系数绝对值有很大关系。当然,若要增加线性模型的建模难度,可以增加扰动项的数值比例,从而削弱线性关系。
# 设置随机数种子
np.random.seed(24)
# 修改因变量
labels1 = labels_true + np.random.normal(size = labels_true.shape) * 2
# 可视化展示
# 扰动较小的情况
plt.subplot(221)
plt.scatter(features[:, 0], labels) # 第一个特征和标签的关系
plt.subplot(222)
plt.plot(features[:, 1], labels, 'ro') # 第二个特征和标签的关系
# 扰动较大的情况
plt.subplot(223)
plt.scatter(features[:, 0], labels1) # 第一个特征和标签的关系
plt.subplot(224)
plt.plot(features[:, 1], labels1, 'yo') # 第二个特征和标签的关系
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285f92baec8>
<AxesSubplot:>
[<matplotlib.lines.Line2D at 0x285fb6f9fc8>]
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fb6e5388>
<AxesSubplot:>
[<matplotlib.lines.Line2D at 0x285fb75ea88>]
当然,我们也能生成非线性关系的数据集,此处我们创建满足$y=2x^2+1$规律的数据集。
np.power([2, 3], 2)
array([4, 9], dtype=int32)
# 设置随机数种子
np.random.seed(24)
num_inputs = 1 # 一个特征
num_examples = 1000 # 总共一千条数据
# 线性方程系数
w_true = np.array(2)
b_true = np.array(1)
# 特征和标签取值
features = np.random.randn(num_examples, num_inputs)
labels_true = np.power(features, 2) * w_true + b_true
labels = labels_true + np.random.normal(size = labels_true.shape) * 2
# 可视化展示
plt.scatter(features, labels)
<matplotlib.collections.PathCollection at 0x267c29d1588>
关于曲线相关,其实也可将其转化为线性相关,例如上例中,我们只需要新增一列$x_2=x$即可构建一个线性模型$y=x_2+1$,该方法也是特征工程中的一种特征衍生的方法。
此时需要注意的是,无论是创建了曲线规律的数据集,还是增加了扰动项绝对数值,都会对建模造成困难。但二者的造成困难的方式是不同的。如果是曲线规律的数据集,则代表规律本身更加复杂,此时需要使用更加复杂的模型来进行规律提取,该部分属于模型选取和参数调优的技术内容;而如果是扰动项比较大,则代表规律被掩盖的比较深,此时需要采用其他技术手段进行白噪声的处理,该部分属于特征工程技术内容。但本节内,无论是曲线规律还是白噪声数值过大,都会对线性方程建模造成困难。
这也就是控制数据集建模难度的最基础的抓手。
为了方便后续使用,我们将上述过程封装在一个函数内
A = np.arange(4).reshape(2, 2)
A
array([[0, 1], [2, 3]])
np.power(A, 3)
array([[ 0, 1], [ 8, 27]], dtype=int32)
A.dot(2)
array([[0, 2], [4, 6]])
np.ones_like(A)
array([[1, 1], [1, 1]])
def arrayGenReg(num_examples = 1000, w = [2, -1, 1], bias = True, delta = 0.01, deg = 1):
"""回归类数据集创建函数。
:param num_examples: 创建数据集的数据量
:param w: 包括截距的(如果存在)特征系数向量
:param bias:是否需要截距
:param delta:扰动项取值
:param deg:方程最高项次数
:return: 生成的特征数组和标签数组
"""
if bias == True:
num_inputs = len(w)-1 # 数据集特征个数
features_true = np.random.randn(num_examples, num_inputs) # 原始特征
w_true = np.array(w[:-1]).reshape(-1, 1) # 自变量系数
b_true = np.array(w[-1]) # 截距
labels_true = np.power(features_true, deg).dot(w_true) + b_true # 严格满足人造规律的标签
features = np.concatenate((features_true, np.ones_like(labels_true)), axis=1) # 加上全为1的一列之后的特征
else:
num_inputs = len(w)
features = np.random.randn(num_examples, num_inputs)
w_true = np.array(w).reshape(-1, 1)
labels_true = np.power(features, deg).dot(w_true)
labels = labels_true + np.random.normal(size = labels_true.shape) * delta
return features, labels
注:上述函数默认创建的是一个满足$y=2x_1-x_2+1$的数据集。
首先查看扰动项较小的时候的数据情况
# 设置随机数种子
np.random.seed(24)
# 扰动项取值为0.01
f, l = arrayGenReg(delta=0.01)
f
array([[ 1.32921217, -0.77003345, 1. ], [-0.31628036, -0.99081039, 1. ], [-1.07081626, -1.43871328, 1. ], ..., [ 1.5507578 , -0.35986144, 1. ], [-1.36267161, -0.61353562, 1. ], [-1.44029131, 0.50439425, 1. ]])
# 绘制图像查看结果
plt.subplot(121)
plt.scatter(f[:, 0], l) # 第一个特征和标签的关系
plt.subplot(122)
plt.scatter(f[:, 1], l) # 第二个特征和标签的关系
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x267c2ac7948>
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x267c2afdf48>
然后查看扰动项较大时数据情况
# 设置随机数种子
np.random.seed(24)
# 扰动项取值为2
f, l = arrayGenReg(delta=2)
# 绘制图像查看结果
plt.subplot(121)
plt.scatter(f[:, 0], l) # 第一个特征和标签的关系
plt.subplot(122)
plt.scatter(f[:, 1], l) # 第二个特征和标签的关系
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fbef0048>
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fbd1ba48>
当特征和标签满足二阶关系时候数据表现
# 设置随机数种子
np.random.seed(24)
# 最高次项为2
f, l = arrayGenReg(deg=2)
# 绘制图像查看结果
plt.subplot(121)
plt.scatter(f[:, 0], l) # 第一个特征和标签的关系
plt.subplot(122)
plt.scatter(f[:, 1], l) # 第二个特征和标签的关系
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fc080f08>
<AxesSubplot:>
<matplotlib.collections.PathCollection at 0x285fc15cb48>
在定义好数据创建函数之后,即可开始尝试手动实现线性回归模型。
该数据生成器并非为线性回归模型量身定制,而是通用与此后我们学习的所有回归类模型。关于分类模型数据集的创建,我们将在介绍逻辑回归时讲解。
此外,对于机器学习模型,我们将更多的从数据规律和模型提取规律角度出发,并不会太多顾及模型可解释性等问题。上述数据本身也是从规律角度出发构建的数据,并不具备“解释性”。
此处我们使用了一个随机数种子,以确保随机结果的可重复性。当我们设置某个随机数种子之后,每次随机过程都是可重复的:我们只需要再次调用相同随机种子,就可以重复此前随机过程。
np.random.randn(9)
array([ 1.62779574, 0.35449279, 1.03752763, -0.38568351, 0.519818 , 1.68658289, -1.32596315, 1.4289837 , -2.08935428])
np.random.seed(24)
np.random.randn(9)
array([ 1.32921217, -0.77003345, -0.31628036, -0.99081039, -1.07081626, -1.43871328, 0.56441685, 0.29572189, -1.62640423])
np.random.randn(9)
array([ 0.2195652 , 0.6788048 , 1.88927273, 0.9615384 , 0.1040112 , -0.48116532, 0.85022853, 1.45342467, 1.05773744])
np.random.seed(24)
np.random.randn(9)
array([ 1.32921217, -0.77003345, -0.31628036, -0.99081039, -1.07081626, -1.43871328, 0.56441685, 0.29572189, -1.62640423])
np.random.randn(9)
array([ 0.2195652 , 0.6788048 , 1.88927273, 0.9615384 , 0.1040112 , -0.48116532, 0.85022853, 1.45342467, 1.05773744])
当然,不同随机数种子所诞生的随机过程是不一样的,这也是“种子”的由来。此外,不同库中的随机过程需要用的不同随机种子也是不同的,比如上述我们用np.random.seed来规定numpy中相关随机过程,但如果是其他第三方库,如random库所定义的随机过程,就需要使用random库中的随机种子来确定。
import random
l = list(range(5))
l
[0, 1, 2, 3, 4]
random.seed(24)
random.shuffle(l)
l
[4, 2, 0, 1, 3]
random.shuffle(l)
l
[1, 4, 0, 3, 2]
l = list(range(5))
l
[0, 1, 2, 3, 4]
random.seed(24)
random.shuffle(l)
l
[4, 2, 0, 1, 3]
random.shuffle(l)
l
[1, 4, 0, 3, 2]
l = list(range(5))
l
[0, 1, 2, 3, 4]
np.random.seed(24)
random.shuffle(l)
l
[4, 0, 3, 2, 1]
random.shuffle(l)
l
[0, 4, 3, 1, 2]
l = list(range(5))
l
[0, 1, 2, 3, 4]
np.random.seed(24)
random.shuffle(l)
l
[4, 2, 3, 1, 0]
根据课程安排,本节定义的函数将后续课程中将经常使用,因此需要将其封装为一个模块方便后续调用。封装为模块有以下几种基本方法:
然后将文件保存在jupyter主目录下,并取名为ML_basic_function,后续即可通过import ML_basic_function进行调用。如果是jupyterlab用户,也可按照如下方式进行编写:
Step 1.打开左侧文件管理栏页,点击新建
Step 2.在新建目录中,选择Test File,并通过重命名将其命名为ML_basic_function.py
Step 3.在打开的文本编辑器中输入代码
并且需要注意,需要在py文件内导入相关的包。
Step 4.测试能否调用
首先重启当前jupyter
然后尝试导入自定义模块
from ML_basic_function import *
查看相关函数说明并使用
arrayGenReg?
Signature: arrayGenReg(num_examples=1000, w=[2, -1, 1], bias=True, delta=0.01, deg=1) Docstring: 回归类数据集创建函数。 :param num_examples: 创建数据集的数据量 :param w: 包括截距的(如果存在)特征系数向量 :param bias:是否需要截距 :param delta:扰动项取值 :param deg:方程最高项次数 :return: 生成的特征张和标签张量 File: f:\code file\机器学习实战\ml_basic_function.py Type: function
arrayGenReg()
(array([[-0.02288559, 0.71327691, 1. ], [ 1.28499182, -1.56530647, 1. ], [ 0.49971435, 0.67030438, 1. ], ..., [-0.28042436, 0.67200216, 1. ], [ 1.36287814, 1.02653665, 1. ], [-1.07159586, -0.01419314, 1. ]]), array([[ 2.39827879e-01], [ 5.12912037e+00], [ 1.33103149e+00], [ 1.05298983e+00], [ 4.68984787e+00], [-8.31814680e-01], [ 1.21287761e+00], [ 1.61414139e+00], [ 7.36961630e-01], [ 4.35536832e-01], [ 5.66268172e+00], [ 1.91769533e+00], [ 1.47292540e+00], [ 1.78401415e-01], [ 4.39015628e+00], [-3.09484999e+00], [-1.63199019e+00], [ 2.97309215e-01], [ 1.87154712e+00], [ 2.69122838e+00], [ 4.69491048e+00], [ 2.92370059e+00], [-1.39516732e+00], [-3.60360214e+00], [ 2.51687694e+00], [ 4.89787404e+00], [ 7.99627248e-01], [ 2.34579580e+00], [ 1.61243843e+00], [-3.42711478e+00], [ 1.97015844e+00], [-1.29401638e+00], [-6.13607906e-01], [ 9.15959629e-01], [ 1.61507913e+00], [-7.73493234e-01], [-3.04178989e-01], [ 5.54798304e+00], [ 1.51008541e-01], [ 4.08553512e+00], [-8.62090212e-01], [ 3.99293187e+00], [ 1.29185034e+00], [-2.58720658e-01], [ 4.42980377e+00], [ 3.67970327e+00], [ 7.65662744e-01], [ 4.64372413e+00], [ 1.21917322e+00], [ 1.04383852e+00], [-3.51324545e-01], [ 2.55038692e-01], [ 1.99514844e+00], [-1.90462460e+00], [ 2.21775720e+00], [-1.24848896e+00], [-4.06890016e-01], [ 3.33684428e-01], [-2.63292596e-01], [ 1.88787870e+00], [ 4.53224116e+00], [ 5.91954650e+00], [ 2.92934539e+00], [-7.39444585e-01], [ 1.09838392e-01], [ 3.64139322e+00], [-1.05169568e+00], [-1.50157642e+00], [ 4.03449534e+00], [ 1.68874724e+00], [ 7.22816119e-01], [-6.34751763e-01], [ 7.51521440e-01], [-1.12600116e+00], [ 7.48944967e-01], [ 3.74867074e+00], [ 2.58255917e+00], [ 2.06149839e-01], [ 8.73217943e-01], [ 2.44647765e+00], [ 2.25397961e+00], [ 2.11648591e+00], [-1.63342432e+00], [ 2.62752739e+00], [ 1.62604002e+00], [-2.57570131e+00], [ 2.73351849e+00], [ 1.81763095e+00], [ 3.83967512e+00], [ 1.67271924e+00], [-1.56438589e+00], [ 2.92059874e+00], [ 2.43464005e+00], [ 2.48854189e+00], [ 1.17332074e+00], [ 1.55276645e+00], [ 4.52825667e+00], [ 5.78074422e-01], [ 4.00163149e+00], [-2.50614596e+00], [ 3.28771095e+00], [ 3.41376314e+00], [ 2.82361216e+00], [ 3.05462334e+00], [-2.28616047e-01], [ 4.86858694e+00], [ 2.99551298e+00], [ 2.74418706e+00], [ 1.44841383e+00], [ 3.46473977e+00], [ 2.71548488e-01], [ 3.80262472e+00], [ 5.63144251e+00], [-5.94638629e-01], [ 2.39108545e+00], [ 1.17877822e+00], [ 2.73160954e+00], [-1.62015063e+00], [ 2.46028196e+00], [ 2.36365555e+00], [-3.81275183e-01], [-1.01128707e-01], [ 1.15657489e+00], [ 4.13134411e+00], [-1.18908778e+00], [ 1.01546598e+00], [ 1.14400757e+00], [ 2.95411656e+00], [-2.09412871e+00], [-5.41072606e+00], [ 4.03018872e-01], [ 1.76407404e+00], [-1.27132837e+00], [-1.33879947e+00], [-1.49193924e+00], [-2.27709058e+00], [ 4.75685173e-01], [ 1.75976497e+00], [-7.74033213e-02], [ 1.90840803e+00], [ 2.11089280e+00], [ 1.32877240e+00], [-5.42763140e-01], [ 3.81891977e+00], [-1.87887980e+00], [ 1.04451445e+00], [ 2.71181970e+00], [ 1.11227372e+00], [-1.69806707e-01], [ 1.95768617e+00], [-1.41250301e+00], [ 1.40693618e+00], [ 1.80760491e+00], [ 4.20105314e-01], [ 1.22255748e+00], [-2.18029260e-02], [ 2.59555652e+00], [-3.16633346e+00], [-2.33847651e+00], [ 5.84279905e+00], [-8.29269378e-01], [ 2.04342897e+00], [ 2.14326404e+00], [ 8.63692077e-01], [-1.37947454e+00], [-3.61449784e+00], [-1.34188818e+00], [-1.28748185e+00], [ 2.97668585e+00], [ 9.29810491e-01], [ 1.53962941e+00], [ 3.00437752e+00], [ 1.68597456e-02], [ 6.18088049e-01], [ 3.98252920e+00], [-1.03226779e-01], [-1.10940185e+00], [-2.82636327e+00], [ 1.94113966e+00], [ 3.71680070e+00], [ 2.66782272e+00], [ 3.31845323e+00], [-2.49075213e+00], [ 1.16154504e+00], [ 2.72517578e+00], [ 3.29460498e+00], [ 1.22538838e-01], [ 2.07034030e+00], [ 3.23919345e+00], [ 1.78111595e+00], [-5.66388055e-01], [-7.45591605e-01], [ 5.58196970e-01], [ 6.68901104e-01], [-2.29747204e+00], [ 7.05398132e-01], [-1.42447698e+00], [-7.61607068e-01], [-1.43612836e+00], [-2.91224315e+00], [-1.61574767e+00], [ 3.23396566e+00], [ 2.86977213e+00], [ 4.24038345e-01], [ 9.72332024e-01], [-3.88232896e+00], [ 3.01477660e+00], [-3.47011536e+00], [-1.52434089e+00], [ 1.67079113e+00], [-3.66128523e+00], [-1.03204232e+00], [ 2.33675390e-01], [ 2.35121431e+00], [-1.34766691e+00], [-3.54964993e+00], [-9.18406441e-01], [-2.82113199e+00], [ 2.46913155e+00], [ 4.36677087e+00], [-9.36511017e-01], [ 2.61344781e+00], [ 1.41224784e+00], [-1.09823313e+00], [-9.94503687e-02], [ 2.66385252e+00], [ 2.47617280e+00], [-9.45904852e-01], [ 1.02353708e+00], [ 2.00517892e+00], [-1.21412451e+00], [ 2.22043174e+00], [ 1.34117596e+00], [-6.11647542e-01], [-4.07851308e+00], [-3.11325302e-01], [ 6.08643618e+00], [ 2.25836939e+00], [-1.18318971e-01], [ 3.93114826e+00], [-9.63644678e-01], [ 5.83447050e-01], [ 2.61546121e+00], [ 3.01774511e-01], [ 2.54019198e+00], [ 1.18730709e+00], [ 8.56379837e-01], [ 2.81245229e+00], [ 4.77261849e-02], [-1.01230505e+00], [ 1.92517847e+00], [ 4.55029835e-01], [ 3.84224690e-01], [ 1.45460697e+00], [-6.34201517e-02], [ 2.67282354e+00], [ 5.44919923e+00], [ 1.63179539e+00], [ 1.83857870e+00], [ 1.24923218e+00], [ 3.99112136e-01], [ 4.89309106e-01], [ 1.49023944e+00], [-7.40720993e-01], [ 6.95888459e+00], [-1.26578412e+00], [ 2.31935826e+00], [-3.28472135e+00], [ 4.76654723e-01], [-8.46712159e-01], [ 1.83952724e+00], [-9.59176023e-01], [ 1.70729408e+00], [ 2.20814685e+00], [-4.59897086e-01], [-2.41579935e-01], [ 1.11864308e+00], [ 2.35809465e+00], [ 7.84339906e+00], [ 4.77946766e+00], [ 2.51378936e+00], [ 6.51677753e+00], [ 2.13078462e+00], [ 2.83205264e+00], [ 6.39504613e+00], [-4.43385435e-01], [-2.70602629e-01], [ 1.23741611e+00], [ 4.24307556e-01], [ 5.35061798e-01], [ 4.24684295e-01], [ 8.54938385e-01], [ 2.20077387e+00], [-1.79486285e-02], [ 1.54107841e+00], [ 1.82221864e+00], [ 1.92369361e+00], [ 4.15475631e-01], [-1.04355190e+00], [-4.61926899e-01], [ 3.08028863e+00], [ 1.65831915e+00], [-5.37022158e-01], [ 2.51466179e+00], [ 1.25508438e+00], [ 2.87651029e-01], [-2.47536171e-01], [ 8.78518129e-01], [ 1.06252269e+00], [ 2.08988292e+00], [ 2.11905231e+00], [ 1.42552778e+00], [ 1.66693994e+00], [ 4.38734576e-01], [ 5.45899509e-01], [ 2.19035950e+00], [ 2.43757428e+00], [ 1.78778813e+00], [ 1.06819915e+00], [ 2.86196260e+00], [ 3.73755145e+00], [ 1.96339020e+00], [-3.49255926e-01], [-3.75153070e-01], [-1.02260934e+00], [-3.08399221e+00], [ 4.11196954e-01], [ 5.44446026e+00], [ 6.50561416e-01], [ 1.95190676e+00], [ 2.16820399e+00], [ 1.78751833e-01], [-3.48122570e-01], [ 1.46565587e+00], [ 6.34552956e-02], [ 1.32848278e+00], [-1.59135652e+00], [ 3.74210606e+00], [ 3.72614819e+00], [ 6.98357140e-02], [-5.52300306e-01], [ 3.05436841e-01], [ 6.45376756e-01], [ 1.98371595e+00], [ 3.75676997e-01], [-3.21242008e+00], [ 2.92874202e+00], [-1.89674239e+00], [ 1.86990125e+00], [ 1.95611865e+00], [ 2.54687415e+00], [ 2.83938335e+00], [ 2.48105406e+00], [ 4.32349836e+00], [ 1.84542420e+00], [ 3.47917603e-01], [ 1.53776160e+00], [ 1.56849463e+00], [ 3.52577796e-01], [-8.94519761e-01], [ 6.57792314e+00], [ 1.68491732e+00], [-5.27633323e-01], [ 2.60337727e+00], [ 2.82244670e+00], [-3.34447319e+00], [-3.07823685e+00], [ 7.54169388e-01], [-1.87494577e-01], [ 2.33310953e+00], [-4.14459230e-01], [ 6.33076690e+00], [ 1.52261505e+00], [-1.35316736e+00], [ 9.58536198e-01], [ 4.11977116e+00], [ 1.00941198e+00], [ 1.70208909e-01], [ 5.61602147e-01], [ 1.01561313e+00], [ 6.54049595e-02], [ 1.14019662e+00], [-2.98671390e+00], [-3.00942406e+00], [ 2.30065577e+00], [-3.01810583e-01], [-2.35709041e+00], [ 1.12169208e+00], [ 5.32343974e+00], [ 3.82847993e-01], [ 1.14684643e+00], [-2.81826288e+00], [-2.56489561e+00], [ 1.46297091e-02], [ 2.57490819e+00], [ 1.28341409e+00], [ 2.53572131e+00], [ 6.00956970e-01], [-3.05267156e+00], [ 3.40979283e+00], [ 8.83274358e-01], [ 5.93248153e+00], [ 1.63633186e-01], [ 4.77357888e-01], [ 3.85187260e+00], [-2.09732484e+00], [-4.65063468e-01], [ 2.64464356e+00], [ 2.38659620e+00], [ 2.06435428e+00], [ 2.52026683e-01], [ 1.59495854e+00], [ 2.16216685e+00], [-9.20028595e-01], [ 3.41666245e-01], [ 6.57399039e+00], [ 2.45558140e+00], [ 2.48829589e+00], [-1.16511431e+00], [ 4.57811790e-01], [ 2.33733085e+00], [ 7.46526154e-01], [ 6.31321650e-01], [ 3.91751863e+00], [-1.41346540e+00], [ 2.54768044e+00], [ 1.19933335e+00], [-1.25785617e+00], [ 2.11182139e+00], [ 4.04152999e+00], [ 1.21583830e+00], [ 4.05208793e+00], [ 1.76939914e+00], [ 2.10921989e-02], [-2.36565971e+00], [ 2.10701379e+00], [-5.85022946e-01], [ 2.76969459e+00], [-1.62791705e+00], [ 7.41530543e-01], [ 2.56108638e+00], [ 1.96360832e+00], [ 6.49442491e-01], [ 5.71329451e-01], [ 5.16323561e+00], [ 2.51275613e+00], [-5.24960265e-01], [ 1.64094620e+00], [ 1.93005513e+00], [-1.65839392e+00], [-5.03079325e-01], [-2.16696112e+00], [ 7.27521218e+00], [-1.96484945e-01], [ 5.02508280e-01], [-1.32500629e+00], [ 2.10903871e+00], [ 1.34463442e+00], [-3.77168686e-01], [-2.08657927e-01], [ 6.26816941e-01], [ 2.74711038e+00], [ 2.02261606e+00], [-4.98472449e+00], [-1.34004210e+00], [ 2.33193892e+00], [ 1.91379319e+00], [ 1.47356107e+00], [ 1.49850166e-01], [ 2.74019604e+00], [ 1.17755999e+00], [ 3.69658474e+00], [-2.20772083e+00], [ 2.98071340e+00], [-2.41805122e+00], [ 3.11279168e+00], [-4.33001087e-01], [ 3.81771246e+00], [-1.40634777e+00], [ 3.12442311e+00], [ 8.49133739e-01], [ 1.36833696e+00], [ 2.11127124e+00], [ 6.58397881e-01], [-1.89743325e+00], [ 2.08002102e-01], [-5.98779358e-01], [-1.21717190e+00], [-4.18216722e-01], [ 4.60402497e+00], [-1.84812630e+00], [-2.76083847e+00], [-8.32884973e-01], [-3.13053895e+00], [ 2.31058784e+00], [-1.77147497e+00], [-1.60297896e+00], [-1.88594329e+00], [ 1.18898325e+00], [ 2.32545163e+00], [ 1.89873211e+00], [-8.40200957e-02], [-1.52857110e+00], [ 6.78982844e+00], [ 9.31413227e-01], [-5.21381025e-01], [ 1.62069508e+00], [ 7.35373012e-01], [ 2.49501148e+00], [-1.13439637e+00], [ 3.14637971e+00], [-6.42824707e-01], [-5.09723911e-01], [ 1.60481282e+00], [ 5.19790492e-01], [-3.21731354e+00], [-5.00452787e-01], [ 1.52440878e-02], [ 6.67595991e+00], [-5.22443008e-01], [-1.60741122e+00], [ 3.96924887e+00], [-2.42547253e+00], [-2.68741923e+00], [ 3.48249457e+00], [ 2.33561305e+00], [-4.12070329e+00], [ 3.20089005e+00], [ 3.54874643e+00], [ 1.63705208e+00], [ 2.11435341e+00], [ 3.26242785e+00], [ 7.55824795e-01], [ 2.07096126e+00], [-2.35006796e+00], [-1.00797369e+00], [ 3.21679075e+00], [ 9.08172635e-01], [-3.89149050e-01], [ 7.07396078e-02], [-4.19432410e+00], [ 1.54277565e+00], [ 3.01532337e+00], [ 4.46649989e+00], [ 2.65001697e+00], [ 5.35769543e+00], [ 8.73269520e-01], [-1.40343934e+00], [-5.31634906e-01], [ 2.46422762e+00], [-2.64200203e+00], [ 4.02897889e+00], [ 2.29715642e+00], [ 1.86058110e+00], [ 5.11789217e+00], [-3.08494388e-01], [ 4.36254249e+00], [ 1.59550116e+00], [-2.10391520e-01], [ 3.11772223e-01], [ 1.35682039e+00], [-2.86795425e-01], [-1.49942765e+00], [ 1.17640415e+00], [ 8.58882277e-01], [ 2.81513689e+00], [ 1.09835538e+00], [ 2.46511970e+00], [-2.74500736e+00], [ 1.48075535e+00], [ 6.17465592e-01], [ 2.52049370e+00], [ 1.15887332e+00], [ 1.82655402e+00], [-2.76970823e+00], [ 3.22673730e+00], [ 7.76495385e-01], [ 3.30718504e+00], [-2.97989837e-01], [ 3.58632866e+00], [ 1.87703663e+00], [ 3.11671812e-02], [ 1.46776207e+00], [ 1.31409634e+00], [ 3.45327292e+00], [ 1.41622429e+00], [ 2.14713946e+00], [ 1.73094931e+00], [ 3.94437470e+00], [ 4.83190388e-02], [ 3.38568829e-01], [-2.68868455e+00], [-8.89632678e-01], [-1.02672418e+00], [-3.83610690e+00], [ 1.87106110e+00], [-2.35051657e+00], [ 5.56819996e+00], [-1.95415983e+00], [ 3.03438379e-01], [ 3.71014694e+00], [ 2.80631812e+00], [-3.20896022e-01], [ 3.15452703e+00], [ 1.93875829e+00], [-4.15072607e-01], [-1.02115203e+00], [ 2.33607296e+00], [ 3.50716988e+00], [ 5.12989863e-01], [ 1.08365959e-01], [ 1.04589546e+00], [ 8.51332679e-01], [-3.98632851e+00], [-1.99704450e+00], [ 3.46896323e+00], [-4.70341250e-01], [ 3.11987211e+00], [ 2.09258836e+00], [-2.94302996e+00], [-1.50927045e+00], [ 1.32009294e-01], [-2.22951523e+00], [ 3.27350873e+00], [ 4.73481780e+00], [ 1.51273701e+00], [ 1.05147244e+00], [ 1.82928230e-01], [-1.14000649e+00], [ 7.41701928e-01], [-2.19211988e+00], [ 1.79034171e+00], [-7.36142247e-01], [-3.76513636e+00], [-1.80631938e+00], [ 1.77196298e+00], [-9.76045925e-01], [ 1.47250765e+00], [ 5.73079950e-01], [-2.23568658e-01], [ 3.08578684e+00], [-2.78847219e-01], [ 2.74027071e+00], [-3.40303390e+00], [ 1.25330411e+00], [ 2.91451046e+00], [ 1.99014228e+00], [ 3.35589562e+00], [ 3.83148211e+00], [ 2.18924817e+00], [-2.94282450e+00], [ 4.21435630e+00], [ 2.60034650e+00], [ 2.12726697e+00], [ 7.40044022e-01], [ 5.30294259e-01], [-1.37718287e+00], [ 1.38921930e+00], [-1.68488186e+00], [-1.00027476e+00], [-1.76677319e+00], [-4.04011878e+00], [ 8.12756454e-01], [ 1.30893165e+00], [ 2.69676338e+00], [ 4.10810865e+00], [-2.26189260e-01], [ 1.96606430e+00], [-7.98173247e-01], [-2.74620048e-01], [-6.95478329e+00], [ 1.87770945e+00], [-1.16282889e+00], [-2.04573290e+00], [-1.13032909e+00], [ 1.33080417e+00], [-1.81078975e+00], [-9.82182112e-01], [ 2.23416087e+00], [ 4.09214464e+00], [ 1.74483002e+00], [-2.21770203e-01], [ 1.12091102e+00], [ 3.86606456e+00], [-1.58483361e-02], [-2.73311184e+00], [ 1.51281237e+00], [ 5.92111715e-01], [ 3.60413258e+00], [-1.36158213e+00], [ 9.49817897e-01], [ 4.61773127e+00], [ 7.90640495e-02], [ 2.48143728e-01], [ 8.50081942e-01], [ 1.11910655e+00], [ 2.97871299e-01], [-3.46691929e+00], [ 5.02261405e+00], [ 3.96790211e+00], [ 4.23146055e+00], [ 1.71825848e-01], [ 2.10574866e+00], [-4.55357257e+00], [ 1.76450558e+00], [ 1.66022601e+00], [ 1.61947280e+00], [-1.59330523e-01], [-2.73784541e+00], [-2.22694846e+00], [ 1.11437758e+00], [ 3.66176324e-01], [ 2.03635512e+00], [ 1.37762555e-01], [ 1.07467467e+00], [ 1.33283062e-01], [ 9.93695225e-01], [-5.91531437e-01], [-1.45369605e-01], [ 2.73958715e+00], [ 1.45372956e+00], [ 2.19546051e+00], [ 9.18606788e-01], [ 1.79747960e+00], [ 1.80057133e-02], [-1.91130500e+00], [ 2.58964009e+00], [ 4.21862944e+00], [ 3.58455139e+00], [ 4.05356147e+00], [ 1.51454162e+00], [-1.07950757e+00], [-1.43865535e+00], [-3.04653888e-01], [-2.24631976e+00], [ 1.43144942e+00], [-9.65822041e-01], [ 1.50367271e+00], [ 1.88906094e-02], [ 3.64213233e+00], [-1.77048156e+00], [-1.64299475e+00], [ 2.42069800e+00], [ 2.81761728e+00], [ 2.37105985e+00], [ 2.16294371e+00], [-2.51875726e+00], [ 1.15188759e+00], [-3.08510432e-02], [ 1.05342085e+00], [ 2.38626308e+00], [ 1.13805690e+00], [ 6.04508755e+00], [ 2.52874559e+00], [ 5.39487473e-01], [ 3.30250779e+00], [ 3.85485138e+00], [ 3.85768764e+00], [ 2.98756599e+00], [ 1.71369845e+00], [-3.14519879e-01], [ 1.29903948e+00], [ 7.88163088e-01], [ 4.53823407e+00], [ 5.77724040e-03], [ 6.95407528e-03], [ 2.75285188e+00], [ 4.18824718e+00], [-2.43215391e+00], [ 2.62726836e+00], [ 1.67977833e+00], [ 8.79947998e-01], [-6.98900731e-02], [-5.20447357e-01], [-1.60914205e+00], [-7.24018019e-01], [-1.05821032e+00], [ 2.42607124e+00], [ 1.21895237e+00], [-2.46373726e+00], [ 3.39907905e+00], [ 6.60875200e-01], [ 1.69369973e-01], [-6.66505211e-01], [ 6.03827631e-02], [ 1.54007759e-02], [ 1.65414865e+00], [-3.24379610e+00], [-1.21583509e+00], [ 1.85350469e-01], [ 1.68406528e+00], [ 4.91661796e+00], [ 1.07929682e+00], [ 1.28981330e+00], [ 2.50147058e+00], [ 2.06884263e+00], [ 9.07476096e-01], [-3.75518489e+00], [ 2.35691779e+00], [ 1.81971418e+00], [ 2.86124682e+00], [ 2.53832580e+00], [ 4.96767094e+00], [ 4.04579459e-01], [-1.12566438e+00], [-9.16263032e-01], [ 3.47331018e+00], [-4.40817058e+00], [ 5.05277146e+00], [ 3.59057816e+00], [-3.08651180e-01], [ 2.86320305e-01], [ 2.34678258e+00], [-4.24171089e+00], [ 7.20566525e-02], [ 2.56502597e+00], [ 2.01641975e+00], [-2.03138281e+00], [ 1.25091713e+00], [ 9.09871858e-01], [ 2.55394518e-01], [ 2.08358947e+00], [-4.19966391e-01], [-2.02377090e+00], [-2.25050521e+00], [ 4.85583297e-01], [ 1.06775227e+00], [ 1.29012223e+00], [-2.91117272e-01], [-2.24742821e+00], [ 2.87265527e+00], [ 2.32944688e+00], [-3.10336299e+00], [ 2.94733809e+00], [ 6.39731479e+00], [ 3.64393742e+00], [ 1.22905497e+00], [ 5.64488522e-01], [-2.43880725e+00], [ 4.28727454e-01], [ 1.66288461e-01], [ 7.36256983e-01], [-3.32790940e-01], [-8.82364820e-02], [ 3.17444216e+00], [-4.36868432e+00], [ 1.44639120e+00], [-1.32101634e+00], [-6.34419616e-01], [ 1.95256236e-01], [ 2.96996621e+00], [ 1.22269644e+00], [-3.20247095e+00], [ 1.24065001e+00], [ 6.50235699e-01], [-9.63347316e-01], [-1.66249268e+00], [ 4.64838373e-01], [ 3.10492578e+00], [ 1.57883393e+00], [ 1.64811766e+00], [ 6.58018598e+00], [ 1.98434719e+00], [-2.78029188e+00], [ 1.18938127e+00], [ 3.43873061e+00], [ 2.24020974e+00], [ 2.72188642e+00], [-1.60275854e-01], [ 2.00594376e+00], [-4.37689483e+00], [-1.44656646e+00], [ 3.97977377e+00], [ 4.48549256e+00], [-1.95866217e+00], [ 1.76003022e+00], [ 3.78536795e+00], [ 4.60302833e-01], [-5.10500470e-01], [-1.39298772e+00], [-7.04491448e-01], [-1.31540843e+00], [ 3.24366072e+00], [ 3.94819583e+00], [-7.08927310e-01], [ 2.03650766e+00], [ 3.74507677e+00], [ 3.04133369e+00], [ 7.54220266e-01], [-3.47147666e+00], [ 1.40511750e+00], [ 9.07047712e-04], [ 2.44966738e+00], [ 8.93410687e-01], [-2.76632684e+00], [-1.95796817e+00], [ 4.42884605e+00], [ 2.73463398e+00], [-7.74556174e-01], [ 3.15699179e-01], [ 3.22893096e+00], [ 2.40957056e+00], [ 5.13706294e+00], [ 4.47863463e-01], [ 3.71562729e+00], [ 8.27948908e-01], [-8.73987904e-01], [ 3.74304202e+00], [ 5.91231664e-01], [-3.53510945e+00], [ 1.52521471e+00], [ 1.93297524e+00], [ 2.89669390e+00], [-9.65177028e-01], [-2.55349429e+00], [ 1.49090337e+00], [ 3.89415463e+00], [ 4.20237508e-01], [ 5.41346572e+00], [ 1.05596432e+00], [-3.24395355e-01], [ 1.70367647e+00], [-1.19182248e+00], [-1.56472179e+00], [ 2.12709647e+00], [ 3.46786521e+00], [-1.19252821e+00], [ 9.69363969e-01], [ 6.85313754e-01], [ 1.22748869e+00], [ 4.75694125e+00], [ 3.08310174e+00], [ 2.11709542e+00], [ 3.05136435e+00], [ 2.52074703e+00], [ 1.57451671e-01], [-9.41994649e-01], [-3.65053976e+00], [ 5.02667946e-01], [ 2.01476493e+00], [ 5.71717849e+00], [ 3.65513637e+00], [ 4.28095996e+00], [ 1.40348849e+00], [-4.48162642e-01], [ 2.35781297e+00], [-1.20038168e+00], [-7.43703458e-01], [-1.28782103e+00], [ 2.23197079e+00], [ 1.37552593e+00], [ 1.37532793e+00], [ 2.48169242e+00], [-1.00415305e-01], [ 2.46094543e+00], [-1.39435076e+00], [-8.20013382e-01], [ 5.38920699e-01], [ 2.67282914e-01], [ 4.67624294e-01], [ 5.46013491e-01], [ 1.97485360e+00], [-3.41825721e-01], [-1.57550571e+00], [-9.05819443e-02], [ 2.69799684e+00], [-1.39432137e+00], [ 1.06055643e+00], [-3.73873741e-01], [ 1.13747019e+00], [ 2.57508275e+00], [ 6.14317653e+00], [-5.57415569e-01], [ 1.23692156e+00], [-2.44608994e-01], [-1.02182456e+00], [ 2.95144637e+00], [ 3.15264046e+00], [ 1.77884778e+00], [ 3.49835092e+00], [ 6.54833379e-01], [-2.01736932e+00], [-5.34145353e-01], [-3.86659354e+00], [ 1.30603964e+00], [ 1.75233823e+00], [ 2.11602346e+00], [ 4.66955947e-01], [ 9.79511709e-01], [-3.08840524e+00], [ 6.20766067e+00], [ 2.46773674e+00], [-1.25808951e+00], [ 7.70858382e-01], [ 1.35438550e+00], [ 1.69438858e+00], [ 2.33028404e-01], [-2.23458097e-01], [ 2.69561611e+00], [-1.11481705e+00]]))
至此就完成了自定义模块的编写与保存,后续我们还将陆续写入其他函数。