day1/session3.tex
changeset 238 1575143284cd
parent 229 5541c47bc2e8
child 239 8953675dc056
equal deleted inserted replaced
237:78ce38a1e383 238:1575143284cd
   124 %%   \frametitle{Outline}
   124 %%   \frametitle{Outline}
   125 %%   \tableofcontents
   125 %%   \tableofcontents
   126 %%   % You might wish to add the option [pausesections]
   126 %%   % You might wish to add the option [pausesections]
   127 %% \end{frame}
   127 %% \end{frame}
   128 
   128 
       
   129 \section{Statistics}
   129 \begin{frame}
   130 \begin{frame}
   130   \frametitle{More on data processing}
   131   \frametitle{More on data processing}
   131   \begin{block}{}
   132   \begin{block}{}
   132     We have a huge--1m records--data file.\\How do we do \emph{efficient} statistical computations, that is find mean, median, mode, standard deveiation etc; draw pie charts?
   133     We have a huge--1m records--data file.\\How do we do \emph{efficient} statistical computations, that is find mean, median, mode, standard deveiation etc; draw pie charts?
   133   \end{block}
   134   \end{block}
   176     \item Marks of 5 subjects: English, Hindi, Maths, Science, Social
   177     \item Marks of 5 subjects: English, Hindi, Maths, Science, Social
   177     \item Total marks
   178     \item Total marks
   178     \item Pass/Fail (P/F)
   179     \item Pass/Fail (P/F)
   179     \item Withdrawn (W)
   180     \item Withdrawn (W)
   180   \end{itemize}
   181   \end{itemize}
   181 \end{frame}
   182   \inctime{5}
   182 
   183 \end{frame}
       
   184 
       
   185 \subsection{Data processing}
   183 \begin{frame}[fragile]
   186 \begin{frame}[fragile]
   184   \frametitle{File reading and parsing \ldots}
   187   \frametitle{File reading and parsing \ldots}
   185   \begin{lstlisting}
   188   \begin{lstlisting}
   186 for record in open('sslc1.txt'):
   189 for record in open('sslc1.txt'):
   187     fields = record.split(';')
   190     fields = record.split(';')
   188   \end{lstlisting}
   191   \end{lstlisting}
   189 \end{frame}
   192 \end{frame}
   190 
   193 
       
   194 \subsection{Dictionary}
   191 \begin{frame}[fragile]
   195 \begin{frame}[fragile]
   192   \frametitle{Dictionary: Introduction}
   196   \frametitle{Dictionary: Introduction}
   193   \begin{itemize}
   197   \begin{itemize}
   194     \item lists index: 0 \ldots n
   198     \item lists index: 0 \ldots n
   195     \item dictionaries index using strings
   199     \item dictionaries index using strings
   196   \end{itemize}
   200   \end{itemize}
   197 \begin{block}{Example}
   201   \begin{block}{Example}
   198 d = \{ ``Hitchhiker's guide'' : 42,
   202 d = \{ ``Hitchhiker's guide'' : 42,
   199      ``Terminator'' : ``I'll be back''\}\\
   203      ``Terminator'' : ``I'll be back''\}\\
   200 d[``Terminator''] => ``I'll be back''
   204 d[``Terminator''] => ``I'll be back''
   201 \end{block}
   205   \end{block}
   202 \end{frame}
   206 \end{frame}
   203 
   207 
   204 \begin{frame}[fragile]
   208 \begin{frame}[fragile]
   205   \frametitle{Dictionary: Introduction}
   209   \frametitle{Dictionary: Introduction}
   206 \begin{lstlisting}
   210   \begin{lstlisting}
   207 In [1]: d = {"Hitchhiker's guide" : 42,
   211 In [1]: d = {"Hitchhiker's guide" : 42,
   208       "Terminator" : "I'll be back"}
   212       "Terminator" : "I'll be back"}
   209 
   213 
   210 In [2]: d["Hitchhiker's guide"]
   214 In [2]: d["Hitchhiker's guide"]
   211 Out[2]: 42
   215 Out[2]: 42
   213 In [3]: "Hitchhiker's guide" in d
   217 In [3]: "Hitchhiker's guide" in d
   214 Out[3]: True
   218 Out[3]: True
   215 
   219 
   216 In [4]: "Guido" in d
   220 In [4]: "Guido" in d
   217 Out[4]: False
   221 Out[4]: False
   218 \end{lstlisting}
   222   \end{lstlisting}
   219 \end{frame}
   223 \end{frame}
   220 
   224 
   221 \begin{frame}[fragile]
   225 \begin{frame}[fragile]
   222   \frametitle{Dictionary: Introduction}
   226   \frametitle{Dictionary: Introduction}
   223 \begin{lstlisting}
   227   \begin{lstlisting}
   224 In [5]: d.keys()
   228 In [5]: d.keys()
   225 Out[5]: ['Terminator', "Hitchhiker's 
   229 Out[5]: ['Terminator', "Hitchhiker's 
   226                               guide"]
   230                               guide"]
   227 
   231 
   228 In [6]: d.values()
   232 In [6]: d.values()
   229 Out[6]: ["I'll be back", 42]
   233 Out[6]: ["I'll be back", 42]
   230 \end{lstlisting}
   234   \end{lstlisting}
   231 \end{frame}
   235 \end{frame}
   232 
   236 
   233 \begin{frame}[fragile]
   237 \begin{frame}[fragile]
   234   \frametitle{enumerate: Iterating through list indices}
   238   \frametitle{enumerate: Iterating through list indices}
   235 \begin{lstlisting}
   239   \begin{lstlisting}
   236 In [1]: names = ["Guido","Alex", "Tim"]
   240 In [1]: names = ["Guido","Alex", "Tim"]
   237 
   241 
   238 In [2]: for i, name in enumerate(names):
   242 In [2]: for i, name in enumerate(names):
   239    ...:     print i, name
   243    ...:     print i, name
   240    ...: 
   244    ...: 
   241 0 Guido
   245 0 Guido
   242 1 Alex
   246 1 Alex
   243 2 Tim
   247 2 Tim
   244 \end{lstlisting}
   248   \end{lstlisting}
       
   249   \inctime{5}
   245 \end{frame}
   250 \end{frame}
   246 
   251 
   247 \begin{frame}[fragile]
   252 \begin{frame}[fragile]
   248   \frametitle{Dictionary: Building parsed data}
   253   \frametitle{Dictionary: Building parsed data}
   249     Let our dictionary be:
   254   Let our dictionary be:
   250     \begin{lstlisting}
   255   \begin{lstlisting}
   251 science = {} # is an empty dictionary
   256 science = {} # is an empty dictionary
   252     \end{lstlisting}
   257   \end{lstlisting}
   253 \end{frame}
   258 \end{frame}
   254 
   259 
   255 \begin{frame}[fragile]
   260 \begin{frame}[fragile]
   256   \frametitle{Dictionary - Building parsed data}
   261   \frametitle{Dictionary - Building parsed data}
   257   \begin{itemize}
   262   \begin{itemize}
   289 if score > 90:
   294 if score > 90:
   290     science[region_code] += 1
   295     science[region_code] += 1
   291   \end{lstlisting}
   296   \end{lstlisting}
   292 \end{frame}
   297 \end{frame}
   293 
   298 
       
   299 \subsection{Visualizing the data}
   294 \begin{frame}[fragile]
   300 \begin{frame}[fragile]
   295   \frametitle{Pie charts}
   301   \frametitle{Pie charts}
   296   \small
   302   \small
   297   \begin{lstlisting}
   303   \begin{lstlisting}
   298 figure(1)
   304 figure(1)
   306     \column{5.25\textwidth}
   312     \column{5.25\textwidth}
   307     \hspace*{1.1in}
   313     \hspace*{1.1in}
   308 \includegraphics[height=2in, interpolate=true]{data/science}
   314 \includegraphics[height=2in, interpolate=true]{data/science}
   309     \column{0.8\textwidth}
   315     \column{0.8\textwidth}
   310 \end{columns}
   316 \end{columns}
       
   317   \inctime{5}
   311 \end{frame}
   318 \end{frame}
   312 
   319 
   313 \begin{frame}[fragile]
   320 \begin{frame}[fragile]
   314   \frametitle{Building data for all subjects \ldots}
   321   \frametitle{Building data for all subjects \ldots}
   315   \begin{lstlisting}
   322   \begin{lstlisting}
   379 \begin{frame}[fragile]
   386 \begin{frame}[fragile]
   380   \frametitle{Pie charts}
   387   \frametitle{Pie charts}
   381   \includegraphics[height=3in, interpolate=true]{data/all_regions}
   388   \includegraphics[height=3in, interpolate=true]{data/all_regions}
   382 \end{frame}
   389 \end{frame}
   383 
   390 
       
   391 \subsection{Obtaining stastics}
   384 \begin{frame}[fragile]
   392 \begin{frame}[fragile]
   385   \frametitle{Obtaining statistics}
   393   \frametitle{Obtaining statistics}
   386   \begin{lstlisting}
   394   \begin{lstlisting}
   387 math_scores = array(scores[2])
   395 math_scores = array(scores[2])
   388 
   396 
   393 print "Mode: ", stats.mode(math_scores)
   401 print "Mode: ", stats.mode(math_scores)
   394 
   402 
   395 print "Standard Deviation: ",
   403 print "Standard Deviation: ",
   396               std(math_scores)
   404               std(math_scores)
   397   \end{lstlisting}
   405   \end{lstlisting}
       
   406   \inctime{15}
   398 \end{frame}
   407 \end{frame}
   399 
   408 
   400 \begin{frame}[fragile]
   409 \begin{frame}[fragile]
   401   \frametitle{What tools did we use?}
   410   \frametitle{What tools did we use?}
   402   \begin{itemize}
   411   \begin{itemize}