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

浅用tensorflow天气预测

1.开发环境

(1)Python3.8

(2)Anaconda3

(3)Tensorflow

(4)Numpy

(5)Pandas

(6)Sklearn

先依次安装好上面的软件和包,其中python3.8和Anaconda3是直接下载安装,如果官方链接比较慢,可以搜下三方的源安装。其中Anaconda3不是必须的,用这个工具是因为确实挺香的。

剩下的3-6都是pip安装的包,注意使用Anaconda3的话就在Anaconda Prompt里使用pip命令,如果是其他集成环境或者原生的python环境,直接就在cmd里使用pip安装。

2、实现代码

import numpy as np
import pandas as pd
import tensorflow as tf
from tensorflow.keras import layers
import tensorflow.keras
import warnings
#####################################################
features = pd.read_csv('C:/Inst/20230411/20230411/训练集.csv')
print("数据维度",features.shape)
print('features=')
print(features.head(10))#####################################################
#删除前7行无效数据
features = features[7:]
#将avg列单独存起来
labels_avg = np.array(features['avg'])
print("数据维度",features.shape)
print('features=')
print(features.head(10))#####################################################
#特征中去掉无用标签
features = features.drop('high',axis=1)
features = features.drop('low',axis=1)
features = features.drop('avg',axis=1)
print("数据维度",features.shape)
print('features=')
print(features.head(10))#####################################################
#转换成可以处理的数据格式
features = np.array(features)
#预处理
from sklearn import preprocessing
input_features = preprocessing.StandardScaler().fit_transform(features)
print('input_features=')
print(input_features[0:7])#####################################################
#构造网络模型
model1 = tf.keras.Sequential()
model1.add(layers.Dense(16))
model1.add(layers.Dense(32))
model1.add(layers.Dense(1))
#对网络进行配置
model1.compile(optimizer=tf.keras.optimizers.SGD(0.001),loss='mean_squared_error')#####################################################
#训练
model1.fit(input_features, labels_avg, validation_split=0.1, epochs=50, batch_size=64)#####################################################
#读入待预测数据
tobe_predict = pd.read_csv('C:/Inst/20230411/20230411/验证集.csv')
#去除前7行数据
tobe_predict = tobe_predict[7:]
#vag列先存起来,后面用来比较验证预测的效果
tobe_predict_avg = np.array(tobe_predict['avg'])
#去掉无用的列
tobe_predict = tobe_predict.drop('avg',axis=1)
tobe_predict = tobe_predict.drop('high',axis=1)
tobe_predict = tobe_predict.drop('low',axis=1)#转换成合适的格式
tobe_predict = np.array(tobe_predict)print("数据维度",tobe_predict.shape)#预处理
tobe_predict = preprocessing.StandardScaler().fit_transform(tobe_predict)
print("tobe_predict=",tobe_predict[0:7])#####################################################
#预测模型结果
predict1 = model1.predict(tobe_predict)
print("预测的平均温度")
print(predict1)print("实际的平均温度")
print(tobe_predict_avg)

 

http://www.lryc.cn/news/249199.html

相关文章:

  • 基于SpringBoot学生读书笔记共享
  • 设计模式之装饰模式(2)--有意思的想法
  • 深入了解 Pinia:现代 Vue 应用的状态管理利器
  • TTS声音合成:paddlespeech、sherpa-onnx、coqui-ai
  • Android frameworks 开发总结之十一
  • 抑制过拟合——Dropout原理
  • 开发板启动进入系统以后再挂载 NFS 文件系统, 这里的NFS文件系统是根据正点原子教程制作的ubuntu_rootfs
  • Ubuntu系统执行“docker ps“出现“permission denied“
  • Python与设计模式--桥梁模式
  • Linux下查看目录大小
  • 鸿蒙原生应用/元服务开发-AGC分发如何下载管理Profile
  • 解决warning: #188-D: enumerated type mixed with another type问题
  • docker的知识点,以及使用
  • WTM(基于Blazor)问题处理记录
  • ubuntu 安装 towhee
  • ERP软件对Oracle安全产品的支持
  • Linux 基础-常用的命令和搭建 Java 部署环境
  • c语言总结(解题方法)
  • Webpack的ts的配置详细教程
  • 传智杯第五届题解
  • Android 通过demo调试节点权限问题
  • 邮政快递物流查询,将指定某天签收的单号筛选出来
  • Java 8 lambda的一个编译bug
  • 无人机覆盖路径规划综述
  • 【代码随想录】算法训练计划37
  • 网络基础_1
  • 机器学习:DBSCAN算法(效果比K-means好)
  • 在Spring Boot中隔离@Async异步任务的线程池
  • FFmpeg架构全面分析
  • OAuth(开放授权)介绍