当前位置: 首页 > news >正文

彩票网站什么做手机软件做的相册怎样传到网站

彩票网站什么做,手机软件做的相册怎样传到网站,沈阳公司网站建设,wordpress做微信支付#x1f680;个人主页#xff1a;为梦而生~ 关注我一起学习吧#xff01; #x1f4a1;专栏#xff1a;机器学习python实战 欢迎订阅#xff01;后面的内容会越来越有意思~ ⭐内容说明#xff1a;本专栏主要针对机器学习专栏的基础内容进行python的实现#xff0c;部分… 个人主页为梦而生~ 关注我一起学习吧 专栏机器学习python实战 欢迎订阅后面的内容会越来越有意思~ ⭐内容说明本专栏主要针对机器学习专栏的基础内容进行python的实现部分基础知识不再讲解有需要的可以点击专栏自取~ 往期推荐机器学习基础专栏 【机器学习基础】机器学习入门1 【机器学习基础】机器学习入门2 【机器学习基础】机器学习的基本术语 【机器学习基础】机器学习的模型评估评估方法及性能度量原理及主要公式 【机器学习基础】一元线性回归适合初学者的保姆级文章 【机器学习基础】多元线性回归适合初学者的保姆级文章 ⭐本期内容针对以上的一元和多元线性回归的梯度下降求解方法进行代码展示 文章目录 一元线性回归多元线性回归 一元线性回归 设计思路 首先class LinearRegression(object):定义一个LinearRegression类继承自object类。 在这个类中首先def __init__(self):定义类的构造函数。 在构造函数中初始化线性回归模型的参数self.__M、self.__theta0和self.__theta1以及梯度下降中的步长学习率self.__alpha。 线性回归模型是要不断计算输出的所以定义函数def predict(self, x)用于预测给定输入x对应的输出。 同时线性回归的目的是通过迭代不断的修改参数 θ \theta θ所以需要定义函数用来做这个工作它是通过梯度下降的方法来求解的所以def __cost_theta0(self, X, Y)和def __cost_theta1(self, X, Y)这两个方法用于计算代价函数关于参数 θ 0 \theta_0 θ0​和 θ 1 \theta_1 θ1​的偏导数。 下面def train(self, features, target)把上面的每个步骤和到了一起定义了一个训练方法train用于通过梯度下降算法找到最优的模型参数 θ 0 \theta_0 θ0​和 θ 1 \theta_1 θ1​的使得代价函数的平方误差最小。在训练过程中通过迭代更新参数并输出每次迭代后的参数值。 在while的每一次迭代中通过更新参数self.__theta0和self.__theta1来逐渐最小化代价函数的平方误差。 if 0:o.5f.format(prevt0) 0:o.5f.format(self.__theta0) and 0:o.5f.format(prevt1) 0:o.5f.format(self.__theta1):判断是否达到收敛条件即两次迭代的参数值没有改变如果满足条件则退出循环。 最后输出最终得到的参数值。 总体代码实现 定义LinearRegression的class #!/usr/bin/env python3 # 这是一个Shebang指定了此脚本要使用的解释器为python3。 import numpyclass LinearRegression(object):# Constructor. Initailize Constants.def __init__(self):super(LinearRegression, self).__init__()self.__M 0self.__theta0 2self.__theta1 2# defining Alpha I.E length of steps in gradient descent Or learning Rate.self.__alpha 0.01def predict(self,x):return (self.__theta0 x * self.__theta1)# Cost Function fot theta0.def __cost_theta0(self,X,Y):sqrerror 0.0for i in range(0,X.__len__()):sqrerror (self.predict(X[i]) - Y[i])return (1/self.__M * sqrerror)# Cost Function fot theta1.def __cost_theta1(self,X,Y):sqrerror 0.0for i in range(0,X.__len__()):sqrerror (self.predict(X[i]) - Y[i]) * X[i]return (1/self.__M * sqrerror)# training Data :# Finding Best __theta0 and __theta1 for data such that the Squared Error is Minimized.def train(self,features,target):# Validate Dataif not features.__len__() target.__len__():raise Exception(features and target should be of same length)# Initailize M with Size of X and Yself.__M features.__len__()# gradient descentprevt0, prevt1 self.__theta0 , self.__theta1while True:tmp0 self.__theta0 - self.__alpha * (self.__cost_theta0(features,target))tmp1 self.__theta1 - self.__alpha * (self.__cost_theta1(features,target))self.__theta0, self.__theta1 tmp0, tmp1print(theta0(b) :, self.__theta0)print(theta1(m) :, self.__theta1)if 0:o.5f.format(prevt0) 0:o.5f.format(self.__theta0) and 0:o.5f.format(prevt1) 0:o.5f.format(self.__theta1):breakprevt0, prevt1 self.__theta0 , self.__theta1# Training Completed.# log __theta0 __theta1print(theta0(b) :, self.__theta0)print(theta1(m) :, self.__theta1) 样例测试 from LinearRegression_OneVariables import LinearRegression import numpy as npX np.array([1,2,3,4,5,6,7,8,9,10])# Y 0 1X Y np.array([1,2,3,4,5,6,7,8,9,10])modal LinearRegression.LinearRegression()modal.train(X,Y)print(modal.predict(14)) 多元线性回归 设计思路 首先将文件导入打乱顺序并选择训练集。 datapd.read_csv(c:\\windquality.csv)data_arraydata.values#shuffling for train test spplit np.random.shuffle(data_array)train,testdata_array[:1200,:],data_array[1200:,:] x_traintrain[:,:-1] x_testtest[:,:-1] y_traintrain[:,-1] y_testtest[:,-1]然后初始化参数注意这里是多元的所以有多个参数需要初始化。包括迭代次数和学习率 coef10 coef20 coef30 coef40 coef50 coef60 coef70 coef80 coef90 coef100 coef110 epoch1000 alpha.0001然后使用梯度下降算法进行计算 总体代码实现 import pandas as pd import numpy as np import matplotlib.pyplot as pltdatapd.read_csv(c:\\windquality.csv)data_arraydata.values#shuffling for train test spplit np.random.shuffle(data_array)train,testdata_array[:1200,:],data_array[1200:,:] x_traintrain[:,:-1] x_testtest[:,:-1] y_traintrain[:,-1] y_testtest[:,-1]coef10 coef20 coef30 coef40 coef50 coef60 coef70 coef80 coef90 coef100 coef110 epoch1000 alpha.0001 c0 nlen(y_train) for i in range(epoch):y_pred((coef1*x_train[:,0])(coef2*x_train[:,1])(coef3*x_train[:,2])(coef4*x_train[:,3])(coef5*x_train[:,4])(coef6*x_train[:,5])(coef7*x_train[:,6])(coef8*x_train[:,7])(coef9*x_train[:,8])(coef10*x_train[:,9])(coef11*x_train[:,10])c)#to predict drivativeintercept(-1/n)*sum(y_train-y_pred)dev1(-1/n)*sum(x_train[:,0]*(y_train-y_pred))dev2(-1/n)*sum(x_train[:,1]*(y_train-y_pred))dev3(-1/n)*sum(x_train[:,2]*(y_train-y_pred))dev4(-1/n)*sum(x_train[:,3]*(y_train-y_pred))dev5(-1/n)*sum(x_train[:,4]*(y_train-y_pred))dev6(-1/n)*sum(x_train[:,5]*(y_train-y_pred))dev7(-1/n)*sum(x_train[:,6]*(y_train-y_pred))dev8(-1/n)*sum(x_train[:,7]*(y_train-y_pred))dev9(-1/n)*sum(x_train[:,8]*(y_train-y_pred))dev10-1/n*sum(x_train[:,9]*(y_train-y_pred))dev11-1/n*sum(x_train[:,10]*(y_train-y_pred))#linecc-alpha*interceptcoef1coef1-alpha*dev1coef2coef2-alpha*dev2coef3coef3-alpha*dev3coef4coef4-alpha*dev4coef5coef5-alpha*dev5coef6coef6-alpha*dev6coef7coef7-alpha*dev7coef8coef8-alpha*dev8coef9coef9-alpha*dev9coef10coef10-alpha*dev10coef11coef11-alpha*dev11print(\nintercept:,c,\ncoefficient1:,coef1,\ncoefficient2:,coef2,\ncoefficient3:,coef3,\ncoefficient4:,coef4,\ncoefficient5:,coef5,\ncoefficient6:,coef6,\ncoefficient7:,coef7,\ncoefficient8:,coef8,\ncoefficient9:,coef9,\ncoefficient10,coef10, \ncoefficient11,coef11)#Calculating the predicted values predicted_values [] for i in range(0,399):y_pred ((coef1 * x_test[i,0]) (coef2 * x_test[i,1]) (coef3 * x_test[i,2]) (coef4 * x_test[i,3]) (coef5 * x_test[i,4]) (coef6 * x_test[i,5]) (coef7 * x_test[i,6]) (coef8 * x_test[i,7]) (coef9 * x_test[i,8]) (coef10 * x_test[i,9]) (coef11 * x_test[i,10]) intercept)predicted_values.append(y_pred)for i in range(len(predicted_values)):print(predicted_values[i])
http://www.yutouwan.com/news/350327/

相关文章:

  • 沙洋网站定制wordpress 免费版
  • 信融营销型网站建设公司局域网怎么建立
  • 外国做视频在线观看网站网站建设运营公司企业特色
  • 江苏网站设计公司电话电商网站设计推荐亿企邦
  • wordpress怎么加站点图标网站搭建公司哪家好
  • 珠海市香洲区建设局网站辽源做网站的公司
  • 建设网站需要准备什么做网站需要服务器还是主机
  • iis网站目录权限厦门公司网页制作
  • 营口网站seo领创科技网站开发
  • 广州番禺建设银行网站登录深圳的知名网站设计有哪些
  • 什么公司能做网站建设曲靖做网站
  • 收费网站素材网站建设:上海珍岛
  • 两学一做考学网站天津网络科技有限公司
  • 卡盟网站开发建材行业门户网站源码
  • 专门做墓志铭的网站金融投资网站源码
  • 济南网站建设公司哪个好职业培训学校加盟合作
  • 网站设计教程网站建大网站
  • 怎么找的做网站的人wordpress打开失败
  • 重庆转店铺哪个网站平台好wordpress设置在新页面打开
  • 重庆免费自助建站模板在哪里购买虚拟空间建设网站
  • ie打不开建设企业网站门户网站维护方案
  • 福州市建设工程工料机信息网站微信网站页面制作
  • 成品网站源码68w68临沂招聘网最新招聘
  • 合肥专业网站建设网络加速器下载
  • 呼市网站seo优化工资提成怎么算网络营销方式和平台推广
  • 高端网站定制建站html代码hr表示
  • canvas网站源码百度 营销推广怎么做
  • 做微商进哪个网站安全吗内容转载的网站怎么做
  • 网站产品展示方案工程建设与设计好发表吗
  • 选手机网站做网站优化选阿里巴巴还是百度