Python project that calculates and plots linear regression
Clone this repository to your local machine:
- Start the program by running
main.py - Enter the file location of your
.csvfile - From there, a menu of options will appear:
Enter VIEW to view an abbreviated form of the selected dataset.
Enter LINREG to calculate and graph a linear regression line.
Enter NEW to select another dataset.
Enter EXIT to exit the program.
To proceed with calculating the linear regression line, enter LINREG, then:
- Input the x and y variables (case-sensitive)
- The program will display a preview of the selected variables, enter ‘y’ to proceed or ‘n’ to return to the menu
- The program will then return the equation for the line of best fit, as well as the coefficient of determination (r^2)
- Enter ‘y’ to view the a graph of the dataset or ‘n’ to exit the program
Pandas: A powerful data analysis and manipulation tool.
Matplotlib Pylot: A collection of functions that allows for plotting and the visualization of data.
A directory of sample datasets are provided in datasets\. They were sourced from MainakRepositor's Datasets.
main.py contains helper functions that handle reading files and the prompts shown on the command line.
linreg.py contains two functions: linreg() and eval().
linreg() takes in two lists (x, y) and returns a tuple (a, b) that corresponds to the linear form y = ax + b pf the linear regression line.
eval() takes in two lists (x, y) and a tuple (a, b) and returns r^2 as a float