Created
December 2, 2022 22:58
-
-
Save mamigot/980661eb4a76f7f998b7bf89d3ffc405 to your computer and use it in GitHub Desktop.
CNN 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 | |
]) | |
# Reshape the input data | |
X = X.reshape(X.shape[0], 1, 1) | |
# Define the CNN model | |
model = tf.keras.models.Sequential([ | |
tf.keras.layers.Conv1D(filters=10, kernel_size=1, input_shape=(1, 1)), | |
tf.keras.layers.Flatten(), | |
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 | |
]) | |
# Reshape the input data | |
X_test = X_test.reshape(X_test.shape[0], 1, 1) | |
# 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