-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2013-02-01-Obtaining-Data.html
944 lines (716 loc) · 26.8 KB
/
2013-02-01-Obtaining-Data.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>2013-02-01-Obtaining-Data</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="2013-02-01-Obtaining-Data"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2013-02-01 13:45:14 PST"/>
<meta name="author" content="Jim Blomo"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link rel="stylesheet" type="text/css" href="production/common.css" />
<link rel="stylesheet" type="text/css" href="production/screen.css" media="screen" />
<link rel="stylesheet" type="text/css" href="production/projection.css" media="projection" />
<link rel="stylesheet" type="text/css" href="production/color-blue.css" media="projection" />
<link rel="stylesheet" type="text/css" href="production/presenter.css" media="presenter" />
<link href='http://fonts.googleapis.com/css?family=Lobster+Two:700|Yanone+Kaffeesatz:700|Open+Sans' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="preamble">
</div>
<div id="content">
<h1 class="title">2013-02-01-Obtaining-Data</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1 Obtaining Data</a></li>
<li><a href="#sec-2">2 Ways to Collect</a>
<ul>
<li><a href="#sec-2-1">2.1 Operational Data</a>
<ul>
<li><a href="#sec-2-1-1">2.1.1 Data from production</a></li>
</ul>
</li>
<li><a href="#sec-2-2">2.2 Example</a>
<ul>
<li><a href="#sec-2-2-1">2.2.1 Distributed Data</a></li>
</ul>
</li>
<li><a href="#sec-2-3">2.3 Data Warehouse</a>
<ul>
<li><a href="#sec-2-3-1">2.3.1 No free lunch</a></li>
</ul>
</li>
<li><a href="#sec-2-4">2.4 Unstructured</a>
<ul>
<li><a href="#sec-2-4-1">2.4.1 Yelp JSON logs</a></li>
</ul>
</li>
<li><a href="#sec-2-5">2.5 Search Logs Example</a>
<ul>
<li><a href="#sec-2-5-1">2.5.1 Imposing Structure</a></li>
</ul>
</li>
<li><a href="#sec-2-6">2.6 External APIs</a>
<ul>
<li><a href="#sec-2-6-1">2.6.1 Motivation</a></li>
</ul>
</li>
<li><a href="#sec-2-7">2.7 NYTimes API Example</a>
<ul>
<li><a href="#sec-2-7-1">2.7.1 Accessing these</a></li>
</ul>
</li>
<li><a href="#sec-2-8">2.8 Data Sets</a>
<ul>
<li><a href="#sec-2-8-1">2.8.1 Research</a></li>
</ul>
</li>
<li><a href="#sec-2-9">2.9 Data Set Example</a></li>
</ul>
</li>
<li><a href="#sec-3">3 Exploring Data</a>
<ul>
<li><a href="#sec-3-1">3.1 Size</a></li>
</ul>
</li>
<li><a href="#sec-4">4 Yelp Academic Dataset</a>
<ul>
<li><a href="#sec-4-1">4.1 Example</a></li>
</ul>
</li>
<li><a href="#sec-5">5 CLI introduction</a>
<ul>
<li><a href="#sec-5-1">5.1 Help</a></li>
</ul>
</li>
<li><a href="#sec-6">6 <code>wget</code></a>
<ul>
<li><a href="#sec-6-1">6.1 Command</a></li>
</ul>
</li>
<li><a href="#sec-7">7 <code>scp</code></a>
<ul>
<li><a href="#sec-7-1">7.1 Command</a></li>
</ul>
</li>
<li><a href="#sec-8">8 <code>gunzip</code> <code>unzip</code></a>
<ul>
<li><a href="#sec-8-1">8.1 Commands</a></li>
</ul>
</li>
<li><a href="#sec-9">9 <code>less</code></a></li>
<li><a href="#sec-10">10 Searching in <code>less</code></a>
<ul>
<li><a href="#sec-10-1">10.1 Command</a></li>
</ul>
</li>
<li><a href="#sec-11">11 <code>grep</code></a></li>
<li><a href="#sec-12">12 <code>wc</code></a></li>
<li><a href="#sec-13">13 Composable</a></li>
</ul>
</div>
</div>
<div id="outline-container-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> Obtaining Data <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-1">
</div>
</div>
<div id="outline-container-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Ways to Collect <span class="tag"><span class="slide">slide</span> <span class="two_col">two_col</span></span></h2>
<div class="outline-text-2" id="text-2">
<ul>
<li>Operational Data
</li>
<li>Data Warehouse
</li>
<li>Unstructured Data
</li>
<li>External API
</li>
<li>Data Sets
</li>
</ul>
<p>
<img src="img/bottlecaps.jpg" alt="img/bottlecaps.jpg" />
</p>
</div>
<div id="outline-container-2-1" class="outline-3">
<h3 id="sec-2-1"><span class="section-number-3">2.1</span> Operational Data <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-1">
<ul>
<li>Most frequent in industry
</li>
<li>Usually stored in databases best suited for transactional use
</li>
<li>Challenge is reorganizing data to suit question
</li>
</ul>
</div>
<div id="outline-container-2-1-1" class="outline-4">
<h4 id="sec-2-1-1"><span class="section-number-4">2.1.1</span> Data from production <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-1-1">
<ul>
<li>Most frequently you'll have data that is being used by the application,
and you'll want to find insights in it
</li>
<li>We'll go into more detail in another class, but online use is
optimized for small queries and small updates
</li>
<li>Frequently just accessing the data in bulk is a software engineering
problem:
<ul>
<li>ensuring long queries don't hold up production usage
</li>
<li>joining across databases via software
</li>
<li>understanding esoteric columns, like "flags"
</li>
</ul>
</li>
<li>Often will want to reorganize data to look like transactional
</li>
<li>img: <a href="http://woodwarddesign.ca/blog/2009/03/06/bottle-caps/">http://woodwarddesign.ca/blog/2009/03/06/bottle-caps/</a>
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-2" class="outline-3">
<h3 id="sec-2-2"><span class="section-number-3">2.2</span> Example <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-2">
<ul>
<li>Find the user names with most "liked" reviews on Yelp
</li>
</ul>
<p>
users
</p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col class="left" /><col class="left" /><col class="left" />
</colgroup>
<tbody>
<tr><td class="left">userID</td><td class="left">name</td><td class="left">flags</td></tr>
<tr><td class="left">25234</td><td class="left">Jim</td><td class="left">0x200</td></tr>
</tbody>
</table>
<p>
reviews
</p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col class="left" /><col class="left" /><col class="left" /><col class="left" /><col class="left" /><col class="left" />
</colgroup>
<tbody>
<tr><td class="left">reviewID</td><td class="left">businessID</td><td class="left">userID</td><td class="left">stars</td><td class="left">text</td><td class="left">flags</td></tr>
<tr><td class="left">282</td><td class="left">52432</td><td class="left">25234</td><td class="left">4</td><td class="left">great place!</td><td class="left">0x1</td></tr>
</tbody>
</table>
<p>
feedback
</p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col class="left" /><col class="left" /><col class="left" /><col class="left" />
</colgroup>
<tbody>
<tr><td class="left">reviewID</td><td class="left">srcUserID</td><td class="left">ufcFlags</td><td class="left">flags</td></tr>
<tr><td class="left">282</td><td class="left">8205</td><td class="left">0x1</td><td class="left">0x0</td></tr>
</tbody>
</table>
</div>
<div id="outline-container-2-2-1" class="outline-4">
<h4 id="sec-2-2-1"><span class="section-number-4">2.2.1</span> Distributed Data <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-2-1">
<ul>
<li>At Yelp we have a variety of database tables, and those tables can be
spread across different databases
</li>
<li>At a minimum we frequently need to <code>JOIN</code> across tables to answer queries
<ul>
<li>eg. matching up user names with reviews from separate tables
</li>
</ul>
</li>
<li>It is possible the review table is only indexed on business ID, and so
finding all reviews by a user is really disk intensive: make sure you're
not slowing down the whole site!
</li>
<li>An additional challenge is when the "feedback" tables are in a separate
database: can no longer issue normal SQL queries
</li>
<li>What are these "flag" columns for?
</li>
<li>Exactly: no one knows. Often must look into code, or compare data to
production representation to guess meaning. In Yelp, <code>0x1</code> often means
"inactive", so we probably don't want to count that feedback
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-3" class="outline-3">
<h3 id="sec-2-3"><span class="section-number-3">2.3</span> Data Warehouse <span class="tag"><span class="slide">slide</span> <span class="two_col">two_col</span></span></h3>
<div class="outline-text-3" id="text-2-3">
<ul>
<li>Data located on same system
</li>
<li>Organized for analytics queries
</li>
<li>Requires extra maintenance and understanding of construction
</li>
</ul>
<p>
<img src="img/Ikea-Warehouse.jpg" alt="img/Ikea-Warehouse.jpg" />
</p>
</div>
<div id="outline-container-2-3-1" class="outline-4">
<h4 id="sec-2-3-1"><span class="section-number-4">2.3.1</span> No free lunch <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-3-1">
<ul>
<li>A strong data warehouse can be a big improvement over operational data
</li>
<li>Hopefully, someone has already cleaned, joined data in a way that makes
sense!
</li>
<li>Optimized for long running queries: less fear of brining down website!
</li>
<li>But you must learn how that process was accomplished in order to understand
potential problems
</li>
<li>How to handle missing data?
</li>
<li>We'll go into more detail about how data warehouse schemas compare to
online ones later in the course
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-4" class="outline-3">
<h3 id="sec-2-4"><span class="section-number-3">2.4</span> Unstructured <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-4">
<ul>
<li>Haphazard collection of data
</li>
<li>Unclear what structure should be
</li>
<li>Examples: Web logs, text, multimedia
</li>
<li>Must extract structure eventually
</li>
</ul>
</div>
<div id="outline-container-2-4-1" class="outline-4">
<h4 id="sec-2-4-1"><span class="section-number-4">2.4.1</span> Yelp JSON logs <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-4-1">
<ul>
<li>When developing a web application, new context or details become
important: how long did certain requests take? What link did a user follow
to a website?
</li>
<li>Relational Databases aren't well suited for these wide varieties of
potential attributes that don't apply to all items
</li>
<li>So the current work around is just to write all useful information down in
a log, and extract what is needed later
</li>
<li>Text, like business reviews, another example: desired structure changes
radically between questions: How many words? Characters? What is the sentiment?
</li>
<li>Pictures can contain attributes like color depth, length, width
</li>
<li>First step of data mining is often imposing structure on data: the data is
not inherently unstructured, it just is unclear what the structure <b>should be</b>
until query time
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-5" class="outline-3">
<h3 id="sec-2-5"><span class="section-number-3">2.5</span> Search Logs Example <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-5">
<pre class="src src-log">193.139.1 jim [10/Oct/2013:13:55:36 -0700] <span style="color: #8b2252;">"GET /search?query=headache HTTP/1.1"</span> 200 9288
282.482.3 shreyas [10/Oct/2013:13:56:36 -0700] <span style="color: #8b2252;">"GET /search?query=bananas HTTP/1.1"</span> 200 2929
345.114.1 steven [10/Oct/2013:13:56:37 -0700] <span style="color: #8b2252;">"GET /search?query=cold HTTP/1.1"</span> 200 8232
10.328.52 anne [10/Oct/2013:13:56:39 -0700] <span style="color: #8b2252;">"GET /search?query=flu+shot HTTP/1.1"</span> 200 2342
10.328.52 lily [10/Oct/2013:13:57:40 -0700] <span style="color: #8b2252;">"GET /search?query=i290 HTTP/1.1"</span> 200 2342
</pre>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<caption></caption>
<colgroup><col class="left" /><col class="left" /><col class="left" />
</colgroup>
<tbody>
<tr><td class="left">userName</td><td class="left">date</td><td class="left">query</td></tr>
<tr><td class="left">jim</td><td class="left">10/Oct/2013:13:55:36 -0700</td><td class="left">headache</td></tr>
<tr><td class="left">shreyas</td><td class="left">10/Oct/2013:13:56:36 -0700</td><td class="left">bananas</td></tr>
<tr><td class="left">steven</td><td class="left">10/Oct/2013:13:56:37 -0700</td><td class="left">cold</td></tr>
<tr><td class="left">anne</td><td class="left">10/Oct/2013:13:56:39 -0700</td><td class="left">flu shot</td></tr>
<tr><td class="left">lily</td><td class="left">10/Oct/2013:13:57:40 -0700</td><td class="left">i290</td></tr>
</tbody>
</table>
</div>
<div id="outline-container-2-5-1" class="outline-4">
<h4 id="sec-2-5-1"><span class="section-number-4">2.5.1</span> Imposing Structure <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-5-1">
<ul>
<li>Extract only the rows we know follow a format
</li>
<li>Format queries from some encoding (eg. URL) to standardized format
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-6" class="outline-3">
<h3 id="sec-2-6"><span class="section-number-3">2.6</span> External APIs <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-6">
<ul>
<li>Better documented than internal data!
</li>
<li>More limited in amount and detail
</li>
<li>Commonly HTTP/REST based
</li>
</ul>
</div>
<div id="outline-container-2-6-1" class="outline-4">
<h4 id="sec-2-6-1"><span class="section-number-4">2.6.1</span> Motivation <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-6-1">
<ul>
<li>Companies are often searching for other ways to leverage their data
</li>
<li>Both for immediate business purposes, and for brand recognition
</li>
<li>Twitter more (in)famous example
</li>
<li>NYTimes another good option
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-7" class="outline-3">
<h3 id="sec-2-7"><span class="section-number-3">2.7</span> NYTimes API Example <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-7">
<ul>
<li><a href="http://developer.nytimes.com/docs/read/article_search_api">Article Search API</a>
</li>
<li><a href="http://api.nytimes.com/svc/search/v1/article?format=json&query=ballot&api-key=6578bab7f8c3808ce4c392edc9a793f0:8:5717915">http://api.nytimes.com/svc/search/v1/article?format=json&query=ballot&api-key=6578bab7f8c3808ce4c392edc9a793f0:8:5717915</a>
</li>
</ul>
</div>
<div id="outline-container-2-7-1" class="outline-4">
<h4 id="sec-2-7-1"><span class="section-number-4">2.7.1</span> Accessing these <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-7-1">
<ul>
<li>More info on how to access these APIs is in the Web Architecture class,
but feel free to ask Shreyas or I about how best to access them
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-8" class="outline-3">
<h3 id="sec-2-8"><span class="section-number-3">2.8</span> Data Sets <span class="tag"><span class="slide">slide</span></span></h3>
<div class="outline-text-3" id="text-2-8">
<ul>
<li>Download large, curated set of data all at once
</li>
<li>Formats vary, but usually documented
</li>
<li>Can be useful to combine with other datasets or APIs
</li>
</ul>
<p>
<img src="img/kaggle-digits.png" alt="img/kaggle-digits.png" />
</p>
</div>
<div id="outline-container-2-8-1" class="outline-4">
<h4 id="sec-2-8-1"><span class="section-number-4">2.8.1</span> Research <span class="tag"><span class="notes">notes</span></span></h4>
<div class="outline-text-4" id="text-2-8-1">
<ul>
<li>Data sets commonly used in research: can compare different techniques on
same data to understand advantages
</li>
<li>Sizes can range to a few MB to GB
</li>
<li>JSON, CSV, XML all potential formats. Cleaning, organization for your
question again becomes an important aspect
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-2-9" class="outline-3">
<h3 id="sec-2-9"><span class="section-number-3">2.9</span> Data Set Example <span class="tag"><span class="slide">slide</span> <span class="two_col">two_col</span></span></h3>
<div class="outline-text-3" id="text-2-9">
<ul>
<li><a href="http://www.grouplens.org/node/73">MovieLens Data Sets</a>
</li>
<li><a href="https://www.kaggle.com/c/digit-recognizer">Kaggle Digit Recognizer</a>
</li>
<li><a href="https://bitly.com/bundles/hmason/1">Hilary Mason's Data Sets</a>
</li>
</ul>
<p>
<img src="img/video.jpg" alt="img/video.jpg" />
</p>
</div>
</div>
</div>
<div id="outline-container-3" class="outline-2">
<h2 id="sec-3"><span class="section-number-2">3</span> Exploring Data <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-3">
<ul>
<li>Data sets are frequently too large to fit in standard tools like Excel or
Word
</li>
<li>Simplest to explore on the command line
</li>
<li>Homework will be exploring a data set of your choice
</li>
</ul>
</div>
<div id="outline-container-3-1" class="outline-3">
<h3 id="sec-3-1"><span class="section-number-3">3.1</span> Size <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-3-1">
<ul>
<li>Some formats will not be easily parsed into Excel: eg. JSON, XML
</li>
<li>Word will be slow, or unworkable for GB size data
</li>
<li>CLI provides many composable tools for text manipulation
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-4" class="outline-2">
<h2 id="sec-4"><span class="section-number-2">4</span> Yelp Academic Dataset <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-4">
<ul>
<li><a href="http://yelp.com/academic_dataset">Yelp Data Set</a> covers reviews, users,
businesses
</li>
<li>To download, you'll need to sign up: process takes ~24 hours for approval
</li>
<li>Use .edu email
</li>
</ul>
</div>
<div id="outline-container-4-1" class="outline-3">
<h3 id="sec-4-1"><span class="section-number-3">4.1</span> Example <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-4-1">
<ul>
<li>We'll use this as an example, you can use any data set of your choice
</li>
<li>Just for HW, don't need to use for project
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-5" class="outline-2">
<h2 id="sec-5"><span class="section-number-2">5</span> CLI introduction <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-5">
<ul>
<li>Standard commands available in <a href="http://cli.learncodethehardway.com">Learn CLI the hard way</a>
</li>
<li>All example will be run on <code>ischool.berkeley.edu</code>
</li>
<li>Sheyas and I available for more help
</li>
</ul>
</div>
<div id="outline-container-5-1" class="outline-3">
<h3 id="sec-5-1"><span class="section-number-3">5.1</span> Help <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-5-1">
<ul>
<li>If you're new, don't be intimidated.
</li>
<li>Security policies ensure you can't break anything besides your own files
</li>
<li>Keep backups of important stuff anyway
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-6" class="outline-2">
<h2 id="sec-6"><span class="section-number-2">6</span> <code>wget</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-6">
<ul>
<li>Used for downloading files
</li>
<li>Downloading with the browser is fine, but sometimes nice to use faster
connection, or download it directly to machine you're working on
</li>
</ul>
<pre class="src src-bash">$ wget 'http://www.grouplens.org/system/files/ml-100k.zip'
</pre>
</div>
<div id="outline-container-6-1" class="outline-3">
<h3 id="sec-6-1"><span class="section-number-3">6.1</span> Command <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-6-1">
<ul>
<li>Just <code>wget URL</code>
</li>
<li>I like to use quotes in case there are special characters in the URL, eg
<code>?</code>
</li>
<li>Will download to current directory, same name as remote file
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-7" class="outline-2">
<h2 id="sec-7"><span class="section-number-2">7</span> <code>scp</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-7">
<ul>
<li>Copy a file to or from a remote machine
</li>
<li>Uses same connection as SSH, but copies data instead
</li>
<li>Example: Copy data you've downloaded in your browser
</li>
</ul>
<pre class="src src-bash">$ scp ~/Downloads/ml-100k.zip [email protected]:
# or
$ scp ~/Downloads/ml-100k.zip [email protected]:i290/movielens-100k.zip
</pre>
</div>
<div id="outline-container-7-1" class="outline-3">
<h3 id="sec-7-1"><span class="section-number-3">7.1</span> Command <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-7-1">
<ul>
<li>Trailing <code>:</code> is important: signifies remote machine
</li>
<li>If you don't specify path or filename, will copy the file with the same
name into your home directory
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-8" class="outline-2">
<h2 id="sec-8"><span class="section-number-2">8</span> <code>gunzip</code> <code>unzip</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-8">
<ul>
<li>Uncompress data sets for simpler, faster manipulation
</li>
</ul>
<pre class="src src-bash">$ unzip ml-100k.zip
# or
$ gunzip yelp_academic_dataset.json.gz
</pre>
</div>
<div id="outline-container-8-1" class="outline-3">
<h3 id="sec-8-1"><span class="section-number-3">8.1</span> Commands <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-8-1">
<dl>
<dt>unzip</dt><dd>expand potentially many file, leave original alone
</dd>
<dt>gunzip</dt><dd>expand original file, leaving only the uncompressed version
</dd>
</dl>
</div>
</div>
</div>
<div id="outline-container-9" class="outline-2">
<h2 id="sec-9"><span class="section-number-2">9</span> <code>less</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-9">
<ul>
<li>View a file
</li>
<li>History: original command was called <code>more</code> to see a file a page at a time
</li>
<li>"Less is more"
</li>
</ul>
<pre class="src src-bash">less yelp_academic_dataset.json
</pre>
</div>
</div>
<div id="outline-container-10" class="outline-2">
<h2 id="sec-10"><span class="section-number-2">10</span> Searching in <code>less</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-10">
<ul>
<li><code>/</code> (forward slash) lets you input search text
</li>
<li><code>q</code> will quit
</li>
</ul>
<pre class="src src-less">/type<span style="color: #8b2252;">": "</span>user<span style="color: #8b2252;">"</span>
<span style="color: #8b2252;">/type"</span>: <span style="color: #8b2252;">"review"</span>
</pre>
</div>
<div id="outline-container-10-1" class="outline-3">
<h3 id="sec-10-1"><span class="section-number-3">10.1</span> Command <span class="tag"><span class="notes">notes</span></span></h3>
<div class="outline-text-3" id="text-10-1">
<ul>
<li>Useful for finding specific instances to investigate
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-11" class="outline-2">
<h2 id="sec-11"><span class="section-number-2">11</span> <code>grep</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-11">
<ul>
<li>Find and print lines matching a "regular expression"
</li>
<li><a href="http://www.regular-expressions.info/quickstart.html">Regular expressions</a> are "find" on steroids, but you can use simple strings
</li>
</ul>
<pre class="src src-bash">$ grep 'type<span style="color: #8b2252;">": "</span>review<span style="color: #8b2252;">"' yelp_academic_dataset.json</span>
</pre>
</div>
</div>
<div id="outline-container-12" class="outline-2">
<h2 id="sec-12"><span class="section-number-2">12</span> <code>wc</code> <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-12">
<ul>
<li>"wordcount" counts characters, words, lines
</li>
<li>Most useful in data sets for lines: <code>-l</code>
</li>
</ul>
<pre class="src src-bash">$ wc -l yelp_academic_dataset.json
474434 yelp_academic_dataset.json
</pre>
</div>
</div>
<div id="outline-container-13" class="outline-2">
<h2 id="sec-13"><span class="section-number-2">13</span> Composable <span class="tag"><span class="slide">slide</span></span></h2>
<div class="outline-text-2" id="text-13">
<ul>
<li>Genius of Unix: do one thing well, compose commands to get what you want
</li>
<li><code>|</code> pipe characters "sends" output from one program to the input of another
</li>
<li>How many reviews in the data set?
</li>
</ul>
<pre class="src src-bash">$ grep 'type<span style="color: #8b2252;">": "</span>review<span style="color: #8b2252;">"' yelp_academic_dataset.json | wc -l</span>
<span style="color: #8b2252;">330071</span>
<span style="color: #8b2252;">$ egrep -o 'business_id"</span>: <span style="color: #8b2252;">"\w+"</span>' yelp_academic_dataset.json | sort -u | wc -l
9592
</pre>
<script type="text/javascript" src="production/org-html-slideshow.js"></script>
</div>
</div>
</div>
<div id="postamble">
<p class="date">Date: 2013-02-01 13:45:14 PST</p>
<p class="author">Author: Jim Blomo</p>
<p class="creator">Org version 7.8.02 with Emacs version 23</p>
<a href="http://validator.w3.org/check?uri=referer">Validate XHTML 1.0</a>
</div>
</body>
</html>