神经网络_使用TensorFlow预测气温

import datetime
import numpy as np
import pandas as pd 
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras import layers
import tensorflow.keras 
import warnings
from sklearn import preprocessing
warnings.filterwarnings("ignore")
%matplotlib inline

1.数据预处理

1.1导入数据

temperatures = pd.read_csv('tf_temperature.csv')
print("数据维度", temperatures.shape)
temperatures.head()

数据维度 (348, 9)
year month day week temp_2 temp_1 average actual friend
0 2016 1 1 Fri 45 45 45.6 45 29
1 2016 1 2 Sat 44 45 45.7 44 61
2 2016 1 3 Sun 45 44 45.8 41 56
3 2016 1 4 Mon 44 41 45.9 40 53
4 2016 1 5 Tues 41 40 46.0 44 41

数据说明

  • temp_2 前天的最高温度值
  • temp_1 昨天的最高温度值
  • averate 历史上,每年这一天的平均最高温度值
  • actual 标签值,当天的真实的最高温度值
  • friend 朋友猜测的温度值,忽略

1.2 处理时间数据

years = temperatures['year']
months = temperatures['month']
days = temperatures['day']

#转为datetime格式
temp_days = [str(int(year)) + '-' + str(int(month)) + '-' + str(int(day)) for year, month, day in zip(years, months, days)]
temp_days = [datetime.datetime.strptime(date, '%Y-%m-%d') for date in temp_days]
print(temp_days[:5])
[datetime.datetime(2016, 1, 1, 0, 0), datetime.datetime(2016, 1, 2, 0, 0), datetime.datetime(2016, 1, 3, 0, 0), datetime.datetime(2016, 1, 4, 0, 0), datetime.datetime(2016, 1, 5, 0, 0)]

1.3 原始数据画图展示

#画图风格
plt.style.use('fivethirtyeight')
#布局
fig,((plt1,plt2),(plt3,plt4)) = plt.subplots(nrows=2, ncols=2,figsize=(10,10))
fig.autofmt_xdate(rotation = 45)
#标签值
plt1.plot(temp_days, temperatures['actual'])
plt1.set_xlabel('')
plt1.set_ylabel('Temperature')
plt1.set_title('Max Temp')

plt2.plot(temp_days, temperatures['temp_1'])
plt2.set_xlabel('')
plt2.set_ylabel('Temperature')
plt2.set_title('Yesterday Max Temp')

plt3.plot(temp_days, temperatures['temp_2'])
plt3.set_xlabel('')
plt3.set_ylabel('Temperature')
plt3.set_title('The Day Before Yesterday Temp')

plt4.plot(temp_days, temperatures['friend'])
plt4.set_xlabel('')
plt4.set_ylabel(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值