吉首自治州住房和城乡建设局网站阅读网站怎么做

news/2025/9/23 8:40:32/文章来源:
吉首自治州住房和城乡建设局网站,阅读网站怎么做,徐州seo推广公司,怎么开电商网店Overfitting and Regularization 1. 过拟合添加正则化2. 具有正则化的损失函数2.1 正则化线性回归的损失函数2.2 正则化逻辑回归的损失函数 3. 具有正则化的梯度下降3.1 使用正则化计算梯度#xff08;线性回归 / 逻辑回归#xff09;3.2 正则化线性回归的梯度函数3.3 正则化… Overfitting and Regularization 1. 过拟合添加正则化2. 具有正则化的损失函数2.1 正则化线性回归的损失函数2.2 正则化逻辑回归的损失函数 3. 具有正则化的梯度下降3.1 使用正则化计算梯度线性回归 / 逻辑回归3.2 正则化线性回归的梯度函数3.3 正则化逻辑回归的梯度函数 4. 重新运行过拟合示例附录 导入所需的库 import numpy as np %matplotlib inline import matplotlib.pyplot as plt from ipywidgets import Output from plt_overfit import overfit_example, output from lab_utils_common import sigmoid plt.style.use(./deeplearning.mplstyle) np.set_printoptions(precision8)1. 过拟合 plt.close(all) display(output) ofit overfit_example(False)从图中可以看出拟合度 1的数据为“欠拟合”。拟合度 6的数据为“过拟合” 添加正则化 线性回归和逻辑回归之间的损失函数存在差异但在方程中添加正则化是相同的。 线性回归和逻辑回归的梯度函数非常相似。它们的区别仅在于 f w b f_{wb} fwb​ 的实现。 2. 具有正则化的损失函数 2.1 正则化线性回归的损失函数 正则化线性回归的损失函数等式表示为 J ( w , b ) 1 2 m ∑ i 0 m − 1 ( f w , b ( x ( i ) ) − y ( i ) ) 2 λ 2 m ∑ j 0 n − 1 w j 2 (1) J(\mathbf{w},b) \frac{1}{2m} \sum\limits_{i 0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)})^2 \frac{\lambda}{2m} \sum_{j0}^{n-1} w_j^2 \tag{1} J(w,b)2m1​i0∑m−1​(fw,b​(x(i))−y(i))22mλ​j0∑n−1​wj2​(1) 其中 f w , b ( x ( i ) ) w ⋅ x ( i ) b (2) f_{\mathbf{w},b}(\mathbf{x}^{(i)}) \mathbf{w} \cdot \mathbf{x}^{(i)} b \tag{2} fw,b​(x(i))w⋅x(i)b(2) 与没有正则化的线性回归相比区别在于正则化项即 λ 2 m ∑ j 0 n − 1 w j 2 \frac{\lambda}{2m} \sum_{j0}^{n-1} w_j^2 2mλ​∑j0n−1​wj2​ 带有正则化可以激励梯度下降最小化参数的大小。需要注意的是在这个例子中参数 b b b没有被正则化这是标准做法。 等式(1)和(2)的实现如下 def compute_cost_linear_reg(X, y, w, b, lambda_ 1):Computes the cost over all examplesArgs:X (ndarray (m,n): Data, m examples with n featuresy (ndarray (m,)): target valuesw (ndarray (n,)): model parameters b (scalar) : model parameterlambda_ (scalar): Controls amount of regularizationReturns:total_cost (scalar): cost m X.shape[0]n len(w)cost 0.for i in range(m):f_wb_i np.dot(X[i], w) b #(n,)(n,)scalar, see np.dotcost cost (f_wb_i - y[i])**2 #scalar cost cost / (2 * m) #scalar reg_cost 0for j in range(n):reg_cost (w[j]**2) #scalarreg_cost (lambda_/(2*m)) * reg_cost #scalartotal_cost cost reg_cost #scalarreturn total_cost #scalarnp.random.seed(1) X_tmp np.random.rand(5,6) y_tmp np.array([0,1,0,1,0]) w_tmp np.random.rand(X_tmp.shape[1]).reshape(-1,)-0.5 b_tmp 0.5 lambda_tmp 0.7 cost_tmp compute_cost_linear_reg(X_tmp, y_tmp, w_tmp, b_tmp, lambda_tmp)print(Regularized cost:, cost_tmp)2.2 正则化逻辑回归的损失函数 对于正则化的逻辑回归损失函数表示为 J ( w , b ) 1 m ∑ i 0 m − 1 [ − y ( i ) log ⁡ ( f w , b ( x ( i ) ) ) − ( 1 − y ( i ) ) log ⁡ ( 1 − f w , b ( x ( i ) ) ) ] λ 2 m ∑ j 0 n − 1 w j 2 (3) J(\mathbf{w},b) \frac{1}{m} \sum_{i0}^{m-1} \left[ -y^{(i)} \log\left(f_{\mathbf{w},b}\left( \mathbf{x}^{(i)} \right) \right) - \left( 1 - y^{(i)}\right) \log \left( 1 - f_{\mathbf{w},b}\left( \mathbf{x}^{(i)} \right) \right) \right] \frac{\lambda}{2m} \sum_{j0}^{n-1} w_j^2 \tag{3} J(w,b)m1​i0∑m−1​[−y(i)log(fw,b​(x(i)))−(1−y(i))log(1−fw,b​(x(i)))]2mλ​j0∑n−1​wj2​(3) 其中 f w , b ( x ( i ) ) s i g m o i d ( w ⋅ x ( i ) b ) (4) f_{\mathbf{w},b}(\mathbf{x}^{(i)}) sigmoid(\mathbf{w} \cdot \mathbf{x}^{(i)} b) \tag{4} fw,b​(x(i))sigmoid(w⋅x(i)b)(4) 同样与没有正则化的逻辑回归相比区别在于正则化项即 λ 2 m ∑ j 0 n − 1 w j 2 \frac{\lambda}{2m} \sum_{j0}^{n-1} w_j^2 2mλ​∑j0n−1​wj2​ 代码实现为 def compute_cost_logistic_reg(X, y, w, b, lambda_ 1):Computes the cost over all examplesArgs:Args:X (ndarray (m,n): Data, m examples with n featuresy (ndarray (m,)): target valuesw (ndarray (n,)): model parameters b (scalar) : model parameterlambda_ (scalar): Controls amount of regularizationReturns:total_cost (scalar): cost m,n X.shapecost 0.for i in range(m):z_i np.dot(X[i], w) b #(n,)(n,)scalar, see np.dotf_wb_i sigmoid(z_i) #scalarcost -y[i]*np.log(f_wb_i) - (1-y[i])*np.log(1-f_wb_i) #scalarcost cost/m #scalarreg_cost 0for j in range(n):reg_cost (w[j]**2) #scalarreg_cost (lambda_/(2*m)) * reg_cost #scalartotal_cost cost reg_cost #scalarreturn total_cost #scalarnp.random.seed(1) X_tmp np.random.rand(5,6) y_tmp np.array([0,1,0,1,0]) w_tmp np.random.rand(X_tmp.shape[1]).reshape(-1,)-0.5 b_tmp 0.5 lambda_tmp 0.7 cost_tmp compute_cost_logistic_reg(X_tmp, y_tmp, w_tmp, b_tmp, lambda_tmp)print(Regularized cost:, cost_tmp)3. 具有正则化的梯度下降 运行梯度下降的基本算法不会随着正则化发生改变正则化改变的是计算梯度。 3.1 使用正则化计算梯度线性回归 / 逻辑回归 线性回归和逻辑回归的梯度计算几乎相同只是在 f w b f_{\mathbf{w}b} fwb​的计算上有所不同。 ∂ J ( w , b ) ∂ w j 1 m ∑ i 0 m − 1 ( f w , b ( x ( i ) ) − y ( i ) ) x j ( i ) λ m w j ∂ J ( w , b ) ∂ b 1 m ∑ i 0 m − 1 ( f w , b ( x ( i ) ) − y ( i ) ) \begin{align*} \frac{\partial J(\mathbf{w},b)}{\partial w_j} \frac{1}{m} \sum\limits_{i 0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)})x_{j}^{(i)} \frac{\lambda}{m} w_j \tag{2} \\ \frac{\partial J(\mathbf{w},b)}{\partial b} \frac{1}{m} \sum\limits_{i 0}^{m-1} (f_{\mathbf{w},b}(\mathbf{x}^{(i)}) - y^{(i)}) \tag{3} \end{align*} ∂wj​∂J(w,b)​∂b∂J(w,b)​​m1​i0∑m−1​(fw,b​(x(i))−y(i))xj(i)​mλ​wj​m1​i0∑m−1​(fw,b​(x(i))−y(i))​(2)(3)​ 对于线性回归模型 f w , b ( x ) w ⋅ x b f_{\mathbf{w},b}(x) \mathbf{w} \cdot \mathbf{x} b fw,b​(x)w⋅xb对于逻辑回归模型 z w ⋅ x b z \mathbf{w} \cdot \mathbf{x} b zw⋅xb f w , b ( x ) g ( z ) f_{\mathbf{w},b}(x) g(z) fw,b​(x)g(z) 其中 g ( z ) g(z) g(z) 是sigmoid 函数: g ( z ) 1 1 e − z g(z) \frac{1}{1e^{-z}} g(z)1e−z1​ 添加正则化的项是 λ m w j \frac{\lambda}{m} w_j mλ​wj​ 3.2 正则化线性回归的梯度函数 def compute_gradient_linear_reg(X, y, w, b, lambda_): Computes the gradient for linear regression Args:X (ndarray (m,n): Data, m examples with n featuresy (ndarray (m,)): target valuesw (ndarray (n,)): model parameters b (scalar) : model parameterlambda_ (scalar): Controls amount of regularizationReturns:dj_dw (ndarray (n,)): The gradient of the cost w.r.t. the parameters w. dj_db (scalar): The gradient of the cost w.r.t. the parameter b. m,n X.shape #(number of examples, number of features)dj_dw np.zeros((n,))dj_db 0.for i in range(m): err (np.dot(X[i], w) b) - y[i] for j in range(n): dj_dw[j] dj_dw[j] err * X[i, j] dj_db dj_db err dj_dw dj_dw / m dj_db dj_db / m for j in range(n):dj_dw[j] dj_dw[j] (lambda_/m) * w[j]return dj_db, dj_dwnp.random.seed(1) X_tmp np.random.rand(5,3) y_tmp np.array([0,1,0,1,0]) w_tmp np.random.rand(X_tmp.shape[1]) b_tmp 0.5 lambda_tmp 0.7 dj_db_tmp, dj_dw_tmp compute_gradient_linear_reg(X_tmp, y_tmp, w_tmp, b_tmp, lambda_tmp)print(fdj_db: {dj_db_tmp}, ) print(fRegularized dj_dw:\n {dj_dw_tmp.tolist()}, )3.3 正则化逻辑回归的梯度函数 def compute_gradient_logistic_reg(X, y, w, b, lambda_): Computes the gradient for linear regression Args:X (ndarray (m,n): Data, m examples with n featuresy (ndarray (m,)): target valuesw (ndarray (n,)): model parameters b (scalar) : model parameterlambda_ (scalar): Controls amount of regularizationReturnsdj_dw (ndarray Shape (n,)): The gradient of the cost w.r.t. the parameters w. dj_db (scalar) : The gradient of the cost w.r.t. the parameter b. m,n X.shapedj_dw np.zeros((n,)) #(n,)dj_db 0.0 #scalarfor i in range(m):f_wb_i sigmoid(np.dot(X[i],w) b) #(n,)(n,)scalarerr_i f_wb_i - y[i] #scalarfor j in range(n):dj_dw[j] dj_dw[j] err_i * X[i,j] #scalardj_db dj_db err_idj_dw dj_dw/m #(n,)dj_db dj_db/m #scalarfor j in range(n):dj_dw[j] dj_dw[j] (lambda_/m) * w[j]return dj_db, dj_dw np.random.seed(1) X_tmp np.random.rand(5,3) y_tmp np.array([0,1,0,1,0]) w_tmp np.random.rand(X_tmp.shape[1]) b_tmp 0.5 lambda_tmp 0.7 dj_db_tmp, dj_dw_tmp compute_gradient_logistic_reg(X_tmp, y_tmp, w_tmp, b_tmp, lambda_tmp)print(fdj_db: {dj_db_tmp}, ) print(fRegularized dj_dw:\n {dj_dw_tmp.tolist()}, )4. 重新运行过拟合示例 plt.close(all) display(output) ofit overfit_example(True)以分类任务(逻辑回归)为例将拟合度设置为6, λ \lambda λ为0(没有正则化)开始拟合数据出现了过拟合现象。 现在将 λ \lambda λ为1(增加正则化)开始拟合数据。 很明显增加正则化能够减小过拟合。 附录 plot_overfit.py 源码 plot_overfitclass and assocaited routines that plot an interactive example of overfitting and its solutionsimport math from ipywidgets import Output from matplotlib.gridspec import GridSpec from matplotlib.widgets import Button, CheckButtons from sklearn.linear_model import LogisticRegression, Ridge from lab_utils_common import np, plt, dlc, predict_logistic, plot_data, zscore_normalize_featuresdef map_one_feature(X1, degree):Feature mapping function to polynomial featuresX1 np.atleast_1d(X1)out []string k 0for i in range(1, degree1):out.append((X1**i))string string fw_{{{k}}}{munge(x_0,i)} k 1string string b #add b to text equation, not to datareturn np.stack(out, axis1), stringdef map_feature(X1, X2, degree):Feature mapping function to polynomial featuresX1 np.atleast_1d(X1)X2 np.atleast_1d(X2)out []string k 0for i in range(1, degree1):for j in range(i 1):out.append((X1**(i-j) * (X2**j)))string string fw_{{{k}}}{munge(x_0,i-j)}{munge(x_1,j)} k 1#print(string b)return np.stack(out, axis1), string bdef munge(base, exp):if exp 0:return if exp 1:return basereturn base f^{{{exp}}}def plot_decision_boundary(ax, x0r,x1r, predict, w, b, scaler False, muNone, sigmaNone, degreeNone):Plots a decision boundaryArgs:x0r : (array_like Shape (1,1)) range (min, max) of x0x1r : (array_like Shape (1,1)) range (min, max) of x1predict : function to predict z valuesscalar : (boolean) scale data or noth .01 # step size in the mesh# create a mesh to plot inxx, yy np.meshgrid(np.arange(x0r[0], x0r[1], h),np.arange(x1r[0], x1r[1], h))# Plot the decision boundary. For that, we will assign a color to each# point in the mesh [x_min, m_max]x[y_min, y_max].points np.c_[xx.ravel(), yy.ravel()]Xm,_ map_feature(points[:, 0], points[:, 1],degree)if scaler:Xm (Xm - mu)/sigmaZ predict(Xm, w, b)# Put the result into a color plotZ Z.reshape(xx.shape)contour ax.contour(xx, yy, Z, levels [0.5], colorsg)return contour# use this to test the above routine def plot_decision_boundary_sklearn(x0r, x1r, predict, degree, scaler False):Plots a decision boundaryArgs:x0r : (array_like Shape (1,1)) range (min, max) of x0x1r : (array_like Shape (1,1)) range (min, max) of x1degree: (int) degree of polynomialpredict : function to predict z valuesscaler : not sureh .01 # step size in the mesh# create a mesh to plot inxx, yy np.meshgrid(np.arange(x0r[0], x0r[1], h),np.arange(x1r[0], x1r[1], h))# Plot the decision boundary. For that, we will assign a color to each# point in the mesh [x_min, m_max]x[y_min, y_max].points np.c_[xx.ravel(), yy.ravel()]Xm map_feature(points[:, 0], points[:, 1],degree)if scaler:Xm scaler.transform(Xm)Z predict(Xm)# Put the result into a color plotZ Z.reshape(xx.shape)plt.contour(xx, yy, Z, colorsg)#plot_data(X_train,y_train)#for debug, uncomment the #output statments below for routines you want to get error output from # In the notebook that will call these routines, import output # from plt_overfit import overfit_example, output # then, in a cell where the error messages will be the output of.. #display(output)output Output() # sends hidden error messages to display when using widgetsclass button_manager: Handles some missing features of matplotlib check buttonson init:creates button, links to button_click routine,calls call_on_click with active index and firsttimeTrueon click:maintains single button on state, calls call_on_clickoutput.capture() # debugdef __init__(self,fig, dim, labels, init, call_on_click):dim: (list) [leftbottom_x,bottom_y,width,height]labels: (list) for example [1,2,3,4,5,6]init: (list) for example [True, False, False, False, False, False]self.fig figself.ax plt.axes(dim) #lx,by,w,hself.init_state initself.call_on_click call_on_clickself.button CheckButtons(self.ax,labels,init)self.button.on_clicked(self.button_click)self.status self.button.get_status()self.call_on_click(self.status.index(True),firsttimeTrue)output.capture() # debugdef reinit(self):self.status self.init_stateself.button.set_active(self.status.index(True)) #turn off old, will trigger update and set to statusoutput.capture() # debugdef button_click(self, event): maintains one-on state. If on-button is clicked, will process correctly #new_status self.button.get_status()#new [self.status[i] ^ new_status[i] for i in range(len(self.status))]#newidx new.index(True)self.button.eventson Falseself.button.set_active(self.status.index(True)) #turn off old or reenable if sameself.button.eventson Trueself.status self.button.get_status()self.call_on_click(self.status.index(True))class overfit_example(): plot overfit example # pylint: disabletoo-many-instance-attributes# pylint: disabletoo-many-locals# pylint: disablemissing-function-docstring# pylint: disableattribute-defined-outside-initdef __init__(self, regularizeFalse):self.regularizeregularizeself.lambda_0fig plt.figure( figsize(8,6))fig.canvas.toolbar_visible Falsefig.canvas.header_visible Falsefig.canvas.footer_visible Falsefig.set_facecolor(#ffffff) #whitegs GridSpec(5, 3, figurefig)ax0 fig.add_subplot(gs[0:3, :])ax1 fig.add_subplot(gs[-2, :])ax2 fig.add_subplot(gs[-1, :])ax1.set_axis_off()ax2.set_axis_off()self.ax [ax0,ax1,ax2]self.fig figself.axfitdata plt.axes([0.26,0.124,0.12,0.1 ]) #lx,by,w,hself.bfitdata Button(self.axfitdata , fit data, colordlc[dlblue])self.bfitdata.label.set_fontsize(12)self.bfitdata.on_clicked(self.fitdata_clicked)#clear data is a future enhancement#self.axclrdata plt.axes([0.26,0.06,0.12,0.05 ]) #lx,by,w,h#self.bclrdata Button(self.axclrdata , clear data, colorwhite)#self.bclrdata.label.set_fontsize(12)#self.bclrdata.on_clicked(self.clrdata_clicked)self.cid fig.canvas.mpl_connect(button_press_event, self.add_data)self.typebut button_manager(fig, [0.4, 0.07,0.15,0.15], [Regression, Categorical],[False,True], self.toggle_type)self.fig.text(0.1, 0.020.21, Degree, fontsize12)self.degrbut button_manager(fig,[0.1,0.02,0.15,0.2 ], [1,2,3,4,5,6],[True, False, False, False, False, False], self.update_equation)if self.regularize:self.fig.text(0.6, 0.020.21, rlambda($\lambda$), fontsize12)self.lambut button_manager(fig,[0.6,0.02,0.15,0.2 ], [0.0,0.2,0.4,0.6,0.8,1],[True, False, False, False, False, False], self.updt_lambda)#self.regbut button_manager(fig, [0.8, 0.08,0.24,0.15], [Regularize],# [False], self.toggle_reg)#self.logistic_data()def updt_lambda(self, idx, firsttimeFalse):# pylint: disableunused-argumentself.lambda_ idx * 0.2def toggle_type(self, idx, firsttimeFalse):self.logistic idx1self.ax[0].clear()if self.logistic:self.logistic_data()else:self.linear_data()if not firsttime:self.degrbut.reinit()output.capture() # debugdef logistic_data(self,redrawFalse):if not redraw:m 50n 2np.random.seed(2)X_train 2*(np.random.rand(m,n)-[0.5,0.5])y_train X_train[:,1]0.5 X_train[:,0]**2 0.5*np.random.rand(m) #quadratic randomy_train y_train 0 #convert from boolean to integerself.X X_trainself.y y_trainself.x_ideal np.sort(X_train[:,0])self.y_ideal self.x_ideal**2self.ax[0].plot(self.x_ideal, self.y_ideal, --, color orangered, labelideal, lw1)plot_data(self.X, self.y, self.ax[0], s10, loclower right)self.ax[0].set_title(OverFitting Example: Categorical data set with noise)self.ax[0].text(0.5,0.93, Click on plot to add data. Hold [Shift] for blue(y0) data.,fontsize12, hacenter,transformself.ax[0].transAxes, colordlc[dlblue])self.ax[0].set_xlabel(r$x_0$)self.ax[0].set_ylabel(r$x_1$)def linear_data(self,redrawFalse):if not redraw:m 30c 0x_train np.arange(0,m,1)np.random.seed(1)y_ideal x_train**2 cy_train y_ideal 0.7 * y_ideal*(np.random.sample((m,))-0.5)self.x_ideal x_train #for redraw when new data included in Xself.X x_trainself.y y_trainself.y_ideal y_idealelse:self.ax[0].set_xlim(self.xlim)self.ax[0].set_ylim(self.ylim)self.ax[0].scatter(self.X,self.y, labely)self.ax[0].plot(self.x_ideal, self.y_ideal, --, color orangered, labely_ideal, lw1)self.ax[0].set_title(OverFitting Example: Regression Data Set (quadratic with noise),fontsize 14)self.ax[0].set_xlabel(x)self.ax[0].set_ylabel(y)self.ax0ledgend self.ax[0].legend(loclower right)self.ax[0].text(0.5,0.93, Click on plot to add data,fontsize12, hacenter,transformself.ax[0].transAxes, colordlc[dlblue])if not redraw:self.xlim self.ax[0].get_xlim()self.ylim self.ax[0].get_ylim()output.capture() # debugdef add_data(self, event):if self.logistic:self.add_data_logistic(event)else:self.add_data_linear(event)output.capture() # debugdef add_data_logistic(self, event):if event.inaxes self.ax[0]:x0_coord event.xdatax1_coord event.ydataif event.key is None: #shift not pressedself.ax[0].scatter(x0_coord, x1_coord, markerx, s10, c red, labely1)self.y np.append(self.y,1)else:self.ax[0].scatter(x0_coord, x1_coord, markero, s10, labely0, facecolorsnone,edgecolorsdlc[dlblue],lw3)self.y np.append(self.y,0)self.X np.append(self.X,np.array([[x0_coord, x1_coord]]),axis0)self.fig.canvas.draw()def add_data_linear(self, event):if event.inaxes self.ax[0]:x_coord event.xdatay_coord event.ydataself.ax[0].scatter(x_coord, y_coord, markero, s10, facecolorsnone,edgecolorsdlc[dlblue],lw3)self.y np.append(self.y,y_coord)self.X np.append(self.X,x_coord)self.fig.canvas.draw()#output.capture() # debug#def clrdata_clicked(self,event):# if self.logistic True:# self.X np.# else:# self.linear_regression()output.capture() # debugdef fitdata_clicked(self,event):if self.logistic:self.logistic_regression()else:self.linear_regression()def linear_regression(self):self.ax[0].clear()self.fig.canvas.draw()# create and fit the model using our mapped_X feature set.self.X_mapped, _ map_one_feature(self.X, self.degree)self.X_mapped_scaled, self.X_mu, self.X_sigma zscore_normalize_features(self.X_mapped)#linear_model LinearRegression()linear_model Ridge(alphaself.lambda_, normalizeTrue, max_iter10000)linear_model.fit(self.X_mapped_scaled, self.y )self.w linear_model.coef_.reshape(-1,)self.b linear_model.intercept_x np.linspace(*self.xlim,30) #plot line idependent of data which gets disorderedxm, _ map_one_feature(x, self.degree)xms (xm - self.X_mu)/ self.X_sigmay_pred linear_model.predict(xms)#self.fig.canvas.draw()self.linear_data(redrawTrue)self.ax0yfit self.ax[0].plot(x, y_pred, color blue, labely_fit)self.ax0ledgend self.ax[0].legend(loclower right)self.fig.canvas.draw()def logistic_regression(self):self.ax[0].clear()self.fig.canvas.draw()# create and fit the model using our mapped_X feature set.self.X_mapped, _ map_feature(self.X[:, 0], self.X[:, 1], self.degree)self.X_mapped_scaled, self.X_mu, self.X_sigma zscore_normalize_features(self.X_mapped)if not self.regularize or self.lambda_ 0:lr LogisticRegression(penaltynone, max_iter10000)else:C 1/self.lambda_lr LogisticRegression(CC, max_iter10000)lr.fit(self.X_mapped_scaled,self.y)#print(lr.score(self.X_mapped_scaled, self.y))self.w lr.coef_.reshape(-1,)self.b lr.intercept_#print(self.w, self.b)self.logistic_data(redrawTrue)self.contour plot_decision_boundary(self.ax[0],[-1,1],[-1,1], predict_logistic, self.w, self.b,scalerTrue, muself.X_mu, sigmaself.X_sigma, degreeself.degree )self.fig.canvas.draw()output.capture() # debugdef update_equation(self, idx, firsttimeFalse):#print(fUpdate equation, index {idx}, firsttime{firsttime})self.degree idx1if firsttime:self.eqtext []else:for artist in self.eqtext:#print(artist)artist.remove()self.eqtext []if self.logistic:_, equation map_feature(self.X[:, 0], self.X[:, 1], self.degree)string f_{wb} sigmoid(else:_, equation map_one_feature(self.X, self.degree)string f_{wb} (bz 10seq equation.split()blks math.ceil(len(seq)/bz)for i in range(blks):if i 0:string string .join(seq[bz*i:bz*ibz])else:string .join(seq[bz*i:bz*ibz])string string ) if i blks-1 else string ei self.ax[1].text(0.01,(0.75-i*0.25), f${string}$,fontsize9,transform self.ax[1].transAxes, maleft, vatop )self.eqtext.append(ei)self.fig.canvas.draw()

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/911931.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

用一部手机制作网站网站建设文化策划方案

领取福利记得长按,领取技术书籍哦随着互联网大潮的到来,越来越多网站,应用系统需要海量数据的支撑,高并发、低延迟、高可用、高扩展等要求在传统的关系型数据库中已经得不到满足,或者说关系型数据库应对这些需求已经显…

移动端网站教程微信怎样将网站的内容做

本文分享一个南网上行通信规约20140617 报文解析软件 下载链接: https://pan.baidu.com/s/1ngbBG-yL8ucRWLDflqzEnQ 提取码: y1de 主界面如下图所示: 本软件同时支持南网上行通信规约20140617-Fn查询功能 软件同时支持多种规约类型,如:国网…

做漆包线的招聘网站做会计题目的网站

Python作为一种流行的高级编程语言,它的独特特性之一就是全局解释器锁(Global Interpreter Lock,简称GIL)。本文将深入探讨GIL的定义、工作原理以及对Python的影响,并介绍如何应对GIL的限制。 1. 什么是GIL&#xff1…

网站建设标书模版怎么做情侣网站

目录 1. 什么是Docker1.1. 什么是容器1.2. 什么是Docker 2. 安装Docker3. 镜像操作3.1. 拉取镜像3.2. 卸载镜像/容器3.3. 使用镜像/容器 4. 相关指令说明 1. 什么是Docker 1.1. 什么是容器 虚拟机: 操作系统是一个很笨重的程序,即是啥都不干&#xff0c…

绘画做动作的网站网站做pc

目录 背影 极限学习机 爬山算法优化遗传算法优化极限学习机的多分类预测,p-ga-elm多分类预测 主要参数 MATLAB代码 效果图 结果分析 展望 完整代码下载链接:爬山算法优化遗传算法优化极限学习机的多分类预测,p-ga-elm多分类预测(代码完整,数据)资源-CSDN文库 https://d…

为什么做pc网站网站搭建软件d

什么是ArkTS? ArkTS是一个为鸿蒙组件而生的框架,语法亲人好用。基于TypeScript,ArkTS拓展了声明式UI、状态管理等的能力,从本质上来讲,是TypeScript的扩展,主要服务于前端。 ArkTS的开发可以满足“一次开…

宝安响应式网站建设重庆市建设岗位培训中心

(PCWAP)装修设计公司网站模板 家装公司网站源码下载 PbootCMS内核开发的网站模板,该模板适用于装修设计、家装公司类等企业,当然其他行业也可以做,只需要把文字图片换成其他行业的即可; PCWAP,同一个后台&#xff0c…

支付宝签约网站网站技能培训

描述: 有甲、乙两人,其中,甲只说假话,而不说真话;乙则是只说真话,不说假话。但是,他们两个人在回答别人的问题时,只通过点头与摇头来表示,不讲话。有一天,一个…

金融网站cms企业网站优化内容

介绍 文档中会进行SceneView的自定义扩展,实现显示常驻GUI和添加自定义叠加层(Custom Overlay)。 最近项目开发用回了原生的Unity UI相关内容。对于之前常用的FairyGUI来说,原生的UGUI对于UI同学来讲有些不太方便。再加上这次会…

大型美容网站建设额尔古纳做网站

智能优化算法应用:基于学生心理学算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用:基于学生心理学算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.学生心理学算法4.实验参数设定5.算法…

绍兴网站制作网站中国空间站照片

做Linux方面也有三个多月了,对代码中的有些结构一直不是非常明确,比方platform_device与platform_driver一直分不清关系。在网上搜了下,做个总结。两者的工作顺序是先定义platform_device -> 注冊 platform_device->,再定义…

wps做网站框架网络营销官网

BeanShell简介BeanShell是使用Java语法的一套脚本语言,在JMeter的多种组件中都有BeanShell的身影,如:定时器:BeanShell Timer前置处理器:BeanShell PreProcessor采样器:BeanShell Sampler后置处理器&#x…

做进口产品的网站好it外包公司怎么接项目

目录 问题解决 常见的打开模式 问题解决 出现于调用os.Open来打开的文件进行写操作时报的错,原因在于Open函数: func Open(name string) (*File,error) {return OpenFile(name, O_RDONLY, 0) } Open调用了OpenFile,而OpenFile默认以只读…

网站换域名seo怎么做哪家企业做网站好

现在淘宝 (淘宝论坛)店主在经营店铺的过程中,会考虑将自己特别店铺进行类目的更改,那么也有一点店主会担心到如果淘宝更改类目会被降权吗?如果被降权了怎么办呢?那就一起了解具体的内容吧!跟大家分享一些淘宝宝贝被降权的处理方式:1、虚假销…

做网站的封面图片哪里才有深圳百度推广

目录 1. 认识 Linux, 了解 Linux 的相关背景 1.发展史 2. 学会如何使用云服务器 3. 掌握使用远程终端工具 xshell 登陆 Linux 服务器 1. 认识 Linux, 了解 Linux 的相关背景 1.发展史 学习Linux系统编程,你可能要问Linux从哪里来?它是怎么发展的&am…

视频网站建设广州专业找人见人付款

2019独角兽企业重金招聘Python工程师标准>>> 场景 如图下,当A、B列与E、F列皮配上,C列则引用G列的值 原理 VLOOKUP只能查找单列值。我们可以把多列值拼接后形成一个虚拟列,然后VLOOKUP函数查找这个虚拟列进行匹配。 在C1处输入下…

对网站的建议和优化网络营销策划以什么为核心

一、基本概念 string本质是一个类,封装了c风格字符串(以\0结尾的字符数组),具备自动管理内存功能,提供了多种构造函数和多种删查增改的成员方法。string的本质特点归结以下几点: 1、动态数组:…

网站开发如何优秀网站模板下载

到现在为止都是在开发板上运行的裸机程序,相当于之前学习STM32单片机时走过的路,还没有真正进入到核心的驱动开发部分,但这都是基础,所以慢慢来不着急。 接下来进入串口通信的学习,和GPIO一样,也是和单片机…

完整教程:第33章 AI在教育领域的应用

完整教程:第33章 AI在教育领域的应用pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Mona…

python微博舆情分析系统 情感分析 爬虫 机器学习 新浪微博 信息采集 大数据工艺(源码)✅

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …