File size: 1,517 Bytes
5575a8a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import tensorflow as tf
import numpy as np
import joblib
import os
def predict_marks(num_courses, time_study):
# Load model and scalers
if not (os.path.exists('student_marks_rnn_model.h5') and
os.path.exists('scaler_X.pkl') and
os.path.exists('scaler_y.pkl')):
return "Error: Model or scalers not found. Please run train_rnn.py first."
model = tf.keras.models.load_model('student_marks_rnn_model.h5')
scaler_X = joblib.load('scaler_X.pkl')
scaler_y = joblib.load('scaler_y.pkl')
# Preprocess input
input_data = np.array([[num_courses, time_study]])
input_scaled = scaler_X.transform(input_data)
# Reshape for RNN (Samples, TimeSteps, Features)
input_reshaped = input_scaled.reshape((1, 1, 2))
# Predict
prediction_scaled = model.predict(input_reshaped)
prediction = scaler_y.inverse_transform(prediction_scaled)
return prediction[0][0]
if __name__ == "__main__":
print("--- Student Marks Prediction RNN ---")
try:
nc = float(input("Enter number of courses: "))
ts = float(input("Enter time spent studying (hours): "))
result = predict_marks(nc, ts)
if isinstance(result, str):
print(result)
else:
print(f"\nPredicted Marks: {result:.2f}")
except ValueError:
print("Invalid input. Please enter numeric values.")
except Exception as e:
print(f"Error: {e}")
|