Hi,
How do I randomly select 12 elements of data for the training list to obtain the highest correlation coefficient for the testing list (CCtest)?
data = {{0.`, 0.048}, {0.2`, 0.424}, {0.4`, 0.943}, {0.60, 1.177}, {0.8`,
1.475}, {1.`, 1.839}, {1.200, 2.134}, {1.400, 2.395}, {1.6`,
2.564}, {1.8`, 2.814}, {2.`, 2.981}, {2.2`, 2.972}, {2.400, 3.133}, {2.6`,
2.99}, {2.80, 3.190}, {3.`, 3.184}};
train = Take[data, 12]
{{0., 0.048}, {0.2, 0.424}, {0.4, 0.943}, {0.6, 1.177}, {0.8, 1.475}, {1.,
1.839}, {1.2, 2.134}, {1.4, 2.395}, {1.6, 2.564}, {1.8, 2.814}, {2.,
2.981}, {2.2, 2.972}}
lm = LinearModelFit[train, x, x];
gg[x_, y_] := 0.308+1.36x
YPtrain = Map[gg[#[[1]], #[[2]]] &, train]
{0.308, 0.58, 0.852, 1.124, 1.396, 1.668, 1.94, 2.212, 2.484, 2.756, 3.028, \
3.3}
Ytrain = train[[All, 2]]
{0.048, 0.424, 0.943, 1.177, 1.475, 1.839, 2.134, 2.395, 2.564, 2.814, 2.981, \
2.972}
CCtrain = Correlation[YPtrain, Ytrain]
0.985044
Evaluation of 0.308+1.36 x for the testing data:
test = Take[data, -4]
{{2.4, 3.133}, {2.6, 2.99}, {2.8, 3.19}, {3., 3.184}}
YPtest = Map[gg[#[[1]], #[[2]]] &, test]
{3.572, 3.844, 4.116, 4.388}
Ytest = test[[All, 2]]
{3.133, 2.99, 3.19, 3.184}
CCtest = Correlation[YPtest, Ytest]
0.489591


