/
plotsinglelabelregressiontruevspredicted.jl
102 lines (99 loc) · 2.77 KB
/
plotsinglelabelregressiontruevspredicted.jl
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
##### Beginning of file
import LaTeXStrings
import PGFPlotsX
"""
"""
function plotsinglelabelregressiontrueversuspredicted(
estimator::Fittable,
features_df::DataFrames.AbstractDataFrame,
labels_df::DataFrames.AbstractDataFrame,
single_label_name::Symbol;
includeorigin::Bool = false,
legend_pos::AbstractString = "outer north east",
)::PGFPlotsXPlot
ytrue = singlelabelregressionytrue(
labels_df[single_label_name],
)
predictionsalllabels = predict(estimator, features_df)
ypred = singlelabelregressionypred(
predictionsalllabels[single_label_name],
)
truevalueversuspredictedvalue_linearplotobject = PGFPlotsX.@pgf(
PGFPlotsX.Plot(
{
only_marks,
style = "black, fill = black",
},
PGFPlotsX.Coordinates(
ypred,
ytrue,
),
)
)
if includeorigin
perfectlinevalues = sort(
unique(
vcat(
0,
ytrue,
),
);
rev = false,
)
else
perfectlinevalues = sort(
unique(
ytrue,
);
rev = false,
)
end
perfectline_linearplotobject = PGFPlotsX.@pgf(
PGFPlotsX.Plot(
{
no_marks,
style = "dotted, red, color=red, fill=red",
},
PGFPlotsX.Coordinates(
perfectlinevalues,
perfectlinevalues,
),
),
)
estimated_intercept,
estimated_x_coefficient = simple_linear_regression(
Float64.(ypred), # X
Float64.(ytrue), # Y
)
bestfitline_linearplotobject = PGFPlotsX.@pgf(
PGFPlotsX.Plot(
{
no_marks,
style = "dashed, blue, color=blue, fill=blue",
},
PGFPlotsX.Coordinates(
perfectlinevalues,
estimated_intercept .+ estimated_x_coefficient*perfectlinevalues,
),
),
)
p = PGFPlotsX.@pgf(
PGFPlotsX.Axis(
{
xlabel = LaTeXStrings.LaTeXString(
"Predicted value"
),
ylabel = LaTeXStrings.LaTeXString(
"True value"
),
legend_pos = legend_pos,
},
truevalueversuspredictedvalue_linearplotobject,
perfectline_linearplotobject,
bestfitline_linearplotobject,
),
)
wrapper = PGFPlotsXPlot(p)
return wrapper
end
##### End of file