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

中文网站建设公司网站标题写什么作用是什么

中文网站建设公司,网站标题写什么作用是什么,苏州网网站建设,加强政务门户网站建设目录 一、实验介绍 二、实验环境 三、实验内容 0. 导入库 1. 归一化处理 归一化 实验内容 2. 绘制归一化数据折线图 报错 解决 3. 计算移动平均值SMA 移动平均值 实验内容 4. 绘制移动平均值折线图 5 .同时绘制两图 6. array转换为tensor张量 7. 打印张量 一、…

目录

一、实验介绍

二、实验环境

三、实验内容

0. 导入库

1. 归一化处理

归一化

 实验内容

2. 绘制归一化数据折线图

报错

解决

3. 计算移动平均值SMA

移动平均值

实验内容

4. 绘制移动平均值折线图

5 .同时绘制两图

6. array转换为tensor张量

7. 打印张量


 

 

 

一、实验介绍

  • Visualizing the Trend of Random Data Changes
  • 可视化随机数据变化的趋势

 

二、实验环境

 

conda create -n DL python=3.7 
conda activate DL
pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
conda install matplotlib

 

 

三、实验内容

0. 导入库

     According to the usual convention, import numpy, matplotlib.pyplot, and torch.按照通常的惯例,导入 numpy、matplotlib.pyplot 和 torch。
import numpy as np
import matplotlib.pyplot as plt
import torch

1. 归一化处理

归一化

        归一化处理是一种常用的数据预处理技术,用于将数据缩放到特定的范围内,通常是[0,1][-1,1]。这个过程可以确保不同特征或指标具有相似的数值范围,避免某些特征对模型训练的影响过大。

        在机器学习和数据分析中,归一化可以帮助改善模型的收敛速度和性能,减少由于特征尺度差异导致的问题。例如,某些机器学习算法(如梯度下降)对特征的尺度敏感,如果不进行归一化处理,可能会导致模型难以收敛或产生不准确的结果。

        常用的归一化方法包括最小-最大归一化(Min-Max normalization)和Z-score归一化(标准化)。

  • 最小-最大归一化将数据线性地缩放到指定的范围内。
  • Z-score归一化通过计算数据的均值和标准差,将数据转换为均值为0,标准差为1的分布。

 实验内容

    Read the file named `data.txt` containing 100 integers using NumPy, normalize all values to the range [0, 1], and store the normalized array with two decimal places.

        使用 NumPy 读取包含 100 个整数的名为“data.txt”的文件,将所有值规范化为范围 [0, 1],并存储具有两个小数位的规范化数组。

 

data = np.loadtxt('data.txt')
# 归一化处理
normalized_array = (data - np.min(data)) / (np.max(data) - np.min(data))
# 保留两位小数
normalized_data = np.round(normalized_array, 2)
# 打印归一化后的数组
print(normalized_array)

 

69fe508d25e64c1a9c65597cbfe65306.png

2. 绘制归一化数据折线图

         Create a line plot using Matplotlib where the x-axis represents the indices of the normalized array ranging from 1 to 100, and the y-axis represents the values of the normalized array ranging from 0 to 1.

        使用 Matplotlib 创建一个折线图,其中 x 轴表示规范化数组的索引,范围从1到100,y 轴表示规范化数组的值,范围从0到1。

# 创建x轴数据
x = np.arange(1, 101)
# 绘制折线图
plt.plot(x, normalized_array)# 设置x轴和y轴的范围
plt.xlim(1, 100)
plt.ylim(0, 1)
plt.title("Normalized Data")
plt.xlabel("Index")
plt.ylabel("Normalized Array")
plt.show()

 

报错

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

解决

conda install nomkl

 

e1e293471fad4897a870b45d1da96b3b.png

3. 计算移动平均值SMA

移动平均值

        移动平均值(Moving Average)是一种数据平滑处理的方法,可以在一段时间内计算数据序列的平均值。这种方法通过不断更新计算的平均值,使得输出的数据更加平滑,减少噪声和突变的影响。

        移动平均值有多种类型,其中最常见的是简单移动平均值(Simple Moving Average,SMA)和指数移动平均值(Exponential Moving Average,EMA)。这两种方法的计算方式略有不同。

  1. 简单移动平均值(SMA):
    简单移动平均值是对指定时间段内的数据进行平均处理的方法,计算公式如下:

    SMA = (X1 + X2 + X3 + ... + Xn) / n

    其中,X1, X2, ..., Xn 是指定时间段内的数据,n 是时间段的长度。

    例如,要计算最近5天的简单移动平均值,可以将这5天的数据相加,再除以5。

  2. 指数移动平均值(EMA):
    指数移动平均值是对数据进行加权平均处理的方法,计算公式如下:

    EMA = (X * (2/(n+1))) + (EMA_previous * (1 - (2/(n+1))))

    其中,X 是当前数据点的值,n 是时间段的长度,EMA_previous 是上一个时间段的指数移动平均值。

    指数移动平均值使用了指数衰减的加权系数,更加重视最近的数据点。

        使用移动平均值可以平滑数据序列,使得数据更具可读性,减少随机波动的影响。这在时间序列分析、技术分析和数据预测等领域经常被使用。

 

实验内容

        Calculate the moving average of the normalized results using NumPy with a window size of 5. Store the calculated moving average values in a new one-dimensional NumPy array, referred to as the "average values array."

        使用窗口大小为 5 的 NumPy 计算归一化结果的移动平均值。将计算出的移动平均值存储在新的一维 NumPy 数组(称为“平均值数组”)中。

 

# 计算移动平均值
average_values_array = np.convolve(normalized_array, np.ones(5)/5, mode='valid')
print(average_values_array)

 

4. 绘制移动平均值折线图

    Create another line plot using Matplotlib where the x-axis represents the indices of the average values array ranging from 5 to 100, and the y-axis represents the values of the average values array ranging from 0 to 1.

        使用 Matplotlib 创建另一个线图,其中 x 轴表示平均值数组的索引,范围从 5 到 100,y 轴表示从 0 到 1 的平均值数组的值。

x_axis = range(5, 101)# 绘制折线图
plt.plot(x_axis, average_values_array)plt.xlim(5, 100)
plt.ylim(0, 1)
plt.title('Moving Average Line')
plt.xlabel('Index')
plt.ylabel('Average Values Array.')
plt.show()

 

7da23666f5ad444b95198a444c055c85.png

 

5 .同时绘制两图

        Combine the line plots of the normalized array and the average values array in the same figure using different colors for each line. 

        将归一化数组的线图和平均值数组组合在同一图中,每条线使用不同的颜色。

plt.plot(x, normalized_array, color='r', label='Normalized Array Line')
plt.plot(x_axis, average_values_array, color='b', label='Moving Average Line')
plt.legend()
plt.xlim(1, 100)
plt.ylim(0, 1)
plt.xlabel('Index')
plt.ylabel('Value')
plt.show()

e751b1bc39d94149ac897c174d00d501.png

 

6. array转换为tensor张量

   Transform the normalized array into a 2x50 Tensor by reshaping the data.

        通过重塑数据将归一化数组转换为 2x50 张量。

normalized_tensor = torch.tensor(normalized_array).reshape(2, 50)

 

7. 打印张量

        Print the resulting Tensor.

print(normalized_tensor)

0732e4b38e824aa98f36ab959b2ace63.png

 

 

 

 

 

 

http://www.yayakq.cn/news/139586/

相关文章:

  • 外部链接对网站的影响营销方向有哪些
  • 烟台汽车租赁网站建设政务信息公开与网站建设报告
  • 福州 网站建设 医疗快速开发平台免费版
  • 网站打不开dns修改吗海外游戏推广
  • 西安网站建设公司咪豆北京市招标网
  • 东莞建设网站综合服务平台wordpress批量上传插件下载
  • 学做网站推广要多久时间网页设计作业假面骑士
  • 打开英文网站字体不对网站建设与管理 pdf
  • 网站开发 会费管理 模块go语言 做网站
  • 沈阳酒店团购网站制作做网站需要什么基础
  • 网站开发所需费用明细软件工程工业软件好吗
  • 互联网 网站建设价格郑州seo竞价
  • 中为网站建设wordpress 分类目录 设置 前缀 后 出现404
  • 电子商务网站建设怎么做口碑好的秦皇岛网站建设哪里有
  • 学院网站设计案例宁夏水利厅建设处网站
  • 建设一个类似于京东的网站建程网土石方工程
  • 沭阳县建设局网站wordpress主题修改
  • 苏州市吴江建设局网站高端网站建设南宁
  • 为什么会显示危险网站做最好言情网站
  • 一个静态网站多少钱文秘写作网站
  • 建个网站需要什么网站开发和合同范本
  • 网站灰色建设wordpress破解后台
  • 网站站内优化方案html5手机移动app网站制作教程
  • 网站备案能查到什么东西网站运营条件
  • 域名网站排名辽宁省城乡建设厅网站
  • 武隆网站建设报价好看的网站链接
  • 网站开发教程流程网站制作的公司哪个好
  • 网站分成比例系统怎么做互联网行业都有哪些工作赚钱
  • 卖服务器建网站网站3级营销是怎么做的
  • 动易的网站系统鳌江网站建设