Visualizing a Correlation Matrix
Brindle & Co logs three numbers for each trading day -- call them x, y and z, the three the analytics feed happens to publish. Before anyone builds a model, the team wants to know which of them move together. The dashboard already colours every pair; the note underneath has to state the x-and-y figure in writing.
Task: Print the correlation between the x column and the y column.
Input
The first line holds one integer n, the number of days, where 2 <= n <= 1000. Then come n lines, each holding three numbers separated by single spaces: that day's x, y and z. Neither x nor y is the same value on every day.
Output
One line holding the Pearson correlation of x and y -- the ordinary straight-line one, which runs from -1 for a perfect fall to +1 for a perfect rise, with 0 for no straight-line link -- rounded to 2 decimal places.
Example:
Input:
4
1 10 5
2 20 3
3 30 8
4 40 1
Output:
1.00
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in