Created
December 2, 2022 22:57
-
-
Save mamigot/d15ac7a1dae52c171369eb783035bca3 to your computer and use it in GitHub Desktop.
RNN in Python that you could use to predict your final grade in a course based on the grades you have received on various assessments:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
# Define the input data | |
X = np.array([ | |
[10], # grade on first assessment | |
[20], # grade on second assessment | |
[30] # grade on third assessment | |
]) | |
# Define the target variable | |
y = np.array([ | |
[80] # final grade in the course | |
]) | |
# Define the RNN model | |
model = tf.keras.models.Sequential([ | |
tf.keras.layers.SimpleRNN(units=10, input_shape=(1, 1)), | |
tf.keras.layers.Dense(units=1) | |
]) | |
# Compile the model | |
model.compile(optimizer='adam', loss='mean_squared_error') | |
# Fit the model on the data | |
model.fit(X, y, epochs=100) | |
# Define the input data for which we want to make a prediction | |
X_test = np.array([ | |
[15], # grade on fourth assessment | |
[25], # grade on fifth assessment | |
[35] # grade on sixth assessment | |
]) | |
# Make predictions using the model | |
predictions = model.predict(X_test) | |
# Print the predictions | |
print(predictions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment