Name – Vaishnav Jayant Mangar
MIS- 732392037
Sub-Predictive Analysis
Dataset Given – [Link]
Answer – Part 1 – Graphs and Insights
Part 2- Data Exploration and Model Building(Logistics Regression)
Part 1 -Insights –(Graphs and Insights)
1.
Sum of Exam_Score by Motivation_Level
250000
200000
150000
100000
50000
0
High Low Medium
The bar chart shows the Sum of Exam Scores for students grouped by different Motivation Levels (High,
Low, Medium).
The y-axis represents the total sum of exam scores across all students in each motivation category.
The x-axis categorizes students by their Motivation Level: High, Low, and Medium.
Insights
1. Medium Motivation Level Leads to Highest Scores: Students with a medium motivation level
have the highest sum of exam scores, suggesting that they may perform better collectively
compared to those with high or low motivation.
2. Low Motivation Scores Higher than High Motivation: Interestingly, students with low motivation
have a higher cumulative score than those with high motivation. This may suggest that other
factors besides motivation impact scores or that high motivation alone does not guarantee better
academic performance.
2.
Sum of Exam_Score by Extracurricular_Activities
300000
250000
200000
150000
100000
50000
0
No Yes
This bar chart shows the Sum of Exam Scores for students grouped by their participation in
Extracurricular Activities (Yes or No).
The y-axis represents the cumulative exam scores of students within each group.
The x-axis distinguishes students who participate in extracurricular activities (Yes) from those who
do not (No).
Insights
1. Higher Scores with Extracurricular Participation: Students who participate in extracurricular
activities have a higher total exam score than those who do not. This suggests a positive
association between extracurricular involvement and academic performance.
2. Potential Benefits of Balanced Engagement: The results could imply that students who engage in
activities outside of academics might develop skills or attributes (such as time management or
discipline) that benefit their academic success.
3.
Sum of Exam_Score by Extracurricular_Activities
300000
250000
200000
150000
100000
50000
0
No Yes
Graph Description:
The chart is a bar graph titled "Sum of Exam_Score by Extracurricular_Activities". It displays the total
exam scores grouped by whether or not students participated in extracurricular activities.
Insights:
1. Extracurricular Activities Lead to Higher Scores: The bar for "Yes" is significantly taller than
the one for "No," indicating that students who participated in extracurricular activities tend to
achieve higher combined exam scores.
Possible Interpretations:
Enhanced Skills: Extracurricular activities can develop various skills like time management,
teamwork, leadership, and problem-solving, which can positively impact academic performance.
Motivation and Engagement: Participating in extracurricular activities might increase motivation
and engagement in learning, leading to better academic outcomes.
4.
Sum of Exam_Score by Parental_Involvement
250000
200000
150000
100000
50000
0
High Low Medium
Graph Description:
The chart is a bar graph titled "Sum of Exam_Score by Parental_Involvement". It displays the total exam
scores grouped by three levels of parental involvement: High, Low, and Medium. The y-axis represents
the sum of exam scores, and the x-axis shows the different levels of parental involvement.
Insights:
1. Medium Parental Involvement Yields Highest Scores: The bar for Medium parental
involvement is significantly taller than the others, indicating that students with medium levels of
parental involvement tend to achieve the highest combined exam scores.
2. Low Parental Involvement Leads to Lower Scores: The bar for Low parental involvement is the
shortest, suggesting that students with low levels of parental engagement tend to have the lowest
combined exam scores.
3. High Parental Involvement Has a Moderate Impact: The bar for High parental involvement is
taller than the one for Low but shorter than the one for Medium. This implies that while high
levels of parental involvement are beneficial, they may not necessarily result in the highest scores
compared to medium levels.
Part 2 - Data Analysis and Model Building :
In [36]: import pandas as pd
import numpy as np
import [Link] as plt
import seaborn as sns
%matplotlib inline
from [Link] import RandomForestRegressor from
sklearn.linear_model import LinearRegression from
[Link] import LabelEncoder
from sklearn.model_selection import train_test_split
from [Link] import StandardScaler, OneHotEncoder
from [Link] import mean_absolute_error, mean_squared_error,
r2_score
from [Link] import make_regression
Out[36] Hours_Studied Attendanc Parental_Involvem Access_to_Resour Extracurricular_Activi
: e ent ces ties
0 23 84 Low High No
1 19 64 Low Medium No
2 24 98 Medium Medium Yes
3 29 89 Low Medium Yes
4 19 92 Medium Medium Yes
5 19 88 Medium Medium Yes
6 29 84 Medium Low Yes
7 25 78 Low High Yes
8 17 94 Medium High No
9 23 98 Medium Medium Yes
In [37]: [Link]()
<class '[Link]'>
RangeIndex: 6607 entries, 0 to 6606
Data columns (total 20 columns):
# Column Non-Null Count Dtype
0 Hours_Studied 6607 non-null int64
1 Attendance 6607 non-null int64
2 Parental_Involvement 6607 non-null object
3 Access_to_Resources 6607 non-null object
4 6607 non-null object
Extracurricular_Activities
5 Sleep_Hours 6607 non-null int64
6 Previous_Scores 6607 non-null int64
7 Motivation_Level 6607 non-null object
8 Internet_Access 6607 non-null object
9 Tutoring_Sessions 6607 non-null int64
10 Family_Income 6607 non-null object
11 Teacher_Quality 6529 non-null object
12 School_Type 6607 non-null object
13 Peer_Influence 6607 non-null object
14 Physical_Activity 6607 non-null int64
15 Learning_Disabilities 6607 non-null object
16 Parental_Education_Level 6517 non-null object
17 Distance_from_Home 6540 non-null object
18 Gender 6607 non-null object
19 Exam_Score 6607 non-null int64
dtypes: int64(7), object(13)
memory usage: 1.0+ MB
In [Link]
[38]:
(6607, 20)
Out[38]
:
In [Link]()
[39]:
Out[39] Hours_Studied Attendance Sleep_Hours Previous_Scores
:
Tutoring_Sessions Physical_Activ count 6607.000000 6607.000000
6607.00000 6607.000000 6607.000000 6607.0000
mean 19.975329 79.977448 7.02906 75.070531 1.493719 2.9676
std 5.990594 11.547475 1.46812 14.399784 1.230570 1.0312
min 1.000000 60.000000 4.00000 50.000000 0.000000
0.0000
25% 16.000000 70.000000 6.00000 63.000000 1.000000 2.0000
50% 20.000000 80.000000 7.00000 75.000000 1.000000
75% 3.0000
24.000000 90.000000 8.00000 88.000000 2.000000 4.0000
max 44.000000 100.000000 10.00000 100.000000 8.000000
6.0000
In [40]: [Link]()
Hours Studied 41
Out[40]:
Attendance 41
Parental_Involvement 3
Access_to_Resources 3
Extracurricular_Activitie 2
s
Sleep_Hours 7
Previous_Scores 51
Motivation_Level 3
Internet_Access 2
Tutoring_Sessions 9
Family_Income 3
Teacher_Quality 3
School_Type 2
Peer_Influence 3
Physical_Activity 7
Learning_Disabilities 2
Parental_Education_Level 3
Distance_from_Home 3
Gender 2
Exam_Score 45
dtype: int64
In [Link]
Hours Studied int64
Out[41]
: Attendance int64
Parental Involvement object
Access_to_Resources
object
Extracurricular_Activities
object Sleep_Hours
int64
Previous_Scores int64
Motivation_Level object
Internet Access object
Tutoring Sessions int64
Family Income object
Teacher Quality object
School Type object
Peer Influence object
Physical Activity int64
Learning Disabilities object
Parental_Education_Level object
Distance_from_Home
object
In Gender object
[42]: Exam Score int64
type: object
data['Gender'].value_counts().plot(kind='bar',y='value_column',
Out[42] <Axes: title={'center': 'Frequency
color='Indigo',title='Frequency DistributionofofGender')
Distribution Gender'}, xlabel='Gender'>
:
In [43]: data['School_Type'].value_counts().plot(kind='bar',y='value_cou
lmn', title='Frequency Distribution of
School_Type')
<Axes: title={'center': 'Frequency Distribution of School_Type'},
Out[43]
: xlabel='School_T ype'>
[45]:
In
[44]:
Out[44]
:
In # missing values
missing_values = [Link]().sum()
[Link](data["Exam_Score"])
<Axes:
>
# Convert categorical columns to numerical
data_encoded = [Link]()
data_encoded['Gender'] = data_encoded['Gender'].map({'Male': 1, 'Female': 0})
data_encoded['Family_Income'] = data_encoded['Family_Income'].map({'Low': 1, 'Medi
data_encoded['Access_to_Resources'] = data_encoded['Access_to_Resources'].map({'Low
Out[45] (Hours_Studied 0
: Attendance 0
Parental_Involvement 0
Access_to_Resources 0
Extracurricular_Activitie 0
s
Sleep_Hours 0
Previous_Scores 0
Motivation_Level 0
Internet_Access 0
Tutoring_Sessions 0
Family_Income 0
Teacher_Quality 78
School_Type 0
Peer_Influence 0
Physical_Activity 0
Learning_Disabilities 0
Parental_Education_Level 90
Distance_from_Home 67
Gender 0
Exam_Score 0
dtype: int64,
Hours_Studied Parental_Involveme Access_to_Resourc \
Attendance nt es
0 23 84 Low 3
1 19 64 Low 2
2 24 98 Medium 2
3 29 89 Low 2
4 19 92 Medium 2
Extracurricular_Activiti Sleep_Hours Previous_Score Motivation_Leve \
es 7 s l
0 No 73 Low
1 No 8 59 Low
2 Yes 7 91 Medium
3 Yes 8 98 Medium
4 Yes 6 65 Medium
Internet_Access Tutoring_Session Family_Incom Teacher_Quali \
s e ty
0 Yes 0 1 Medium
1 Yes 2 2 Medium
2 Yes 2 2 Medium
3 Yes 1 2 Medium
4 Yes 3 2 High
School_Type Peer_Influence Physical_Activity Learning_Disabilities \
0 Public Positive 3 No
1 Public Negative 4 No
2 Public Neutral 4 No
3 Public Negative 4 No
4 Public Neutral 4 No
Parental_Education_Leve Distance_from_Hom Gender Exam_Score
l e
0 High Near 1 67
School
1 Moderate 0 61
College
2 Near 1 74
Postgraduate
3 High Moderate 1 71
School
4 Near 0 70 )
College
In [46]: # SatisfactionScore distribution
[Link](figsize=(8, 5))
[Link](data_encoded['Exam_Score'], bins=20, kde=True)
[Link]("Distribution of Exam_Score")
[Link]("Exam_Score")
[Link]("Frequency")
[Link]()
In [47]: #Converting Categorical columns to numerical Columns
encoder = LabelEncoder()
data["Gender"] = encoder.fit_transform(data["Gender"])
data["Access_to_Resources"] =
In [48]: # categorical variables
label_encoders = {}
categorical_columns = ['Gender', 'Access_to_Resources', 'Exam_Score',
'Family_Incom
# label encoding to each categorical column
for column in
categorical_columns: le =
LabelEncoder()
data[column] =
le.fit_transform(data[column])
label_encoders[column] = le
# continuous variables
In [49]: # Example - replace 'target_column' with the actual target column name
X =
[Link](columns=['Exam_Score']) y
= data['Exam_Score']
# Split the data into training and testing sets
from sklearn.model_selection import train_test_split
In [57]: data_encoded = pd.get_dummies(data, drop_first=True)
# Calculate the correlation matrix
correlation_matrix = data_encoded.corr()
# Plot the heatmap
[Link](figsize=(20, 8)) # Adjust the figure size as needed
[Link](correlation_matrix, annot=True, cmap='coolwarm', fmt=".2f",
linewidths [Link]("Correlation Heatmap")
In [58]: # LINEAR REGRESSION MODEL
X = data_encoded.drop(columns=['Hours_Studied', 'Sleep_Hours',
'Exam_Score']) y = data_encoded['Exam_Score']
# dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_st
# linear regression model
model = LinearRegression()
[Link](X_train, y_train)
# predictions
y_pred = [Link](X_test)
# Evaluating
mae = mean_absolute_error(y_test,
y_pred) mse =
mean_squared_error(y_test, y_pred)
(0.4395325970265384, 0.6767362990018051, 0.5134397126727787)
Out[58]
:
In x,y= make_regression(noise=40,n_features=1)
[59]: [Link](x,y)
[Link]()
In [60]: linreg=LinearRegression()
[Link](x,y)
a=linreg.coef_
b=linreg.intercept_
p=[Link](-3,3,100)
q=a*p+b
[Link](p,q,)
[Link](x,y)
<[Link] at 0x1e1ccef39d0>
Out[60]
:
Insights from Dataset Exploration
1. Variable Distributions:
o The dataset includes variables like Hours_Studied, Attendance, Sleep_Hours,
and Previous_Scores, which are critical for predicting Exam_Score.
o Exam score distribution, as visualized, provides insight into the central
tendency and spread of students’ performance.
2. Correlation Analysis:
o The correlation heatmap helps identify relationships between predictors (e.g.,
Hours_Studied, Attendance) and Exam_Score. Variables with strong
correlations to Exam_Score are likely significant predictors.
o
Model Selection
To predict student exam scores, a regression model is suitable because the target variable,
Exam_Score, is continuous. Here’s why and how you might approach this with a linear
regression model:
Linear Regression is a simple, interpretable model that assumes a linear relationship
between the predictors and the target variable. It’s useful for determining how each
factor influences Exam_Score.
Random Forest Regressor is another option, particularly when the relationship
between variables is more complex and may not be linear. This model can capture
interactions between variables without needing feature scaling.
Steps to Implement the Model
1. Data Preprocessing:
o Handling Missing Values: Fill or drop missing values to ensure a complete
dataset for training.
o Encoding Categorical Variables: Convert categorical features (like
Parental_Involvement and Access_to_Resources) into numerical form using
techniques like one-hot encoding.
o Scaling: Standardize or normalize continuous variables, especially for models
sensitive to feature scales (like linear regression).
2. Data Splitting:
o Split the data into training and testing sets (e.g., 80% training, 20% testing) to
evaluate model performance accurately.
3. Model Training:
o Train the chosen model (e.g., linear regression or random forest) on the
training data.
o Hyperparameter Tuning: For models like random forests, consider tuning
parameters like n_estimators and max_depth to optimize performance.
4. Model Evaluation:
o Calculate metrics such as Mean Absolute Error (MAE), Root Mean
Squared Error (RMSE), and R² Score to assess model accuracy.
o Interpret Results: Higher R² values and lower error metrics indicate better
model fit. Insights on feature importance (e.g., coefficients in linear
regression) can reveal which factors most impact exam performance.
5. Visualization of Results:
o Scatter Plot: Compare predicted vs. actual scores to evaluate model
predictions visually.
o Residual Plot: Check residuals to identify any patterns, which can indicate
whether model assumptions (like linearity) hold.
This process will enable effective predictions of exam scores and reveal significant factors
influencing student performance. Let me know if you'd like more specifics on any step or
additional visualization suggestions.