-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01Evaluation.py
More file actions
43 lines (36 loc) · 1.73 KB
/
01Evaluation.py
File metadata and controls
43 lines (36 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pandas as pd
from typing import List, Optional
import math
def linearRegressionScore(X, y):
# using linear regression score function to compute the r2
from sklearn.linear_model import LinearRegression
model = LinearRegression()
model.fit(X, y)
r_squared = model.score(X, y)
return r_squared
def evaluation(predictionAge):
from sklearn.metrics import mean_absolute_error, mean_squared_error
mean_squared_error = mean_squared_error(predictionAge["Age"].values, predictionAge["prediction"].values)
mean_absolute_error = mean_absolute_error(predictionAge["Age"].values, predictionAge["prediction"].values)
r2_score = linearRegressionScore(predictionAge[["Age"]], predictionAge[["prediction"]])
dataCorr = predictionAge["Age"].corr(predictionAge['prediction'], method='pearson')
return mean_squared_error, mean_absolute_error, r2_score, dataCorr
SkinPathwayAgePrecdiction = pd.read_pickle("./Precdiction.pickle")
MSEList = []
MAEList = []
R2List = []
RhoList = []
CohortList = []
for cohort in SkinPathwayAgePrecdiction.Cohort.unique():
# test the control group only
predictionPerCohort = SkinPathwayAgePrecdiction[SkinPathwayAgePrecdiction.Label.eq(0) & SkinPathwayAgePrecdiction.Cohort.eq(cohort)].dropna()
if not predictionPerCohort.empty:
mean_squared_error, mean_absolute_error, r2_score, dataCorr = evaluation(predictionPerCohort)
MSEList.append(mean_squared_error)
MAEList.append(mean_absolute_error)
R2List.append(r2_score)
RhoList.append(dataCorr)
CohortList.append(cohort)
Evaluation = pd.DataFrame(data = [MSEList, MAEList, R2List, RhoList, CohortList], index = ["MSE", "MAE", "r2", "Corr", "Cohort"]).T
Evaluation["Tag"]= "Control"
Evaluation