-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathTutorial_180723_Machine_learning.html
More file actions
1013 lines (512 loc) · 44.8 KB
/
Tutorial_180723_Machine_learning.html
File metadata and controls
1013 lines (512 loc) · 44.8 KB
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
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>기계학습의 기초(지도학습/비지도학습/머신러닝) · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="Tutorial_180723_word_vectorsization.html" />
<link rel="prev" href="Tutorial_180720_ProbabilityDistribution.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="Tutorial_180628_Git_and_Github.html">
<a href="Tutorial_180628_Git_and_Github.html">
Git과 Github, 기본 개념과 설명
</a>
</li>
<li class="chapter " data-level="1.3" data-path="Tutorial_180629_Git_with_constitution.html">
<a href="Tutorial_180629_Git_with_constitution.html">
헌법개정안으로 깃베쉬, 소스트리, 브랜치 이해하기
</a>
</li>
<li class="chapter " data-level="1.4" data-path="Tutorial_180629_Github_practice_Statistics1.html">
<a href="Tutorial_180629_Github_practice_Statistics1.html">
확률통계 기초와 깃허브 실습
</a>
</li>
<li class="chapter " data-level="1.5" data-path="Tutorial_180629_Statistics.html">
<a href="Tutorial_180629_Statistics.html">
통계 기본 개념과 설명
</a>
</li>
<li class="chapter " data-level="1.6" data-path="Tutorial_180702_Programming_Intro.html">
<a href="Tutorial_180702_Programming_Intro.html">
스크래치 실습을 통한 프로그래밍 맛보기
</a>
</li>
<li class="chapter " data-level="1.7" data-path="Tutorial_180702_tidydata.html">
<a href="Tutorial_180702_tidydata.html">
데이터다루기(tidydata)와 프로그래밍기초
</a>
</li>
<li class="chapter " data-level="1.8" data-path="Tutorial_180703_Python_introduction.html">
<a href="Tutorial_180703_Python_introduction.html">
파이썬 기초
</a>
</li>
<li class="chapter " data-level="1.9" data-path="Tutorial_180705_PythonReview_Lamda.html">
<a href="Tutorial_180705_PythonReview_Lamda.html">
범죄데이터로 파이썬 실습 (Lamda)
</a>
</li>
<li class="chapter " data-level="1.10" data-path="Tutorial_180705_Resume_01.html">
<a href="Tutorial_180705_Resume_01.html">
특강-자기소개서 워크숍(1)
</a>
</li>
<li class="chapter " data-level="1.11" data-path="Tutorial_180706_Civic_hacking_seminar.html">
<a href="Tutorial_180706_Civic_hacking_seminar.html">
특강-시빅해킹
</a>
</li>
<li class="chapter " data-level="1.12" data-path="Tutorial_180709_StaticBlogging_JekyllandRuby.html">
<a href="Tutorial_180709_StaticBlogging_JekyllandRuby.html">
지킬과 루비로 정적 블로그 만들기
</a>
</li>
<li class="chapter " data-level="1.13" data-path="Tutorial_180710_Lecture_Cooperation.html">
<a href="Tutorial_180710_Lecture_Cooperation.html">
특강-협업
</a>
</li>
<li class="chapter " data-level="1.14" data-path="Tutorial_180710_Lecture_Speciality.html">
<a href="Tutorial_180710_Lecture_Speciality.html">
특강-전문성
</a>
</li>
<li class="chapter " data-level="1.15" data-path="Tutorial_180712_DataVisualization101.html">
<a href="Tutorial_180712_DataVisualization101.html">
데이터 시각화 이해
</a>
</li>
<li class="chapter " data-level="1.16" data-path="Tutorial_180712_AttraciveResume2.html">
<a href="Tutorial_180712_AttraciveResume2.html">
특강-자기소개서 워크숍(2)
</a>
</li>
<li class="chapter " data-level="1.17" data-path="Tutorial_180713_Pandas101.html">
<a href="Tutorial_180713_Pandas101.html">
자료의 요약 과제를 통한 판다스 실습
</a>
</li>
<li class="chapter " data-level="1.18" data-path="Tutorial_180713_ExperimentDesignLecture.html">
<a href="Tutorial_180713_ExperimentDesignLecture.html">
특강-실험계획에 관해 알아보기
</a>
</li>
<li class="chapter " data-level="1.19" data-path="Tutorial_180716_Crawling_Shuffle.html">
<a href="Tutorial_180716_Crawling_Shuffle.html">
저작권과 직업윤리를 인지하고 크롤링 셔플 실습
</a>
</li>
<li class="chapter " data-level="1.20" data-path="Tutorial_180716_Markup_Html5lib.html">
<a href="Tutorial_180716_Markup_Html5lib.html">
Markup Html5lib, 파이썬으로 크롤링하기
</a>
</li>
<li class="chapter " data-level="1.21" data-path="Tutorial_180717_10minPandas.html">
<a href="Tutorial_180717_10minPandas.html">
Pandas 10분 완성
</a>
</li>
<li class="chapter " data-level="1.22" data-path="Tutorial_180717_PandasPetition.html">
<a href="Tutorial_180717_PandasPetition.html">
국민청원 첫시작 판다스로 국민청원하기
</a>
</li>
<li class="chapter " data-level="1.23" data-path="Tutorial_180719_BeautifulSoup.html">
<a href="Tutorial_180719_BeautifulSoup.html">
Beautiful Soup을 사용하여 크롤링
</a>
</li>
<li class="chapter " data-level="1.24" data-path="Tutorial_180719_plotnine.md">
<span>
국민청원 데이터 시각화와 자연어 처리-plontnine 실습하기
</a>
</li>
<li class="chapter " data-level="1.25" data-path="Tutorial_180720_coupang.html">
<a href="Tutorial_180720_coupang.html">
특강 - 비전공자가 데이터 분석가로 취업하기
</a>
</li>
<li class="chapter " data-level="1.26" data-path="Tutorial_180720_ProbabilityDistribution.html">
<a href="Tutorial_180720_ProbabilityDistribution.html">
통계학-자료의 요약, 확률분포(ProbabilityDistribution)
</a>
</li>
<li class="chapter active" data-level="1.27" data-path="Tutorial_180723_Machine_learning.html">
<a href="Tutorial_180723_Machine_learning.html">
기계학습의 기초(지도학습/비지도학습/머신러닝)
</a>
</li>
<li class="chapter " data-level="1.28" data-path="Tutorial_180723_word_vectorsization.html">
<a href="Tutorial_180723_word_vectorsization.html">
텍스트 데이터 시각화 Word_vectorsization
</a>
</li>
<li class="chapter " data-level="1.29" data-path="Tutorial_180726_naver.html">
<a href="Tutorial_180726_naver.html">
특강 - AI R&D Director
</a>
</li>
<li class="chapter " data-level="1.30" data-path="Tutorial_180726_library.md">
<span>
전국도서관표준데이터 분석
</a>
</li>
<li class="chapter " data-level="1.31" data-path="Tutorial_180730_Categorizing_v2.html">
<a href="Tutorial_180730_Categorizing_v2.html">
국민청원 카테고리 분류하기
</a>
</li>
<li class="chapter " data-level="1.32" data-path="Tutorial_180730_Kaggle_NLP_v2.html">
<a href="Tutorial_180730_Kaggle_NLP_v2.html">
Kaggle NLP로 예측율 높이기
</a>
</li>
<li class="chapter " data-level="1.33" data-path="Tutorial_180730_Statistics.html">
<a href="Tutorial_180730_Statistics.html">
Hypothesis test
</a>
</li>
<li class="chapter " data-level="1.34" data-path="Tutorial_180731_MTPlanning.html">
<a href="Tutorial_180731_MTPlanning.html">
데잇걸즈 MT 계획으로 애자일 프로세스 실습해보기
</a>
</li>
<li class="chapter " data-level="1.35" data-path="Tutorial_180802_ZigZag.html">
<a href="Tutorial_180802_ZigZag.html">
특강 - 쇼핑몰 데이터 분석 이야기
</a>
</li>
<li class="chapter " data-level="1.36" data-path="Tutorial_180803_GettingJobGithub.html">
<a href="Tutorial_180803_GettingJobGithub.html">
깃허브로 취업하기
</a>
</li>
<li class="chapter " data-level="1.37" data-path="Tutorial_180803_Statistics4.html">
<a href="Tutorial_180803_Statistics4.html">
회귀분석(Linear regression)
</a>
</li>
<li class="chapter " data-level="1.38" data-path="Tutorial_180806_Folium_practice.md">
<span>
공공데이터 상권정보 분석해 보기
</a>
</li>
<li class="chapter " data-level="1.39" data-path="Tutorial_180806_Geolocatin_API_practice.md">
<span>
서울창업허브(공덕역) 맛집지도
</a>
</li>
<li class="chapter " data-level="1.40" data-path="Tutorial_180806_XGBoost.md">
<span>
XGBoost 분산형 그래디언트 부스팅 알고리즘
</a>
</li>
<li class="chapter " data-level="1.41" data-path="Tutorial_180807_Git_review.html">
<a href="Tutorial_180807_Git_review.html">
깃과 깃헙 복습, 다른 사람의 레파지토리에 기여하기
</a>
</li>
<li class="chapter " data-level="1.42" data-path="Tutorial_180810_Apt_analysis_Statistics5.html">
<a href="Tutorial_180810_Apt_analysis_Statistics5.html">
아파트 분양가 분석 및 회귀분석2
</a>
</li>
<li class="chapter " data-level="1.43" data-path="Tutorial_180813_kaggle_Titanic.html">
<a href="Tutorial_180813_kaggle_Titanic.html">
스프레드시트로 캐글 타이타닉 참가하기
</a>
</li>
<li class="chapter " data-level="1.44" data-path="Tutorial_180814_Python_Class.html">
<a href="Tutorial_180814_Python_Class.html">
객체지향 프로그래밍
</a>
</li>
<li class="chapter " data-level="1.45" data-path="Tutorial_180814_Test_Driven_Development.html">
<a href="Tutorial_180814_Test_Driven_Development.html">
테스트 주도 개발
</a>
</li>
<li class="chapter " data-level="1.46" data-path="Tutorial_180817_Colors_in_Data_Visualization.md">
<span>
데이터 시각화와 색의 활용
</a>
</li>
<li class="chapter " data-level="1.47" data-path="Tutorial_180817_Statistics5.html">
<a href="Tutorial_180817_Statistics5.html">
통계-회귀분석3
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >기계학습의 기초(지도학습/비지도학습/머신러닝)</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="tutorial20180723morning">Tutorial_20180723_Morning</h1>
<h3 id="분석-pandas-🔽">분석 Pandas 🔽</h3>
<ul>
<li>엑셀보다 불러올 수 있는 파일의 사이즈가 크고, 더 다양하게 분석할 수 있는 tool</li>
</ul>
<h3 id="수치계산-numpy-🔽">수치계산 Numpy 🔽</h3>
<ul>
<li>데이터 구조외에도 수치계산을 위해 효율적으로 구현 된 기능을 제공</li>
</ul>
<h3 id="시각화-🔽">시각화 🔽</h3>
<pre><code>Matplolib
- plotline
- seaborn
</code></pre><hr>
<h3 id="관련-개념-정리"><관련 개념 정리></h3>
<h3 id="1-scikit-learn-싸이킷-런">(1) scikit learn (싸이킷 런)</h3>
<ul>
<li>파이썬에 있는 대표적인 Machine Learning Library.</li>
<li>data mining, data analysis를 위한 간결하고 효과적인 툴.</li>
<li>Numpy, scipy, matplotlib으로 쓰여졌다.</li>
<li>오픈 소스이자 상업적으로 사용 가능하다. (BSD license)</li>
</ul>
<h3 id="2-classification분류">(2) classification(분류)</h3>
<ul>
<li>속성에 따라 분류해준다.</li>
</ul>
<h3 id="3-regression회귀">(3) regression(회귀)</h3>
<ul>
<li>수요 분석할 때 많이 사용한다.</li>
</ul>
<h3 id="4-clustering군집화">(4) clustering(군집화)</h3>
<ul>
<li>비슷한 아이들끼리 묶어준다.</li>
</ul>
<h3 id="5-dimensionality-reduction차원축소">(5) dimensionality reduction(차원축소)</h3>
<ul>
<li>압축해서 본다.</li>
<li>wordcloud로 단어의 유사도를 체크하고, 유사도에 기초하여 군집화한다.</li>
<li>3차원의 경우 2차원으로 줄인다.</li>
</ul>
<hr>
<h3 id="기계학습-기초"><기계학습 기초></h3>
<blockquote>
<p><strong>Andread Muller's Machine Learning with Scikit-Learn</strong></p>
<p>Classification, Regression, Clustering, Semi-Supervised Learning, Feature Selection, Feature > Extraction, Manifold Learning, Dimensionality Reduction, Kernel Approximation,
Hyperparameter Optimization, Evaluation Metrics, Out-of-core learning, ...</p>
</blockquote>
<h3 id="supervised-machine-learning-지도학습-🔎">Supervised Machine Learning (지도학습) 🔎</h3>
<ul>
<li>Traning data를 넣어서 어떤 모델을 만들고, Test Data에 있는 Training Labels를 예측하는 것이 Supervised Machine Learning이다.
Coursera에서 강의를 들어볼 수 있다. 보스턴의 집 값을 예측하는 머신 러닝 알고리즘. 통계 시간에 측정 기법들을 배우게 될 것이다.</li>
<li>Traning (훈련)과 Generalization (일반화). 특정 데이터에만 맞는 데이터가 아니라, 어떤 데이터도 예측 가능하도록 결측치를 제거하거나,
하는 등의 과정을 Traning. 이후 테스트하고 평가하는 과정을 Generalization이라고 한다.</li>
<li>분류와 회귀의 경우 거의 지도학습에 해당한다. 비지도 학습으로도 수행할 수 있으나, labels를 가지고 분류하는 경우 supervised. 회귀의 경우
집 값 예측이나 배송 물건 예측, 배송 시간 예측 등은 기존의 데이터를 기계에게 알려주어 그것을 바탕으로 예측하도록 한다. </li>
</ul>
<blockquote>
<h4 id="clffitxtrain-ytrain">clf.fit(X_train, y_train)</h4>
</blockquote>
<pre><code>X는 대문자를 사용하고, y는 소문자를 사용하는 이유는
X = 행렬 y는 벡터이기 때문이다.
</code></pre><pre><code>X_train은 train데이터의 행렬을 뜻한다.
y_train은 train데이터의 벡터를 뜻한다.
</code></pre><blockquote>
<h4 id="clfscorextest-ytest">clf.score(X_test, y_test)</h4>
</blockquote>
<pre><code>train을 통해 알고싶은 것이나, 확인한 결과가 맞는지, test를 통해 알아본다.
(예측 결과가 얼마나 정확한지 평가하는 단계)
</code></pre><h4 id="단-네-줄로-기계학습을-실행할-수-있다--🔻">단 네 줄로 기계학습을 실행할 수 있다! 🔻</h4>
<pre><code class="lang-python">clf = RandomForestClassifier()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
clf.score(X_test, y_texst)
</code></pre>
<h3 id="unsupervised-machine-learning-비지도학습-☂️">Unsupervised Machine Learning (비지도학습) ☂️</h3>
<h4 id="❔-지도학습과-차이점-❔">❔ 지도학습과 차이점 ❔</h4>
<p>Training Data를 넣고, 바로 Test 한다. Unsupervised 같은 경우는, labels가 없다.</p>
<pre><code class="lang-python"> pca = PCA()
pca.fit(X_train)
X_new = pca.transform(X_test)
</code></pre>
<blockquote>
<p>기준O = 지도학습 </p>
<p>기준X = 비지도학습</p>
<p>분류할 때 clustering을 하면 Unsupervised Machine Learning 이다.</p>
</blockquote>
<p><strong>Labels, Features ?</strong></p>
<ul>
<li>e.g.) Labels에 고양이와 개. 몸무게, 키 등의 기준(속성)들이 Features. 지도 학습에서는 Labels를 주고 이것을 바탕으로 Classify 한다. 비지도 학습에서는 Labels가 없음. 분류가 아니라 회귀의 경우, Labels에 집 값이 들어간다.</li>
</ul>
<h4 id="몸무게와-키를-features라고-하고-분류할-때-labels이-개고양이-중-무엇인지-찾는-것">몸무게와 키를 features라고 하고 분류할 때 labels이 개/고양이 중 무엇인지 찾는 것</h4>
<pre><code>몸무게 키 label
30kg 20cm 개
20kg 15cm 고양이
</code></pre><p>(by_정지은님 설명 :girl:)</p>
<h4 id="tfidvertorizer">TfidVertorizer</h4>
<ul>
<li>검색 엔진에서 자주 사용하는 알고리즘. 단어에 가중치를 준다. Bag of Word의 단점을 보완하는 도구로 사용되고 있다.</li>
</ul>
<hr>
<h3 id="overfitting과대적합과-underfitting과소적합">Overfitting(과대적합)과 Underfitting(과소적합)</h3>
<blockquote>
<p>Training과 Heneralization의 격차가 적은 구간이 정확도의 측면에서 최적화된 지점 (Sweet spot)이다. Underfitting의 경우 모수가 적은 경우. 데이터를 적게 부여하고 학습을 시킨 경우, 제대로 학습되어 있지 않다고 하여 underfitting 이라고 한다. </p>
<p>반대로 너무 학습이 잘 되어 Outlier나 결측치에 대해서도 학습을 하는 경우를 overfitting이라고 한다.</p>
<p>e.g.) 어떤 학습 결과가 육아 관련 데이터를 잘 예측하지만 반려동물 데이터에 대해서는 > 잘 예측하지 못한다면, 이 학습 결과는 육아 관련 데이터에 overfitting 되었다고
한다.</p>
</blockquote>
<h4 id="1-overfitting-chartwithupwardstrend">(1) Overfitting :chart_with_upwards_trend:</h4>
<pre><code>Model이 Train Data에 너무 잘 맞지만 일반성이 떨어진다는 의미
-> 너무 훈련데이터에 맞춰져 있어서 Test Data에서는 높은 성능을 보여줄 확률이 낮다.
-> 모델의 복잡도가 필요이상으로 높기 때문이다.
</code></pre><h4 id="해결방법">해결방법</h4>
<blockquote>
<pre><code>- 훈련 데이터를 더 많이 모은다.
- 정규화
- 오류 수정과 이상치 제거
</code></pre></blockquote>
<h4 id="2-underfitting-chartwithdownwardstrend">(2) Underfitting :chart_with_downwards_trend:</h4>
<pre><code>Mddel이 너무 단순해서 Data의 내재된 구조를 학습하지 못할 때 발생.
-> 모수가 너무 작아서 발생
</code></pre><h5 id="해결방법">해결방법</h5>
<blockquote>
<pre><code>- 파라미터가 더 많은 복잡한 모델을 선택
- 모델의 제약을 줄이기(규제 하이퍼파라미터 값 줄이기)
</code></pre></blockquote>
<h4 id="decision-trees">Decision Trees</h4>
<ul>
<li>True / False 로 구분되는 Data. 어떤 기준을 바탕으로 점점 True/False로 Depth를 더해가며 그래프를 그린다.</li>
<li>이것이 정확도가 떨어져서, 이 부분을 보완한 것이 RandomForests이다. 이러한 Decision Trees 를 Random하게 매우 많이 그린다. depth를 너무 깊게 내려가도 overfitting이 되어 정확도가 떨어지고, depth가 너무 낮아도 underfitting 되어 정확도가 떨어진다. 데이터에 맞게 적절한 지점을 찾는 것이 중요하다.</li>
</ul>
<hr>
<h3 id="자연어-처리-실습"><자연어 처리 실습></h3>
<p><strong>(1) 정규표현식을 사용해서 지난 시간 soynlp 실습 결과 wordcloud 개선하기</strong></p>
<ul>
<li><p>불용어 제거하기</p>
<ul>
<li>preprocessing (전처리)</li>
</ul>
</li>
</ul>
<pre><code class="lang-python"> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">preprocessing</span><span class="hljs-params">(text)</span>:</span>
text = re.sub(<span class="hljs-string">'- '</span>, <span class="hljs-string">' '</span>, text)
text = re.sub(<span class="hljs-string">'같습니다'</span>, <span class="hljs-string">' '</span>, text)
text = re.sub(<span class="hljs-string">'좋았습니다'</span>, <span class="hljs-string">'좋았어요'</span>, text)
text = re.sub(<span class="hljs-string">'지영님의'</span>, <span class="hljs-string">'지영님'</span>, text)
<span class="hljs-keyword">return</span> text
</code></pre>
<ul>
<li>remove_stopwords (불용어 제거)</li>
</ul>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">remove_stopwords</span><span class="hljs-params">(text)</span>:</span>
stops = [<span class="hljs-string">'수'</span>, <span class="hljs-string">'있는'</span>, <span class="hljs-string">'있습니다'</span>, <span class="hljs-string">'그'</span>, <span class="hljs-string">'년도'</span>, <span class="hljs-string">'에'</span>, <span class="hljs-string">'합니다'</span>, <span class="hljs-string">'하는'</span>, <span class="hljs-string">'및'</span>, <span class="hljs-string">'제'</span>, <span class="hljs-string">'할'</span>, <span class="hljs-string">'하고'</span>, <span class="hljs-string">'더'</span>, <span class="hljs-string">'대한'</span>, <span class="hljs-string">'한'</span>, <span class="hljs-string">'그리고'</span>, <span class="hljs-string">'월'</span>, <span class="hljs-string">'저는'</span>, <span class="hljs-string">'없는'</span>, <span class="hljs-string">'것입니다'</span>, <span class="hljs-string">'등'</span>, <span class="hljs-string">'일'</span>, <span class="hljs-string">'많은'</span>, <span class="hljs-string">'이런'</span>, <span class="hljs-string">'것은'</span>, <span class="hljs-string">'왜'</span>, <span class="hljs-string">'같은'</span>, <span class="hljs-string">'없습니다'</span>, <span class="hljs-string">'위해'</span>, <span class="hljs-string">'한다'</span>]
<span class="hljs-comment"># Stopwords 불용어 제거</span>
meaningful_words = [word <span class="hljs-keyword">for</span> word <span class="hljs-keyword">in</span> text <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> word <span class="hljs-keyword">in</span> stops]
<span class="hljs-keyword">return</span> <span class="hljs-string">' '</span>.join(meaningful_words)
%time tokens_remove_stopwords = 토큰으로만든단어들.apply(remove_stopwords)
</code></pre>
<p><strong>(2) 정규표현식 불러오기</strong></p>
<ul>
<li><code>import re</code></li>
<li>정규표현식은 모든 언어에 다 있다.</li>
<li>데이터 전처리 preprocessing에 필수 요소이다.</li>
</ul>
<blockquote>
<p>text = re.sub('\\n', ' ', text)에서 공백을 설정해주는 이유는 단어끼리 붙는 것을 방지하기 위해서 이다.</p>
<p>%time을 입력하면 해당 코드를 실행할 때 걸리는 시간을 출력해준다.
%%time = 해당줄이 여러개일 때 사용한다.</p>
</blockquote>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">preprocessing</span><span class="hljs-params">(text)</span>:</span>
<span class="hljs-comment"># 개행문자 제거</span>
text = re.sub(<span class="hljs-string">'\\\\n'</span>, <span class="hljs-string">' '</span>, text)
<span class="hljs-comment"># 특수문자 제거</span>
<span class="hljs-comment"># 특수문자나 이모티콘 등은 때로는 의미를 갖기도 하지만 여기에서는 제거했습니다.</span>
<span class="hljs-comment"># text = re.sub('[?.,;:|\)*~`’!^\-_+<>@\#$%&-=#}※]', '', text)</span>
<span class="hljs-comment"># text = re.sub('[0-9]', '', text)</span>
<span class="hljs-comment"># 한글, 영문, 숫자만 남기고 모두 제거하도록 합니다.</span>
<span class="hljs-comment"># text = re.sub('[^가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z0-9]', ' ', text)</span>
<span class="hljs-comment"># 한글, 영문만 남기고 모두 제거하도록 합니다.</span>
text = re.sub(<span class="hljs-string">'[^가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z]'</span>, <span class="hljs-string">' '</span>, text)
<span class="hljs-keyword">return</span> text
</code></pre>
<h4 id="만약-워드클라우드-안에-원하는-단어수만-출력하고-싶다면-❔">만약 워드클라우드 안에 원하는 단어수만 출력하고 싶다면 ❔</h4>
<blockquote>
<p> row데이터에서 '상위 몇 %' 이런식으로 전처리를 해줘야 된다.</p>
</blockquote>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="Tutorial_180720_ProbabilityDistribution.html" class="navigation navigation-prev " aria-label="Previous page: 통계학-자료의 요약, 확률분포(ProbabilityDistribution)">
<i class="fa fa-angle-left"></i>
</a>
<a href="Tutorial_180723_word_vectorsization.html" class="navigation navigation-next " aria-label="Next page: 텍스트 데이터 시각화 Word_vectorsization">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"기계학습의 기초(지도학습/비지도학습/머신러닝)","level":"1.27","depth":1,"next":{"title":"텍스트 데이터 시각화 Word_vectorsization","level":"1.28","depth":1,"path":"Tutorial_180723_word_vectorsization.md","ref":"Tutorial_180723_word_vectorsization.md","articles":[]},"previous":{"title":"통계학-자료의 요약, 확률분포(ProbabilityDistribution)","level":"1.26","depth":1,"path":"Tutorial_180720_ProbabilityDistribution.md","ref":"Tutorial_180720_ProbabilityDistribution.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{"BASE_URL":"https://dataitgirls2.github.io"},"plugins":["ga","-sharing"],"pluginsConfig":{"ga":{"configuration":"auto","token":"UA-43356518-7"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"Tutorial_180723_Machine_learning.md","mtime":"2018-09-09T04:17:19.732Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-09-09T04:41:47.437Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-ga/plugin.js"></script>
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="gitbook/gitbook-plugin-search/search.js"></script>
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>