Deep Learning Project – Hours Studied vs Exam Score using ANN Model
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
import numpy as np # For data handling.
import pandas as pd # # For data handling.
from sklearn.model_selection import train_test_split # Split data into train and test.
from sklearn.preprocessing import MinMaxScaler # Normalize the data between 0 and 1.
from tensorflow.keras.models import Sequential # Used to build the Neural Network using Keras.
from tensorflow.keras.layers import Dense # Used to build the Neural Network using Keras.
import matplotlib.pyplot as plt # To visualize the training process (loss over epochs).
# Sample Data (Hours Studied vs Exam Score)
data = {
'Hours': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'Score': [15, 25, 35, 45, 55, 65, 70, 78, 88, 95]
}
df = pd.DataFrame(data)
df.shape
# Feature and Target
X = df[['Hours']] # InDepended variable (Input)
y = df['Score'] # Depended variable (output)
y.head()
# Normalize Features
# Neural networks work better if data is between 0 and 1.
# MinMaxScaler converts Hours into 0–1 range.
# Prevents big numbers from dominating small numbers during training.
# For Example orignal hours 1 --> 0.0 , 10 --> 1.0
scaler = MinMaxScaler()
X_scaled = scaler.fit_transform(X)
X_scaled
# Split Data
# 80% data for training, 20% data for testing.
# random_state=42 ensures reproducibility.
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)
X_test
# Build ANN Model
model = Sequential()
model.add(Dense(10, activation='relu', input_shape=(1,))) # Input + Hidden
model.add(Dense(1)) # Output layer
# Compile Model
model.compile(optimizer='adam', loss='mean_squared_error')
# Train Model
history = model.fit(X_train, y_train, validation_split=0.2, epochs=100, verbose=0)
# epochs=100: Model goes through training data 100 times.
# validation_split=0.2: Use 20% of training data for validation.
# verbose=0: No training output printed.
#The model adjusts weights over epochs to minimize loss.
# Make Predictions
predicted_score = model.predict(np.array([[0.8]]))
#predicted_score = model.predict([[0.8]]) # normalized value for 8 hours
print(f"Predicted Score for 8 hours of study: {predicted_score[0][0]:.2f}")
You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

