波士顿房价预测实验报告

更新时间:2023-05-27 09:01:23 阅读: 评论:0

波⼠顿房价预测实验报告实验(⼀)
代码段:
# 实验环境:MindSpore-python3.7-aarch64
戒烟的英文# 配置环境,导⼊库函数
import os
# os.environ['DEVICE_ID'] = '0'
import numpy as np
鱼翅的营养价值import mindspore as ms
from mindspore import nn
from mindspore import context
context.t_context(mode=context.GRAPH_MODE, device_target="Ascend")# CPU
x = np.arange(-5,5,0.3)[:32].reshape((32,1))
y =-5* x +0.1* al(loc=0.0, scale=20.0, size=x.shape)
net = nn.Den(1,1)
loss_fn = nn.loss.MSELoss()
opt = nn.optim.ainable_params(), learning_rate =0.01)
with_loss = nn.WithLossCell(net, loss_fn)
train_step = nn.TrainOneStepCell(with_loss, opt).t_train()
# 观察x和y的形状
print(x.shape)# (32, 1)
print(y.shape)# (32, 1)
for epoch in range(20):
loss = train_step(ms.Tensor(x, ms.float32), ms.Tensor(y, ms.float32))
print('epoch: {0}, loss is {1}'.format(epoch, loss))
鸡豆腐wb =[x.asnumpy()for x ainable_params()]
w, b = np.squeeze(wb[0]), np.squeeze(wb[1])
唐山限号吗print('The true linear function is y = -5 * x + 0.1')
print('The trained linear model is y = {0} * x + {1}'.format(w, b))
for i in range(-10,11,5):
print('x = {0}, predicted y = {1}'.format(i, net(ms.Tensor([[i]], ms.float32))))
# 作图
from matplotlib import pyplot as plt
防霉plt.scatter(x, y, label='Samples')食字开头的成语
专利流程
plt.plot(x, w * x + b, c ='r', label='True function')
plt.plot(x,-5* x +0.1, c='b', label='Trained model')
plt.legend()
羽毛球操plt.show()
实验(⼀)结果:

本文发布于:2023-05-27 09:01:23,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/791169.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:实验   环境   预测   房价   实验报告   食字
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图