Ich habe einen Code erstellt, um den Regressionskoeffizienten der einfachen Regressionsanalyse zu berechnen. Verwenden Sie ihn also bitte, wenn Sie möchten!
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
Column 1 | Column 2 |
---|---|
2.2 | 71 |
4.1 | 81 |
5.5 | 86 |
1.9 | 72 |
3.4 | 77 |
2.6 | 73 |
4.2 | 80 |
3.7 | 81 |
4.9 | 85 |
3.2 | 74 |
dataset = pd.read_csv('test.csv')
Extrahieren Sie Spalten mit X als erklärende Variable und y als Zielvariable.
X = dataset.iloc[:, :-1].values #Indepand variable
y = dataset.iloc[:, 1].values #Depand variable
# Calculate Mean
Sum_X = sum(X)
N_X = len(X)
Mean_X = Sum_X / N_X
Sum_y = sum(y)
N_y = len(y)
Mean_y = Sum_y / N_y
# Calcuate Deviation
Devi_X = []
for Row_X in X:
Devi_X.append(Row_X - Mean_X)
Devi_y = []
for Row_y in y:
Devi_y.append(Row_y - Mean_y)
# Multiply Deviation X and y
counter = 0
MD_Xy = []
while counter < len(Devi_X):
MD_Xy_Value = Devi_X[counter] * Devi_y[counter]
MD_Xy.append(MD_Xy_Value)
counter += 1
# Sum of Multiply Deviation X and y
SMD_Xy = sum(MD_Xy)
# Squares of Calcuate Deviation
Sq_Devi_X = []
for DX in Devi_X:
Sq_Devi_X.append(DX * DX)
Sq_Devi_y = []
for Dy in Devi_y:
Sq_Devi_y.append(Dy * Dy)
# Sum of Squares of Calcuate Deviation
SSX = sum(Sq_Devi_X)
SSy = sum(Sq_Devi_y)
# Calculate Regression paramator
betaOne = SMD_Xy / SSX
betaZero = Mean_y - betaOne * Mean_X
Recommended Posts