Created
September 15, 2020 04:04
-
-
Save rodrigols89/149ba4473248a19d53e460084be79757 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from matplotlib import pyplot as plt | |
| import pandas as pd | |
| df = pd.DataFrame( | |
| { | |
| 'Grade':[50, 50, 46, 95, 50, 5, 57, 42, 26, 72, 78, 60, 40, 17, 85], | |
| 'Salary':[50000, 54000, 50000, 189000, 55000, 40000, 59000, 42000, 47000, 78000, 119000, 95000, 49000, 29000, 130000] | |
| } | |
| ) | |
| df['(x_i - x_mean)'] = df['Grade'] - df['Grade'].mean() | |
| df['(y_i - y_mean)'] = df['Salary'] - df['Salary'].mean() | |
| df['(x_i - x_mean)(y_i - y_mean)'] = df['(x_i - x_mean)'] * df['(y_i - y_mean)'] | |
| df['(x_i - x_mean)^2'] = (df['Grade'] - df['Grade'].mean())**2 | |
| m = (sum(df['(x_i - x_mean)'] * df['(y_i - y_mean)'])) / sum(df['(x_i - x_mean)^2']) | |
| b = df['Salary'].mean() - (m * df['Grade'].mean()) | |
| print("Angular Coefficient (m): {0}\nLinear Coefficient (b): {1}".format(round(m), round(b))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment