GitLab wurde erfolgreich aktualisiert. Durch regelmäßige Updates bleibt das THM GitLab sicher. Danke für Ihre Geduld.

Commit 9461fe74 authored by Jens Plüddemann's avatar Jens Plüddemann

salary data

parent 4701afd4
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from statsmodels.formula.api import ols
class SalaryData:
......@@ -18,8 +20,33 @@ class SalaryData:
r = np.corrcoef(self.years, self.salary)[1, 0]
print(r)
def linear_regression(self):
b1_nominator = np.sum((self.years - np.mean(self.years)) * (self.salary - np.mean(self.salary)))
b1_denominator = np.sum((self.years - np.mean(self.years)) ** 2)
b1 = b1_nominator / b1_denominator
b0 = np.mean(self.salary) - b1 * np.mean(self.years)
print(f'Slope = {b1}')
print(f'Intercept = {b0}')
def linear_regression_sklearn(self):
regressed_data = LinearRegression().fit(self.years.to_numpy().reshape(-1, 1), self.salary.to_numpy().reshape(-1, 1))
print(f'Slope = {regressed_data.coef_[0][0]}')
print(f'Intercept = {regressed_data.intercept_[0]}')
def linear_regression_statsmodels(self):
regressed_data = ols('Salary ~ YearsExperience', data=self.df).fit().params
print(f'Slope = {regressed_data[1]}')
print(f'Intercept = {regressed_data[0]}')
if __name__ == '__main__':
data_set = SalaryData('../../res/Salary_Data.csv')
data_set.plot_initial()
data_set.pearson_correlation_coefficient()
# data_set.plot_initial()
# data_set.pearson_correlation_coefficient()
# data_set.linear_regression()
data_set.linear_regression_sklearn()
data_set.linear_regression_statsmodels()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment