浅用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)
相关推荐
幂律智能几秒前
穿透式监管之下,合同分级分类如何落地
人工智能
QY_Research_10 分钟前
全球智能交通系统物联网市场规模及CAGR14.2%深度分析
大数据·网络·人工智能·物联网·制造
Zzj_tju11 分钟前
32 分钟不是完成科研:多智能体读脑图谱,突破在哪里?
人工智能·机器学习·语言模型·自然语言处理
涛思数据(TDengine)18 分钟前
直播预告 | 知识图谱,让文档自动变成知识网络
人工智能·ai·知识图谱·时序数据库·tdengine·工业ai
优利德19 分钟前
优利德发布67GHz高性能矢量网络分析仪,为AI算力爆发助力
人工智能
软件工程师文艺20 分钟前
AI 编程新范式:Spec Kit 的规格驱动开发到底在解决什么
人工智能·驱动开发
梦帮科技22 分钟前
量子纠缠网络与量子隐形传态攻防:量子中继器信道串扰、纠缠态保真度降解与量子路由劫持
开发语言·网络·人工智能·算法·自动化·php
Z-D-K23 分钟前
AI 安全:让能力、权限与责任同步增长
人工智能·安全
海宇服务27 分钟前
零信任架构实战:基于海宇风控经营异常预警构建自动化央企物资采购供应商资信排查网关
运维·人工智能·架构·自动化
Geek-Chow27 分钟前
00 · DeepSeek V4.1 Flash 大规模推理部署实践学习指南:总览、思维导图与阅读路线(专栏目录)
人工智能·1024程序员节