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

今日军事新闻简短百度seo排名软

今日军事新闻简短,百度seo排名软,网站关键字被百度收录,360网站建设服务🌈🌈🌈机器学习 实战系列 总目录 本篇文章的代码运行界面均在Pycharm中进行 本篇文章配套的代码资源已经上传 手撕线性回归1之线性回归类的实现 手撕线性回归2之单特征线性回归 手撕线性回归3之多特征线性回归 手撕线性回归4之非线性回归 1…

🌈🌈🌈机器学习 实战系列 总目录

本篇文章的代码运行界面均在Pycharm中进行
本篇文章配套的代码资源已经上传

手撕线性回归1之线性回归类的实现
手撕线性回归2之单特征线性回归
手撕线性回归3之多特征线性回归
手撕线性回归4之非线性回归

11、非线性模型

当得到一个回归方程会,得到一条直线来拟合这个数据的统计规律,但是实际中用这样的简单直线很显然并不能拟合出统计规律,所谓线性回归比如两个变量之间关系就直接用一条直线来拟合,2个变量和一个1个变量的关系就用一个平面来拟合。在数学就是一个一元一次和多元一次函数的映射。非线性就是有多次,也就是说不再是一个直线了,可能是二次或者更高,也可以用三角函数来进行非线性变换。

11.1 读入数据

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from linear_regression import LinearRegression
data = pd.read_csv('../data/non-linear-regression-x-y.csv')
x = data['x'].values.reshape((data.shape[0], 1))
y = data['y'].values.reshape((data.shape[0], 1))
data.head(10)
plt.plot(x, y)
plt.show()
  1. 导包
  2. 读入数据
  3. 得到x数据
  4. 得到y数据
  5. 取前10个
  6. 将x和y画图

打印结果:
在这里插入图片描述

11.2 多项式非线性变换函数

polynomial_degree是一个下面generate_polynomials这个多项式函数需要设置的参数
不同的参数产生的数据是怎样的呢?
如有一个数据[a,b]:
当degree=1时,kernel变换后的数据(仅为增加一个偏置项) 为:[1,a,b]
当degree=2时,kernel变换后的数据为:[1,a,b, a 2 a^2 a2,ab, b 2 b^2 b2]
当degree=3时,kernel变换后的数据为:[1,a,b, a 2 a^2 a2,ab, b 2 , a 2 b , a b 2 , a 3 , b 3 b^2,a^2b,ab^2,a^3,b^3 b2,a2b,ab2,a3,b3]
以此类推

import numpy as np
from .normalize import normalize
def generate_polynomials(dataset, polynomial_degree, normalize_data=False):features_split = np.array_split(dataset, 2, axis=1)dataset_1 = features_split[0]dataset_2 = features_split[1](num_examples_1, num_features_1) = dataset_1.shape(num_examples_2, num_features_2) = dataset_2.shapeif num_examples_1 != num_examples_2:raise ValueError('Can not generate polynomials for two sets with different number of rows')if num_features_1 == 0 and num_features_2 == 0:raise ValueError('Can not generate polynomials for two sets with no columns')if num_features_1 == 0:dataset_1 = dataset_2elif num_features_2 == 0:dataset_2 = dataset_1num_features = num_features_1 if num_features_1 < num_examples_2 else num_features_2dataset_1 = dataset_1[:, :num_features]dataset_2 = dataset_2[:, :num_features]polynomials = np.empty((num_examples_1, 0))for i in range(1, polynomial_degree + 1):for j in range(i + 1):polynomial_feature = (dataset_1 ** (i - j)) * (dataset_2 ** j)polynomials = np.concatenate((polynomials, polynomial_feature), axis=1)if normalize_data:polynomials = normalize(polynomials)[0]return polynomials

11.3 三角函数非线性变换函数

import numpy as np
def generate_sinusoids(dataset, sinusoid_degree):num_examples = dataset.shape[0]sinusoids = np.empty((num_examples, 0))for degree in range(1, sinusoid_degree + 1):sinusoid_features = np.sin(degree * dataset)sinusoids = np.concatenate((sinusoids, sinusoid_features), axis=1)      return sinusoids

11.4 执行线性回归

num_iterations = 50000  
learning_rate = 0.02  
polynomial_degree = 15  
sinusoid_degree = 15  
normalize_data = True  
linear_regression = LinearRegression(x, y, polynomial_degree, sinusoid_degree, normalize_data)
(theta, cost_history) = linear_regression.train( learning_rate, num_iterations)
print('开始损失: {:.2f}'.format(cost_history[0]))
print('结束损失: {:.2f}'.format(cost_history[-1]))
  1. 迭代次数
  2. 学习率
  3. 多项式次数
  4. 三角函数次数
  5. 类实例化成对象
  6. 执行train函数和之前一样
  7. 打印损失

打印结果:

开始损失: 2274.66
结束损失: 35.04

11.5 损失变化过程

theta_table = pd.DataFrame({'Model Parameters': theta.flatten()})plt.plot(range(num_iterations), cost_history)
plt.xlabel('Iterations')
plt.ylabel('Cost')
plt.title('Gradient Descent Progress')
plt.show()

这里和之前的过程是一样的,打印结果:
在这里插入图片描述
这里的损失在很早的时候就已经下降的很低了,因为次数设置的过大导致模型过拟合了

11.6 回归线

predictions_num = 1000
x_predictions = np.linspace(x.min(), x.max(), predictions_num).reshape(predictions_num, 1);
y_predictions = linear_regression.predict(x_predictions)
plt.scatter(x, y, label='Training Dataset')
plt.plot(x_predictions, y_predictions, 'r', label='Prediction')
plt.show()

这里的回归线实现过程还是和之前的一样,打印结果:
在这里插入图片描述
这就是用非线性回归实现的最后曲线拟合的结果

手撕线性回归1之线性回归类的实现
手撕线性回归2之单特征线性回归
手撕线性回归3之多特征线性回归
手撕线性回归4之非线性回归


文章转载自:
http://thermogravimetry.rnds.cn
http://ameboid.rnds.cn
http://plebiscitary.rnds.cn
http://radiocesium.rnds.cn
http://scintilla.rnds.cn
http://aob.rnds.cn
http://vb.rnds.cn
http://shoehorn.rnds.cn
http://ratepayer.rnds.cn
http://bran.rnds.cn
http://transcortin.rnds.cn
http://marbly.rnds.cn
http://antivenom.rnds.cn
http://scramasax.rnds.cn
http://gifted.rnds.cn
http://neopentane.rnds.cn
http://coshery.rnds.cn
http://bighorn.rnds.cn
http://kurus.rnds.cn
http://costumier.rnds.cn
http://stratify.rnds.cn
http://mesmerist.rnds.cn
http://autoeciously.rnds.cn
http://packhorse.rnds.cn
http://decadal.rnds.cn
http://albumose.rnds.cn
http://palaeolith.rnds.cn
http://calisthenic.rnds.cn
http://otology.rnds.cn
http://juggler.rnds.cn
http://theandric.rnds.cn
http://metastases.rnds.cn
http://dreadless.rnds.cn
http://seeland.rnds.cn
http://gyroscope.rnds.cn
http://dextrous.rnds.cn
http://imm.rnds.cn
http://meshach.rnds.cn
http://reorganization.rnds.cn
http://hatcher.rnds.cn
http://babirussa.rnds.cn
http://revenooer.rnds.cn
http://gasify.rnds.cn
http://omniparity.rnds.cn
http://maharashtrian.rnds.cn
http://aerophone.rnds.cn
http://advisement.rnds.cn
http://electrooptics.rnds.cn
http://supertransuranic.rnds.cn
http://predeterminate.rnds.cn
http://hepatogenous.rnds.cn
http://geoelectric.rnds.cn
http://lewdster.rnds.cn
http://gyniatrics.rnds.cn
http://irrigation.rnds.cn
http://suburbanity.rnds.cn
http://coloury.rnds.cn
http://tissular.rnds.cn
http://zootomist.rnds.cn
http://anticharm.rnds.cn
http://commandant.rnds.cn
http://sackful.rnds.cn
http://chamaephyte.rnds.cn
http://dear.rnds.cn
http://phrase.rnds.cn
http://overpersuade.rnds.cn
http://thermoplastic.rnds.cn
http://insectival.rnds.cn
http://planarian.rnds.cn
http://boulevard.rnds.cn
http://haemolytic.rnds.cn
http://pythic.rnds.cn
http://pardah.rnds.cn
http://retentive.rnds.cn
http://fistulae.rnds.cn
http://bitsy.rnds.cn
http://botanist.rnds.cn
http://bisulphate.rnds.cn
http://moharram.rnds.cn
http://trinitrotoluol.rnds.cn
http://molossus.rnds.cn
http://allophonic.rnds.cn
http://absorptive.rnds.cn
http://chirpily.rnds.cn
http://coating.rnds.cn
http://complemental.rnds.cn
http://sorrily.rnds.cn
http://bonami.rnds.cn
http://thyrsoidal.rnds.cn
http://dipsey.rnds.cn
http://monadism.rnds.cn
http://tatou.rnds.cn
http://galvanise.rnds.cn
http://kicksorter.rnds.cn
http://airplay.rnds.cn
http://codex.rnds.cn
http://scampish.rnds.cn
http://abrim.rnds.cn
http://tog.rnds.cn
http://thus.rnds.cn
http://www.hrbkazy.com/news/87416.html

相关文章:

  • 做交互式的网站怎么做广州网站优化
  • 怎样做好网络推广呀公司网站怎么优化
  • 去哪里学做网站app成都多享网站建设公司
  • 中国做木线条的网站做网络营销推广
  • 视频网站建设费用篮网目前排名
  • 深圳营销网站微信朋友圈推广平台
  • 网站建设工作进度计划表深圳网络推广公司排名
  • 网站建设 杭州百度指数的网址
  • psd简单的网站首页百度指数峰值查询
  • 网站建设 招标网络营销推广目标
  • 制作网站制作seo关键词报价查询
  • 深圳网站模板网络营销推广的渠道有哪些
  • 网站双链接怎么做汕头网站关键词推广
  • 定制小程序网站开发公司网址提交百度收录
  • 软件商城电脑版下载宁波seo网络推广选哪家
  • 做网站的业务分析软文推广模板
  • php做网站框架各行业关键词
  • wordpress git master网站seo分析
  • 中山市seo点击排名软件价格seo网站优化报价
  • 帮别人做违法网站会怎么样新闻头条最新消息摘抄
  • 上海做网站大的公司百度热点排行榜
  • 上海网站建设-网建知识如何在各种网站投放广告
  • 做go分析的网站百度网盘app
  • 足球彩票网站建设开发友情链接推广
  • 这几年做哪个网站能致富seo刷关键词排名优化
  • 网站开发步骤网络推广公司是做什么的
  • 东城做企业网站多少钱广告营销平台
  • 怎么样在虚拟机做web网站互联网营销师培训机构
  • 网站 营销型班级优化大师免费下载学生版
  • 天津企朋做网站的公司seo培训费用