Skip to content

This code is a Python script that demonstrates a basic linear regression model for predicting students' final grades based on several input features.

Notifications You must be signed in to change notification settings

MarvelBoy047/LInear-Regression

Repository files navigation

This code is a Python script that demonstrates a basic linear regression model for predicting students' final grades based on several input features. Here's a description of the key parts:

  1. Importing Modules/Packages: The code begins by importing necessary Python libraries, including Pandas for data manipulation, NumPy for numerical operations, scikit-learn (sklearn) for machine learning tools, Matplotlib for data visualization, and Pickle for model persistence.

  2. Loading Data: It loads a dataset from a CSV file called "student-mat.csv" and stores it in a Pandas DataFrame. The dataset likely contains information about students, with various attributes including "G1," "G2," "G3" (grades), "studytime," "failures," and "absences."

  3. Data Trimming: The code selects specific columns ("G1," "G2," "G3," "studytime," "failures," and "absences") from the dataset for further analysis.

  4. Data Separation: It splits the data into input (X) and output (Y) variables. "G3" is the target variable to predict, and the other selected columns are used as input features. The data is also divided into training and testing sets using scikit-learn's train_test_split function.

  5. Model Training: The code runs a linear regression model (linear_model.LinearRegression()) using the training data. It fits the model to predict students' final grades ("G3") based on the selected input features.

  6. Model Evaluation: The script calculates the accuracy (R-squared score) of the linear regression model on the test data and prints it. This metric measures how well the model predicts the final grades.

  7. Predictions: The code uses the trained model to make predictions on the test data and prints out the predicted grades alongside the actual grades for comparison.

  8. Data Visualization: It creates a scatter plot using Matplotlib, showing the relationship between the "failures" feature and the final grades ("G3"). This visualization helps visualize how failures may affect final grades.

  9. Final Model Evaluation: The code calculates and prints the final accuracy score for the linear regression model on the test data.

Note: Some parts of the code are commented out (lines with #) and appear to be for saving and loading the model using Pickle. These sections are not active in the provided code but could be used to save and load the trained model for future use.

About

This code is a Python script that demonstrates a basic linear regression model for predicting students' final grades based on several input features.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages