/
cricketML.m
84 lines (55 loc) · 1.53 KB
/
cricketML.m
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
%% This code provides an outline for performing Multivariate Regression to predict
%% performance of cricketers
%%
%% Developed by Tinniam V Ganesh
%% 12 Dec 2014
%% Clear and Close Figures
clear ; close all; clc
fprintf('Loading data ...\n');
%% Load Data
data = load('srt.csv'); %Load Sachin Tendulkar's data
X = data(:, 1:2); % X(:,1) = Minutes at crease X(:,2) = Balls faced
y = data(:, 3); % Runs scored
m = length(y)
figure;
scatter3(X(:,1),X(:,2),y,[],[240 15 15],'x');
maxminutes = max(X(:,1));
maxballsfaced = max(X(:,2));
% Compute cost
% Perform gradient descent
% Store the theta value
% Create a mesh grid for minutes at crease and balls faced
hold on;
x = linspace(0,maxminutes + 20,10);
y = linspace(1,maxballsfaced+ 20,10);
[XX, YY ] = meshgrid(x,y);
% Calculate the prediction plane
[a b] = size(XX)
for i=1:a,
for j= 1:b,
% Compute Normalized ZZ from XX,YY
end;
end;
% Display the prediction plane as a mesh
mesh(XX,YY,ZZ);
xlabel('Minutes at crease');
ylabel('Balls faced');
zlabel('Runs scored');
title('Sachin Tendulkar performance');
print -dpng 'srt.png';
hold off;
% Plot the convergence graph
print -dpng 'convergence-srt.png';
% Calculate predicted runs for different minutes at crease and balls faced
i=j=1;
runs=minutes=bf=zeros(13,13);
for m = 10:25:310, %Minutes played
for n = 10:25:310, %Balls faced
% Compute runs for Minutes played and Balls faced.
j = j+1;
end;
j=1;
i = i+1;
end;
runs
save srt.txt runs -ascii % save as txt file