0% found this document useful (0 votes)
13 views8 pages

Assignment-Deep Learning

Uploaded by

Shashank Rah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views8 pages

Assignment-Deep Learning

Uploaded by

Shashank Rah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

01/11/2024, 15:41 Untitled11.

ipynb - Colab

!pip install meteostat pandas

Collecting meteostat
Downloading [Link] (4.6 kB)
Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packag
Requirement already satisfied: pytz in /usr/local/lib/python3.10/dist-packages
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-package
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python
Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.10/dis
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-pack
Downloading [Link] (31 kB)
Installing collected packages: meteostat
Successfully installed meteostat-1.6.8

from datetime import datetime, timedelta


import pandas as pd
from meteostat import Point, Daily

mesra = Point(23.4294, 85.4124, 350)

today = [Link]()

start_date = today - timedelta(days=60)

end_date = today

data = Daily(mesra, start_date, end_date)


data = [Link]()

if 'tmean' in [Link]:

temperatures = data[['tmean']]
else:
print("Warning: 'tmean' column not found in the data. Using 'tavg' instead.")
temperatures = data[['tavg']]

Warning: 'tmean' column not found in the data. Using 'tavg' instead.

temperatures.to_csv('[Link]', index=True)

[Link] 1/8
01/11/2024, 15:41 [Link] - Colab
import pandas as pd

temp_df = pd.read_csv('[Link]', index_col=0)

temp_df

Show hidden output

Next
steps:
Generate code
with
temp_df
toggle_off View recommended
plots
New interactive
sheet

import pandas as pd
from [Link] import MinMaxScaler

temp_df = pd.read_csv('[Link]', index_col=0)

temp_col_name = temp_df.columns[0]

scaler = MinMaxScaler()

temp_values = temp_df[temp_col_name].[Link](-1, 1)

normalized_temp = scaler.fit_transform(temp_values)

temp_df['Normalized_Temperature'] = normalized_temp

temp_df

[Link] 2/8
01/11/2024, 15:41 [Link] - Colab

tavg Normalized_Temperature

time

2024-09-03 27.9 0.815385

2024-09-04 28.2 0.861538

2024-09-05 27.9 0.815385

2024-09-06 28.1 0.846154

2024-09-07 29.1 1.000000

2024-09-08 28.6 0.923077

2024-09-09 27.2 0.707692

2024-09-10 27.0 0.676923

2024-09-11 27.8 0.800000

2024-09-12 28.3 0.876923

2024-09-13 27.8 0.800000

2024-09-14 25.3 0.415385

2024-09-15 25.0 0.369231

2024-09-16 24.7 0.323077

2024-09-17 25.5 0.446154

2024-09-18 26.4 0.584615

2024-09-19 28.1 0.846154

2024-09-20 28.7 0.938462

2024-09-21 29.0 0.984615

2024-09-22 28.7 0.938462

2024-09-23 28.1 0.846154

2024-09-24 27.1 0.692308

2024-09-25 25.2 0.400000

2024-09-26 26.2 0.553846

2024-09-27 26.1 0.538462

2024-09-28 28.0 0.830769

2024-09-29 28.2 0.861538

2024-09-30 28.5 0.907692

2024-10-01 28.5 0.907692

2024-10-02 27.8 0.800000

2024-10-03 27.8 0.800000

[Link] 3/8
01/11/2024, 15:41 [Link] - Colab
2024-10-04 27.7 0.784615

2024-10-05 27.6 0.769231

2024-10-06 26.7 0.630769

2024-10-07 27.1 0.692308

2024-10-08 26.5 0.600000

2024-10-09 26.4 0.584615

2024-10-10 26.3 0.569231

2024-10-11 26.9 0.661538

2024-10-12 26.9 0.661538

2024-10-13 26.4 0.584615

2024-10-14 25.6 0.461538

2024-10-15 25.3 0.415385

2024-10-16 25.8 0.492308

2024-10-17 26.1 0.538462

2024-10-18 26.0 0.523077

2024-10-19 26.4 0.584615

2024-10-20 25.6 0.461538

2024-10-21 25.4 0.430769

2024-10-22 24.7 0.323077

2024-10-23 24.9 0.353846

2024-10-24 23.4 0.123077

2024-10-25 22.6 0.000000

2024-10-26 23.1 0.076923

2024-10-27 25.2 0.400000

2024-10-28 26.0 0.523077

2024-10-29 26.0 0.523077

2024-10-30 26.2 0.553846

2024-10-31 25.4 0.430769

2024-11-01 24.0 0.215385

[Link] 4/8
01/11/2024, 15:41 [Link] - Colab

Next
steps:
Generate code
with
temp_df
toggle_off View recommended
plots
New interactive
sheet

def create_sequences(data, n_input_days):

X, y = [], []
for i in range(len(data) - n_input_days):
[Link](data[i:i + n_input_days])
[Link](data[i + n_input_days])
return X, y

normalized_temps = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6]


n_input_days = 3

X, y = create_sequences(normalized_temps, n_input_days)

print("X:", X)
print("y:", y)

X: [[0.1, 0.2, 0.3], [0.2, 0.3, 0.4], [0.3, 0.4, 0.5]]


y: [0.4, 0.5, 0.6]

import numpy as np
import pandas as pd
from [Link] import MinMaxScaler
from [Link] import Sequential
from [Link] import LSTM, Dense

normalized_temps = temp_df['Normalized_Temperature'].values

n_input_days = 3

def create_sequences(data, n_input_days):


X, y = [], []
for i in range(len(data) - n_input_days):
[Link](data[i:i + n_input_days])
[Link](data[i + n_input_days])
return [Link](X), [Link](y)

X, y = create_sequences(normalized_temps, n_input_days)

model = Sequential()
[Link](LSTM(units=50, activation='relu', input_shape=([Link][1], 1)))
[Link](Dense(units=1))

[Link](loss='mse', optimizer='adam')

[Link](X, y, epochs=50, batch_size=32)

[Link] 5/8
01/11/2024, 15:41 [Link] - Colab

[Link] 6/8
01/11/2024, 15:41 [Link] - Colab
<[Link] at 0x7802688087c0>

last_n_days_temps = normalized_temps[-n_input_days:]
input_sequence = [Link]([last_n_days_temps])

prediction = [Link](input_sequence)

actual_prediction = scaler.inverse_transform(prediction)

print("Predicted temperature for the next day:", actual_prediction[0][0])

1/1 ━━━━━━━━━━━━━━━━━━━━ 1s 533ms/step


Predicted temperature for the next day: 25.390377

import numpy as np
from tensorflow import keras
from [Link] import Sequential
from [Link] import LSTM, Dense

import numpy as np
from tensorflow import keras
from [Link] import Sequential
from [Link] import SimpleRNN, Dense

sequence = [10, 20, 30, 40, 50, 60, 70, 80, 90]

def create_sequences(data, seq_length):


X, y = [], []
for i in range(len(data) - seq_length - 1):
[Link](data[i:(i + seq_length)])
[Link](data[i + seq_length])
return [Link](X), [Link](y)

seq_length = 3
X, y = create_sequences(sequence, seq_length)

X = [Link](([Link][0], [Link][1], 1))

model = Sequential()
[Link](SimpleRNN(units=50, activation='relu', input_shape=(seq_length, 1)))
[Link](Dense(units=1))

[Link](loss='mse', optimizer='adam')

[Link] 7/8
01/11/2024, 15:41 [Link] - Colab
[Link](X, y, epochs=200, verbose=0)

input_seq = [Link](sequence[-seq_length:]).reshape((1, seq_length, 1))

predicted_number = [Link](input_seq)[0][0]

print("Predicted next number:", predicted_number)

UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. Whe


1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 256ms/step
Predicted next number: 110.82568

import numpy as np
from tensorflow import keras
from [Link] import Sequential
from [Link] import LSTM, Dense

text = "This is a sample text sequence."

chars = sorted(list(set(text)))
char_to_index = {char: index for index, char in enumerate(chars)}
index_to_char = {index: char for index, char in enumerate(chars)}

seq_length = 3
X, y = [], []
for i in range(len(text) - seq_length - 1):
[Link]([char_to_index[char] for char in text[i:i + seq_length]])
[Link](char_to_index[text[i + seq_length]])

X = [Link](X)
y = [Link](y)

X = [Link](([Link][0], [Link][1], 1))

X = X / float(len(chars))

model = Sequential()
[Link](LSTM(units=50, activation='relu', input_shape=(seq_length, 1)))
[Link](Dense(units=len(chars), activation='softmax'))

[Link](loss='sparse_categorical_crossentropy', optimizer='adam')

[Link](X, y, epochs=100, verbose=0)

[Link] 8/8

You might also like