[PYTHON] [Part 3] Use Deep Learning to forecast the weather from weather images

Until last time

Until the last time

Weather forecast from weather images using Deep Learning 1 Weather forecast from weather images using Deep Learning 2

In summary,

weather Precision Recall F-Score
rain 0.54 0.67 0.6
Fine 0.83 0.74 0.78
average 0.74 0.72 0.72

This story

This time, I would like to improve the accuracy by improving the model, teacher data, and explanatory variables.

In particular

It will be around.

analysis

Trivalent classification

Until now, it was a binary classification of "fine" and "rain". However, this contains a large amount of "cloudiness", which was one of the factors that reduced accuracy. Therefore, let's simply classify it as a ternary including "cloudy".

The conditions for teacher data generation are as follows.

flag = []
for tk in tenki_list:
	if "rain" in tk:
		flag.append(0)
	elif "Fine" in tk:
		flag.append(2)
	else:
		flag.append(1)

Rain is the highest priority, followed by fine weather and the last remaining cloudy weather.

The test result is as follows. Each probability is the average probability in the weather. Sorted in descending order of rainfall probability.

weather Rain probability Cloudy probability Clear probability
Sometimes sunny after heavy rain, accompanied by sleet 98% 0% 2%
Cloudy after rain, accompanied by hail 97% 0% 3%
rain 96% 1% 3%
heavy rain 95% 1% 4%
Sunny temporary rain 95% 0% 5%
Cloudy and sometimes sunny after a temporary rain 91% 1% 8%
Sometimes sunny after cloudy 90% 3% 6%
Rainy but sunny temporary drizzle 89% 2% 10%
Temporary cloudy after heavy rain 80% 3% 17%
Cloudy and sometimes rainy 77% 4% 19%
Cloudy and sometimes sunny with temporary rain and thunder 74% 5% 21%
Temporarily cloudy after rain 72% 6% 22%
Sunny after rain 72% 4% 24%
Cloudy temporary rain 71% 5% 24%
Cloudy after rain 71% 3% 26%
Cloudy and sometimes rain 70% 5% 25%
Sometimes cloudy after rain 67% 3% 29%
Temporary cloudy rain 63% 7% 30%
Cloudy after sunny 63% 4% 33%
Rainy and sometimes cloudy 62% 8% 30%
Rain sometimes cloudy 61% 4% 35%
Sunny and sometimes cloudy 60% 3% 37%
Cloudy and sometimes sunny 59% 5% 36%
Rain after cloudy 57% 7% 36%
Temporary rain after fine weather, accompanied by lightning 52% 11% 36%
Temporary clear after cloudy 51% 6% 44%
Sometimes cloudy after a temporary sleet of rain 50% 7% 44%
Temporary rain after cloudy weather 49% 10% 41%
Cloudy 45% 8% 47%
Light cloud 42% 7% 52%
Light cloudy temporary clear 38% 10% 52%
Sunny Temporary cloudy 38% 8% 55%
Sometimes sunny after light cloudy 38% 11% 52%
Temporarily cloudy after fine weather 34% 9% 57%
Light cloudy and sometimes sunny 34% 8% 58%
Cloudy temporary clear 33% 7% 60%
Partially cloudy 33% 9% 58%
Cloudy and sunny after rain 31% 13% 56%
Fine 30% 9% 61%
Sunny and cloudy 30% 8% 62%
Lightly cloudy after fine weather 28% 11% 61%
Sometimes cloudy after fine weather 27% 8% 65%
Sunny 25% 7% 68%
After cloudy weather 22% 10% 68%
Sometimes rain after cloudy 20% 8% 72%
Cloudy and sunny after a temporary rain 20% 11% 70%
Cloudy and sometimes sunny and then temporary rain 18% 10% 73%
After clear rain Sometimes cloudy 4% 5% 91%

As a result, cloudiness is completely unpredictable. (seriously)

Since the teacher data in the above conditional expression is as follows, I think that it makes it very difficult to estimate cloudiness.

weather Percentage
rain 33%
Cloudy 7%
Fine 59%

With this, it feels like playing only the obvious "cloudy". However, for example, if you bring in the condition that "cloudiness is included" first, the number of rain and fine weather will decrease too much, and it will be useless. Hmmm difficult.

However, the average AUC calculated only for "rain" and "fine" is 0.720, and the accuracy of these two seems to be improving. The rain and clear statistics are as follows.

weather precision recall f1-score
rain 0.60 0.76 0.67
Fine 0.69 0.71 0.70
average 0.65 0.74 0.69

Apparently, the estimation accuracy of "rain" has improved.

Increase in Epoch

Last time I did it with Epoch = 50, but this time I will set Epoch to 100. The teacher data is the same as the last time, and is a binary classification of "rain" and "fine".

The average AUC was 0.724, which is more accurate than the previous and ternary classification. (Epoch important)

The statistics are as follows.

weather precision recall f1-score
rain 0.53 0.77 0.63
Fine 0.86 0.68 0.76
average 0.76 0.71 0.72

It feels like Precision is up.

Addition of explanatory variable (image) processing

Up to this point, the explanatory variables have been used as the image data of the previous day for 3 channels. However, the original map image data is information that is common at any time and has no meaning in classification. Therefore, we will consider incorporating "changed" information by taking the difference from the previous day.

Written in code, it looks like this:

    """Convert to difference series"""
    img_mat_new = np.zeros((img_mat.shape[0],3*2,img_mat.shape[2],img_mat.shape[3]),dtype=np.float32)
    img_mat_new = img_mat_new[0:-1] #Reduce by one
    for l in range(1,len(img_mat)):
        """Difference"""
        img_mat_new[l-1,0,:,:] = img_mat[l-1,0,:,:] - img_mat[l,0,:,:]
        img_mat_new[l-1,1,:,:] = img_mat[l-1,1,:,:] - img_mat[l,1,:,:]
        img_mat_new[l-1,2,:,:] = img_mat[l-1,2,:,:] - img_mat[l,2,:,:]
        """that day"""
        img_mat_new[l-1,3,:,:] = img_mat[l,0,:,:]
        img_mat_new[l-1,4,:,:] = img_mat[l,1,:,:]
        img_mat_new[l-1,5,:,:] = img_mat[l,2,:,:]

Don't forget to reduce teacher data by one day.

In this state, set the input channel to 6 and introduce it into the model.

Then the average AUC drops to 0.658. (That's it)

The statistics are as follows.

weather precision recall f1-score
rain 0.57 0.48 0.52
Fine 0.78 0.83 0.8
average 0.71 0.72 0.71

The accuracy of the fine weather has improved, but the rain is no good. Well difficult.

Try changing the image data

What if I change the image data to another type? Until now, the resolution was 640x480, but let's change it to a high resolution image of 3000x3000. However, the problem is the ** visible ** image. (That is, the sunlight is affected by the seasons)

The image will look like the one below.

jpn.14123117.jpg

Source: Provided by Kochi University, University of Tokyo, Japan Meteorological Agency

Wow there is a black spot. .. ..

Well, it's a trial.

The average AUC is 0.675, which is lower than the conventional one.

The statistics are as follows.

weather precision recall f1-score
rain 0.69 0.45 0.54
Fine 0.77 0.9 0.83
average 0.75 0.76 0.74

The accuracy is improved when viewed with F Score. Since the AUC is 0.79, the accuracy of the fine weather has improved, but the accuracy of the rain seems to have decreased slightly.

result

I tried various things,

It became like.

Is it a good pattern to increase Epoch, classify it into three values (I want to improve rain accuracy), and make it a visible image (I want to improve fine weather accuracy)?

I want to aim for AUC 0.8 for the time being.

Since there are time-series elements, is it more accurate to extend it to RNN? (I have to study)

Recommended Posts

[Part 4] Use Deep Learning to forecast the weather from weather images
[Part 1] Use Deep Learning to forecast the weather from weather images
[Part 3] Use Deep Learning to forecast the weather from weather images
[Part 2] Use Deep Learning to forecast the weather from weather images
Deep Learning from the mathematical basics Part 2 (during attendance)
I tried to implement Perceptron Part 1 [Deep Learning from scratch]
Reinforcement learning to learn from zero to deep
Image alignment: from SIFT to deep learning
"Deep Learning from scratch" Self-study memo (Part 12) Deep learning
Get data from Poloniex, a cryptocurrency exchange, via API and use deep learning to forecast prices for the next day.
About the order of learning programming languages (from beginner to intermediate) Part 2
Deep Learning beginners tried weather forecasting from meteorological satellite images using Keras
Tweet the weather forecast with a bot Part 2
Deep Learning from scratch ① Chapter 6 "Techniques related to learning"
POST images from ESP32-CAM (MicroPython) to the server
Stock Price Forecast Using Deep Learning (TensorFlow) -Part 2-
Deep Learning from scratch
Create a dataset of images to use for learning
[Deep Learning from scratch] I implemented the Affine layer
I wanted to use the Python library from MATLAB
Othello ~ From the tic-tac-toe of "Implementation Deep Learning" (4) [End]
[Deep Learning from scratch] I tried to explain Dropout
Deep Learning from scratch 1-3 chapters
Paper: Machine learning paper that reproduces images in the brain, (Deep image reconstruction from human brain activity)
How to use the generator
[Deep learning] Investigating how to use each function of the convolutional neural network [DW day 3]
[Deep Learning from scratch] I tried to explain the gradient confirmation in an easy-to-understand manner.
[Python] I asked LINE BOT to answer the weather forecast.
How to increase the number of machine learning dataset images
(Deep learning) Images were collected from the Flickr API and discriminated by transfer learning with VGG16.
Introduction to Deep Learning ~ Learning Rules ~
I captured the Touhou Project with Deep Learning ... I wanted to.
Deep Reinforcement Learning 1 Introduction to Reinforcement Learning
"Deep Learning from scratch" Self-study memo (Part 8) I drew the graph in Chapter 6 with matplotlib
How to use the decorator
Introduction to Deep Learning ~ Backpropagation ~
[Deep Learning from scratch] About the layers required to implement backpropagation processing in a neural network
Chapter 1 Introduction to Python Cut out only the good points of deep learning made from scratch
[Machine learning] Understand from mathematics why the correlation coefficient ranges from -1 to 1.
Lua version Deep Learning from scratch Part 6 [Neural network inference processing]
How to use machine learning for work? 01_ Understand the purpose of machine learning
[Python + heroku] From the state without Python to displaying something on heroku (Part 1)
[Python + heroku] From the state without Python to displaying something on heroku (Part 2)
How to use the zip function
How to use the optparse module
Deep Learning / Deep Learning from Zero Chapter 3 Memo
How to use SWIG from waf
Deep Learning / Deep Learning from Zero 2 Chapter 5 Memo
Introduction to Deep Learning ~ Function Approximation ~
Try deep learning with TensorFlow Part 2
Deep learning from scratch (cost calculation)
Deep learning to start without GPU
Introduction to Deep Learning ~ Coding Preparation ~
Post images from Python to Tumblr
Use the Flickr API from Python
Deep Learning / Deep Learning from Zero 2 Chapter 7 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 8 Memo
Deep Learning / Deep Learning from Zero Chapter 5 Memo
Deep Learning / Deep Learning from Zero Chapter 4 Memo
Deep Learning / Deep Learning from Zero 2 Chapter 3 Memo
Deep Learning memos made from scratch