鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇
Posted Stata杩炰韩浼?/a>
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇相关的知识,希望对你有一定的参考价值。
鈥?/p>
鐢板師 (鍖椾含浜ら€氬ぇ瀛?
godfreytian@163.com
鈥?/p>
馃崕 杩炰韩浼氫富椤碉細lianxh.cn
鎵爜鏌ョ湅鏈€鏂版帹鏂囧拰鍒嗕韩
NEW锛?/span>杩炰韩浼毬锋帹鏂囦笓杈戯細
| | |
| | | |
| | | |
| | |
鈥?/p>
鐩綍
1. SVM 浠嬬粛
1.1 SVM 绠€浠?/p>
1.2 SVM 鍩烘湰姒傚康
1.3 SVM 绠楁硶鐗瑰緛
2. SVM 姹傝В杩囩▼
3. 鏍稿嚱鏁?/p>
3.1 浣跨敤鏍稿嚱鏁扮殑鍘熷洜
3.2 甯哥敤鏍稿嚱鏁?/p>
3.3 鏍稿嚱鏁扮殑閫夋嫨
4. SVM 鐨?Python 瀹炵幇
5. SVM 鐨?Stata 瀹炵幇
6. 鍙傝€冩枃鐚?/p>
鈥?/p>
锛?020骞?鏈?鏃?/span>
涓昏鍢夊锛氱帇瀛樺悓鏁欐巿 (涓ぎ璐㈢粡澶у)
鈥?/p>
2020骞?鏈?3鏃ワ紝19:00-21:00, 88鍏?br class="mq-58">涓昏鍢夊锛氬徃缁ф槬 锛?/p>
鈥?/p>
1. SVM 浠嬬粛
1.1 SVM 绠€浠?/span>
鏀寔鍚戦噺鏈猴紙support vector machines, SVM锛夌殑鍩烘湰妯″瀷鏄畾涔夊湪鐗瑰緛绌洪棿涓婄殑闂撮殧鏈€澶х殑绾挎€у垎绫诲櫒锛岄棿闅旀渶澶т娇瀹冩湁鍒簬鎰熺煡鏈猴紱SVM 杩樺寘鎷牳鎶€宸э紝杩欎娇瀹冩垚涓哄疄璐ㄤ笂鐨勯潪绾挎€у垎绫诲櫒銆係VM 鐨勫涔犵瓥鐣ュ氨鏄棿闅旀渶澶у寲锛屽彲褰㈠紡鍖栦负涓€涓眰瑙e嚫浜屾瑙勫垝鐨勯棶棰橈紝涔熺瓑浠蜂簬姝e垯鍖栫殑鍚堥〉鎹熷け鍑芥暟鐨勬渶灏忓寲闂銆係VM 鐨勫涔犵畻娉曞氨鏄眰瑙e嚫浜屾瑙勫垝鐨勬渶浼樺寲绠楁硶銆?/p>
1.2 SVM 鍩烘湰姒傚康
浜嗚В SVM 绠楁硶涔嬪墠锛岄鍏堥渶瑕佷簡瑙d竴涓嬬嚎鎬у垎绫诲櫒杩欎釜姒傚康銆傛瘮濡傜粰瀹氫竴绯诲垪鐨勬暟鎹牱鏈紝姣忎釜鏍锋湰閮芥湁瀵瑰簲鐨勪竴涓爣绛俱€備负浜嗕娇寰楁弿杩版洿鍔犵洿瑙傦紝鎴戜滑浠ヤ簩缁村钩闈负渚嬶紝灏嗙壒寰佸悜閲忔槧灏勪负绌洪棿涓殑涓€浜涚偣锛屽氨鏄涓嬪浘鐨勫疄蹇冪偣鍜岀┖蹇冪偣锛屽畠浠睘浜庝笉鍚岀殑涓ょ被銆?/p>
閭d箞 SVM 鐨勭洰鐨勫氨鏄兂瑕佺敾鍑轰竴鏉$嚎锛屼互鈥滄渶濂藉湴鈥濆尯鍒嗚繖涓ょ被鐐癸紝浠ヨ嚦濡傛灉浠ュ悗鏈変簡鏂扮殑鐐癸紝杩欐潯绾夸篃鑳藉仛鍑哄緢濂界殑鍒嗙被锛屼篃灏辨槸璇磋浣挎潯鐩寸嚎鑳藉杈惧埌鏈€濂界殑娉涘寲鑳藉姏銆傞偅涔堣兘澶熺敾鍑哄灏戞潯绾垮鏍锋湰鐐硅繘琛屽尯鍒嗭紵绾挎槸鏈夋棤鏁版潯鍙互鐢荤殑锛屽尯鍒氨鍦ㄤ簬鏁堟灉濂戒笉濂姐€傛瘮濡備笅鍥句腑缁跨嚎灏变笉濂斤紝钃濈嚎涓€鑸紝绾㈢嚎鐪嬭捣鏉ヤ細鏇村ソ銆傛垜浠墍甯屾湜鎵惧埌鐨勮繖鏉℃晥鏋滄渶濂界殑绾垮彨浣滃垝鍒嗚秴骞抽潰锛屽畠鏄竴涓兘浣夸袱绫讳箣闂寸殑绌洪棿澶у皬鏈€澶х殑涓€涓秴骞抽潰銆?/p>
涓轰粈涔堣鍙綔鈥滆秴骞抽潰鈥濆憿锛熷洜涓烘牱鏈殑鐗瑰緛寰堝彲鑳芥槸楂樼淮鐨勶紝姝ゆ椂鏍锋湰绌洪棿鐨勫垝鍒嗗氨闇€瑕佲€滆秴骞抽潰鈥濄€傝繖涓秴骞抽潰鍦ㄤ簩缁村钩闈笂鐪嬪埌鐨勫氨鏄竴鏉$洿绾匡紝鍦ㄤ笁缁寸┖闂翠腑灏辨槸涓€涓钩闈紝鍥犳锛屾垜浠妸杩欎釜鍒掑垎鏁版嵁鐨勫喅绛栬竟鐣岀粺绉颁负瓒呭钩闈€傜杩欎釜瓒呭钩闈㈡渶杩戠殑鐐瑰氨鍙仛鏀寔鍚戦噺銆傛敮鎸佸悜閲忔満灏辨槸瑕佷娇瓒呭钩闈㈠拰鏀寔鍚戦噺涔嬮棿鐨勯棿闅斿敖鍙兘鐨勫ぇ锛岃繖鏍疯秴骞抽潰鎵嶅彲浠ュ皢涓ょ被鏍锋湰鍑嗙‘鐨勫垎寮€锛岃€屼繚璇侀棿闅斿敖鍙兘鐨勫ぇ灏辨槸淇濊瘉鍒嗙被鍣ㄨ宸敖鍙兘鐨勫皬銆?/p>
閭d箞鐢荤嚎鐨勬爣鍑嗘槸浠€涔堬紵濡備綍鎵嶈兘鐢诲嚭鏁堟灉濂界殑绾匡紵SVM 灏嗕細瀵绘壘鍙互鍖哄垎涓や釜绫诲埆骞朵笖鑳戒娇杈归檯锛坢argin锛夋渶澶х殑瓒呭钩闈紙hyper plane锛夛紝鍗冲垝鍒嗚秴骞抽潰銆傝竟闄呭氨鏄垎绫荤殑瓒呭钩闈㈠拰瀵瑰簲绫诲埆鏈€杩戠殑鏍锋湰鐐逛箣闂寸殑璺濈銆?img data-ratio="0.7111756168359942" src="/img?url=https://mmbiz.qpic.cn/mmbiz_png/u7hveCZPhOrtfy8TEQdmWxIb3dU9fnSlfXpFG1Y5ywEvup3ibsM4GicarEVSpFSF4twBFr4YLrtQPKff5Ws8mnKg/640?wx_fmt=png" data-type="png" data-w="689" alt="鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇" class="mq-81">
濡備笂鍥炬墍绀猴紝鎵€鏈夊潗钀藉湪杈归檯瓒呭钩闈笂鐨勭偣琚О涓烘敮鎸佸悜閲忥紙support vectors锛夛紝瀹冧滑鏄敤鏉ュ畾涔夎竟闄呯殑锛屾槸璺濈鍒掑垎瓒呭钩闈㈡渶杩戠殑鐐广€傛敮鎸佸悜閲忔敮鎾戜簡杈归檯鍖哄煙锛屽苟涓旂敤浜庡缓绔嬪垝鍒嗚秴骞抽潰銆傚€煎緱娉ㄦ剰鏄紝鏀寔鍚戦噺姣忎竴渚у彲鑳戒笉姝竴涓紝鏈夊彲鑳戒竴渚ф湁澶氫釜鐐归兘钀藉湪杈归檯骞抽潰涓娿€傚涓嬪浘鎵€绀猴紝SVM鐨勭洰鏍囧氨鏄娇杩欎釜杈归檯锛?span class="mq-83"> 锛夋渶澶у寲锛屽叾涓?span class="mq-103"> 鏄悜閲忕殑鑼冩暟锛坣orm锛夈€?img data-ratio="0.5192307692307693" src="/img?url=https://mmbiz.qpic.cn/mmbiz_jpg/u7hveCZPhOrtfy8TEQdmWxIb3dU9fnSlAygYltlwS2GUsEaFHdRiaNHwVEM4HrWtosn28o44WcOyDCicfOuts7icQ/640?wx_fmt=jpeg" data-type="jpeg" data-w="1040" alt="鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇" class="mq-119">
1.3 SVM 绠楁硶鐗瑰緛
SVM 鎵€璁粌鍑虹殑妯″瀷锛屽叾绠楁硶澶嶆潅搴︽槸鐢辨敮鎸佸悜閲忕殑涓暟鍐冲畾鐨勶紝鑰屼笉鏄敱鏁版嵁鐨勭淮搴﹀喅瀹氱殑锛屽綋鐒舵敮鎸佸悜閲忕殑涓暟澶氬皯涔熷拰璁粌闆嗙殑澶у皬鏈夊叧銆傚洜姝?SVM 鍙互涓€瀹氱▼搴︿笂閬垮厤杩囨嫙鍚堬紙overfitting锛夌殑鐜拌薄銆係VM 璁粌鍑烘潵鐨勬ā鍨嬪畬鍏ㄤ緷璧栦簬鏀寔鍚戦噺锛屽嵆浣胯缁冮泦閲岄潰鎵€鏈夐潪鏀寔鍚戦噺鐨勭偣閮借鍘婚櫎锛岄噸澶嶈缁冭繃绋嬶紝缁撴灉渚濈劧浼氬緱鍒板畬鍏ㄧ浉鍚岀殑妯″瀷銆傝嫢涓€涓?SVM 璁粌寰楀嚭鐨勬敮鎸佸悜閲忎釜鏁版瘮杈冨皯锛岄偅涔?SVM 璁粌鍑虹殑妯″瀷鍏锋湁杈冨ソ鐨勬硾鍖栬兘鍔涖€?/p>
2. SVM 姹傝В杩囩▼
SVM鐨勭洰鏍囧氨鏄壘鍑鸿竟闄呮渶澶х殑瓒呭钩闈紝閭d箞濡備綍鎵惧嚭杩欎釜鏈€澶ц竟闄呯殑瓒呭钩闈㈠憿锛圡MH锛夛紵鍒╃敤 Karush-Kuhn-Tucker锛圞KT锛夋潯浠跺拰鎷夋牸鏈楁棩鍏紡锛屽彲浠ユ帹鍑?MMH 鍙互琚〃绀轰负浠ヤ笅鍐冲畾杈圭晫锛坉ecision boundary锛?/p>
璇ユ柟绋嬪氨琛ㄧず杈归檯鏈€澶у寲鐨勫垝鍒嗚秴骞抽潰銆?/p>
-
鏄敮鎸佸悜閲忕偣鐨勪釜鏁帮紝鍥犱负鍏跺疄澶у鏁扮偣骞朵笉鏄敮鎸佸悜閲忕偣锛屽彧鏈夎惤鍦ㄨ竟闄呰秴骞抽潰涓婄殑鐐规墠鏄敮鎸佸悜閲忕偣銆傚洜姝ゆ垜浠氨鍙灞炰簬鏀寔鍚戦噺鐐圭殑杩涜姹傚拰锛? -
涓烘敮鎸佸悜閲忕偣鐨勭壒寰佸€硷紱 -
鏄敮鎸佸悜閲忕偣 鐨勭被鍒爣璁帮紙class label)锛屾瘮濡?1杩樻槸-1锛? -
鏄娴嬭瘯鐨勫疄渚嬶紝鎯崇煡閬撳畠搴旇灞炰簬鍝竴绫伙紝鎶婂畠甯﹀叆璇ユ柟绋嬶紱 -
鍜? 閮芥槸鍗曚竴鏁板€煎瀷鍙傛暟锛岀敱浠ヤ笂鎻愬埌鐨勬渶浼樼畻娉曞緱鍑猴紝 鏄媺鏍兼湕鏃ヤ箻鏁般€?
姣忓綋鏈夋柊鐨勬祴璇曟牱鏈? 锛屽皢瀹冨甫鍏ヨ鏂圭▼锛岀湅璇ユ柟绋嬬殑鍊兼槸姝h繕鏄礋锛屾牴鎹鍙疯繘琛屽綊绫汇€?/p>
3. 鏍稿嚱鏁?/span>
3.1 浣跨敤鏍稿嚱鏁扮殑鍘熷洜
鍦ㄧ嚎鎬?SVM 涓浆鍖栦负鏈€浼樺寲闂鏃舵眰瑙g殑鍏紡璁$畻鏄互鍐呯Н锛坉ot product锛夊舰寮忓嚭鐜扮殑锛屽亣璁惧師濮嬬殑鏁版嵁鏄潪绾挎€х殑锛屾垜浠€氳繃涓€涓槧灏?
灏嗗叾鏄犲皠鍒颁竴涓珮缁寸┖闂翠腑锛屾暟鎹垯鍙樺緱绾挎€у彲鍒嗕簡銆備絾鏄槧灏勪箣鍚庡緱鍒扮殑鏂扮┖闂寸殑缁村害鏄洿楂樼殑锛岀敋鑷虫槸鏃犵┓缁寸殑锛岃繖鏄唴绉殑璁$畻灏变細鍙樺緱闈炲父楹荤儲锛屽洜姝ら渶瑕佸埄鐢ㄦ牳鍑芥暟锛坘ernel function锛夋潵鍙栦唬璁$畻闈炵嚎鎬ф槧灏勫嚱鏁扮殑鍐呯Н銆備互涓嬫牳鍑芥暟鍜岄潪绾挎€ф槧灏勫嚱鏁扮殑鍐呯Н绛夊悓锛屼絾鏍稿嚱鏁?K 鐨勮繍绠楅噺瑕佽繙灏戜簬姹傚唴绉€?/p>
3.2 甯哥敤鏍稿嚱鏁?/span>
-
h 搴﹀椤瑰紡鏍稿嚱鏁帮紙polynomial kernel of degree h锛?
杩欐牳鎵€瀵规槧鐨勬槧灏勬槸鍙互琛ㄧず鍑烘潵鐨勶紝璇ョ┖闂寸殑缁村害鏄?span class="mq-273"> 锛屽叾涓?m 鏄師濮嬬┖闂寸殑缁村害銆?/p>
-
楂樻柉寰勫悜鍩烘牳鍑芥暟锛圙aussian radial basis function kernel锛?
杩欎釜鏍稿氨浼氬皢鍘熷绌洪棿鏄犲皠涓烘棤绌风┖闂达紝涓嶈繃锛屽鏋? 閫夌殑寰堝ぇ锛岄珮娆$壒寰佷笂鐨勬潈閲嶅疄闄呬笂琛板噺鐨勯潪甯稿揩锛屽洜姝ゅ疄闄呬笂鐩稿綋浜庝竴涓綆缁寸殑瀛愮┖闂达紱鍙嶄箣锛屽鏋? 閫夌殑寰堝皬锛屽垯鍙互灏嗕换鎰忕殑鏁版嵁鏄犲皠涓虹嚎鎬у彲鍒嗭紝浣嗕篃浼氫即闅忎弗閲嶇殑杩囨嫙鍚堥棶棰樸€備絾鎬荤殑鏉ヨ锛岄€氳繃璋冩帶鍙傛暟 锛岄珮鏂牳鍏锋湁鐩稿綋楂樼殑鐏垫椿鎬э紝涔熸槸浣跨敤鏈€骞挎硾鐨勬牳鍑芥暟涔嬩竴銆?/p>
-
S 鍨嬫牳鍑芥暟锛圫igmoid function kernel锛?
杩欎釜鏍稿瓨鍦ㄧ殑涓昏鐩殑鏄娇寰椻€滄槧灏勫悗绌洪棿涓殑闂鈥濆拰鈥滄槧灏勫墠绌洪棿涓殑闂鈥濅袱鑰呭湪褰㈠紡涓婄粺涓€璧锋潵銆?/p>
鈥?/p>
杩炰韩浼?- 鏂囨湰鍒嗘瀽涓庣埇铏?- 涓撻瑙嗛
涓昏鍢夊锛氬徃缁ф槬 || 娓镐竾娴?/p>
3.3 鏍稿嚱鏁扮殑閫夋嫨
鍦ㄩ€夊彇鏍稿嚱鏁拌В鍐冲疄闄呴棶棰樻椂锛岄€氬父閲囩敤鐨勬柟娉曟湁涓ょ锛氫竴鏄埄鐢ㄤ笓瀹剁殑鍏堥獙鐭ヨ瘑棰勫厛閫夊畾鏍稿嚱鏁?浜屾槸閲囩敤 Cross-Validation 鏂规硶锛屽嵆鍦ㄨ繘琛屾牳鍑芥暟閫夊彇鏃讹紝鍒嗗埆璇曠敤涓嶅悓鐨勬牳鍑芥暟锛屽綊绾抽€夊彇璇樊鏈€灏忕殑鏍稿嚱鏁般€?/p>
4. SVM 鐨?Python 瀹炵幇
浠ラ娴嬩腑灏忎紒涓氫俊鐢ㄩ闄╀负渚嬶紝閫夊彇 2019 骞村湪涓皬鏉夸笂甯傜殑浼佷笟涓烘牱鏈紝棰勬祴鍏舵槸鍚﹀叿鏈夎繚绾﹂闄╋紝鎴戜滑灏嗕笂甯備紒涓氫腑 ST 鎴?*ST 鐨勪紒涓氳涓烘槸鏈夎繚绾﹂闄╃殑浼佷笟锛岄€夊彇 6 椤硅储鍔℃寚鏍囪繘琛岄娴嬶紝璐㈠姟鎸囨爣鍒嗗埆涓猴細娴佸姩姣旂巼銆侀€熷姩姣旂巼銆佸埄娑︾巼銆丷OA銆佹€昏祫浜у闀跨巼銆佺幇閲戞瘮鐜囥€?/p>
# 棣栧厛瑕佽皟鐢ㄩ渶瑕佺殑妯″潡
import numpy as np #璋冪敤numpy妯″潡
import pandas as pd #璋冪敤Pandas妯″潡
# 璇诲彇鏁版嵁
X1=pd.ExcelFile('dataset.xlsx') #璇诲彇鏁版嵁
X1.sheet_names
# 璁剧疆鐗瑰緛鍙橀噺
X_Features = pd.read_excel(X1, sheet_names="Sheet1", usecols=[1,2,3,4,5,6])
X_Features.head() #鍙互鏌ョ湅鐗瑰緛鍙橀噺锛岃姝ラ鍙互鐪佺暐
杈撳嚭鐨勭粨鏋滀负 6 椤圭敤浜庨娴嬬殑璐㈠姟鎸囨爣锛屼粎灞曠ず鍑哄墠 5 琛屾暟鎹€?/p>
current ratio | profit margin | quick ratio | ROA | assets growth rate | cash ratio | |
---|---|---|---|---|---|---|
0 | 1.2575 | -444.3600 | 0.9753 | -142.4324 | -75.2146 | 56.3938 |
1 | 0.4772 | -41.0634 | 0.3112 | -5.0946 | 26.3844 | 4.7799 |
2 | 2.1478 | -60.3331 | 1.3147 | -28.1622 | -7.4949 | 75.0185 |
3 | 0.2740 | -24.0082 | 0.1667 | -18.8108 | -43.2743 | 3.8674 |
4 | 0.7362 | -101.3008 | 0.5202 | -36.2078 | -44.9836 | 26.0609 |
X_Features.info() #鍙互鏌ョ湅鐗瑰緛鍙橀噺鐨勬暟鎹被鍨嬶紝璇ユ楠ゅ彲浠ョ渷鐣?/span>
# 璁剧疆鏍囩
Y_Response = pd.read_excel(X1, sheet_names="Sheet1", usecols=[7])
Y_Response = Y_Response["risk"].ravel() #璁剧疆鏍囩
# 璁剧疆璁粌闆嗗拰娴嬭瘯闆?/span>
from sklearn import model_selection
X_Train, X_Test, Y_Train, Y_Test = model_selection.train_test_split(X_Features, Y_Response, test_size=0.3, shuffle=True) #鍒掑垎鍑鸿缁冮泦鍜屾祴璇曢泦锛宼est_size琛ㄧず娴嬭瘯闆嗙殑姣斾緥锛岃繖閲屾槸30%锛岃鏁板瓧鍙互鏇存敼锛泂huffle=True鏄皢搴忓垪鐨勬墍鏈夊厓绱犻殢鏈烘帓搴?/span>
X_Train.head() #鏌ョ湅璁粌闆嗭紝璇ユ楠ゅ彲鐪佺暐
X_Test.head() #鏌ョ湅娴嬭瘯闆嗭紝璇ユ楠ゅ彲鐪佺暐
# 璋冪敤 SVM 绠楁硶
from sklearn.svm import SVC #璋冪敤Scikit learn涓殑SVM绠楁硶
# 璁剧疆鍙傛暟杩涜鎷熷悎
C = 1e5 #鎯╃綒鍥犲瓙锛岃鏁板瓧鍙互鏇存敼
clf = SVC(C=C, kernel='rbf', gamma=20, decision_function_shape='ovr') #kernel='rbf'鏃讹紙default锛夛紝涓洪珮鏂牳锛実amma鍊艰秺灏忥紝鍒嗙被鐣岄潰瓒婅繛缁紱gamma鍊艰秺澶э紝鍒嗙被鐣岄潰瓒娾€滄暎鈥濓紝鍒嗙被鏁堟灉瓒婂ソ锛屼絾鏈夊彲鑳戒細杩囨嫙鍚堛€俤ecision_function_shape='ovr'鏃讹紝涓簅ne v rest锛屽嵆涓€涓被鍒笌鍏朵粬绫诲埆杩涜鍒掑垎銆?/span>
clf.fit(X_Train, Y_Train.ravel()) #瀵硅缁冮泦杩涜鎷熷悎
# 瀵规祴璇曢泦鏁版嵁杩涜棰勬祴
y_pred = clf.predict(X_Test) #瀵规祴璇曢泦鏁版嵁杩涜棰勬祴
#鏌ョ湅棰勬祴鐨勫噯纭害
from sklearn.metrics import classification_report
print (classification_report(Y_Test, y_pred)) #鏌ョ湅棰勬祴鐨勫噯纭巼锛圓ccuracy锛夈€佺簿纭巼锛圥recision锛夈€佸彫鍥炵巼锛圧ecall锛夊拰F鍊硷紙F-Measure锛夌瓑鎸囨爣
precision recall f1-score support
0 0.98 1.00 0.99 270
1 0.00 0.00 0.00 6
accuracy 0.98 276
macro avg 0.49 0.50 0.49 276
weighted avg 0.96 0.98 0.97 276
浠庨娴嬬粨鏋滄潵鐪嬶紝棰勬祴鐨勫噯纭巼锛圓ccuracy锛変负 98%锛岃櫧鐒舵暣浣撲笂棰勬祴鐨勫噯纭害杈冮珮锛屼絾鏄湪娴嬭瘯闆嗕腑鏈夎繚绾﹂闄╃殑 6 瀹朵紒涓氬嵈娌℃湁棰勬祴鍑烘潵锛屼富瑕佹槸鍥犱负鍦ㄦ暣浣撶殑鏍锋湰涓紝鏈夎繚绾﹂闄╃殑浼佷笟鏁伴噺杩囧皯锛岃繖涔熻鏄庡湪杩涜淇$敤椋庨櫓棰勬祴鏃讹紝鏈変俊鐢ㄩ闄╃殑浼佷笟鏍锋湰涓嶈兘澶皯銆?/p>
5. SVM 鐨?Stata 瀹炵幇
浣跨敤 Stata鑷甫鐨?1978 Automobile Data 鏁版嵁锛岄娴嬫苯杞︾被鍨嬫槸鈥淒omestic鈥濊繕鏄€淔oreign鈥濄€傚湪杩欎竴渚嬪瓙涓紝浣跨敤2椤规寚鏍囪繘琛岄娴嬶紝鍒嗗埆鏄?price 鍜?gear_ratio銆傚湪 Stata 涓殑 SVM 瀹炵幇闇€瑕佸畨瑁呭閮ㄥ懡浠?svmachines锛屽叿浣撳疄鐜拌繃绋嬪涓嬨€?/p>
* 鍦ㄤ娇鐢?Stata 杩涜 SVM 瀹炵幇涔嬪墠锛岄渶瑕佸厛瀹夎澶栭儴鍛戒护锛歴vmachines
ssc install svmachines, replace
* 绗竴姝ラ渶瑕佸仛鐨勬槸鍖哄垎璁粌闆嗗拰娴嬭瘯闆?br class="mq-529">sysuse auto, clear
set seed 9876
generate u = runiform()
sort u
local split = floor(_N/2)
local train = "1/`=`split'-1'"
local test = "`split'/`=_N'"
* 鍦ㄨ缁冮泦涓埄鐢⊿VM杩涜璁粌锛?br class="mq-541">svmachines foreign price gear_ratio if !missing(rep78) in `train'
* 娴嬭瘯闆嗛噷杩涜棰勬祴锛屽苟缁熻鍑嗙‘鐜囷細
predict P in `test'
generate err = foreign != P in `test'
tab err in `test'
err | Freq. Percent Cum.
------------+-----------------------------------
0 | 28 73.68 73.68
1 | 10 26.32 100.00
------------+-----------------------------------
Total | 38 100.00
浠ヤ笂杈撳嚭缁撴灉涓紝0 琛ㄧず棰勬祴姝g‘锛? 琛ㄧず棰勬祴閿欒銆傛牴鎹互涓婅緭鍑虹粨鏋滐紝灏卞彲浠ヨ繘涓€姝ヨ绠楀嚭鍑嗙‘鐜囩瓑鎸囨爣銆傚湪杩欎竴渚嬪瓙涓紝棰勬祴鐨勫噯纭巼锛圓ccuracy锛変负锛?8 梅 38 = 73.68%
涓嬮潰鎴戜滑浣跨敤 Stata 鐨勫彟涓€缁勬暟鎹繘琛?SVM 鐨?Stata 瀹炵幇銆備娇鐢?Stata 鑷甫鐨?nlsw88.dta 鏁版嵁锛岃鏁版嵁鍖呭惈浜?1988 骞撮噰闆嗙殑 2246 涓編鍥藉濂崇殑璧勬枡銆傚湪杩欎竴绀轰緥涓紝鎴戜滑浣跨敤缇庡浗濡囧コ鐨勫伐璧勨€渨age鈥濆幓棰勬祴鈥渦nion鈥濇槸鍚︿负宸ヤ細鎴愬憳锛屽叿浣撳疄鐜拌繃绋嬪涓嬨€?/p>
*-S1: 绗竴姝ュ拰涓婁竴涓緥瀛愮浉鍚岋紝鎴戜滑闇€瑕佸仛鐨勬槸鍖哄垎璁粌闆嗗拰娴嬭瘯闆?br class="mq-562">sysuse nlsw88.dta, clear
set seed 9876
generate u = runiform()
sort u
local split = floor(_N/2)
local train = "1/`=`split'-1'"
local test = "`split'/`=_N'"
*-S2: 鍦ㄨ缁冮泦涓埄鐢⊿VM杩涜璁粌锛?br class="mq-575">svmachines union wage if !missing(union) in `train'
* Note: if !missing(union) 鐨勭洰鐨勬槸涓轰簡鍦ㄨ繘琛屾満鍣ㄥ涔犳椂蹇界暐缂哄け鐨勬暟鎹」锛?br class="mq-580">* 涔熷彲浠ヤ簨鍏堜娇鐢?nbsp;drop 鐨勫姛鑳藉皢鏈夌己澶辩殑鏁版嵁 drop 鎺?br class="mq-581">
*-S3: 娴嬭瘯闆嗛噷杩涜棰勬祴锛屽苟缁熻鍑嗙‘鐜囷細
predict P in `test'
generate err = union != P in `test'
tab err in `test'
err | Freq. Percent Cum.
------------+-----------------------------------
0 | 709 63.08 63.08
1 | 415 36.92 100.00
------------+-----------------------------------
Total | 1,124 100.00
浠ヤ笂杈撳嚭缁撴灉涓紝0 琛ㄧず棰勬祴姝g‘锛? 琛ㄧず棰勬祴閿欒銆傛牴鎹互涓婅緭鍑虹粨鏋滐紝灏卞彲浠ヨ繘涓€姝ヨ绠楀嚭鍑嗙‘鐜囩瓑鎸囨爣銆傚湪杩欎竴渚嬪瓙涓紝棰勬祴鐨勫噯纭巼锛圓ccuracy锛変负锛?09 梅 1124 = 63.08%锛岀浉杈冧簬涓婁竴涓緥瀛愶紝鍑嗙‘鐜囨湁鎵€涓嬮檷銆傝繖涓昏鏄洜涓哄湪杩欎竴渚嬪瓙涓紝鎴戜滑涓富瑕佷负浜嗗睍绀?SVM 鐨勫疄鐜帮紝鍥犳鍙€夊彇浜?wage 杩欎竴涓彉閲忓 union 杩涜棰勬祴锛屽ぇ瀹跺湪鍋氶娴嬫椂閫氬父浼氶€夊彇鏇村鐨勫彉閲忋€?/p>
6. 鍙傝€冩枃鐚?/span>
-
Guenther N, Schonlau M. Support Vector Machines[J]. Stata Journal, 2016, 16(4):917-937. [PDF]
鈥?/p>
杩炰韩浼?鍦ㄧ嚎璇惧爞
鈥?鈥? http://lianxh.duanshu.com
鍏嶈垂鍏紑璇撅細
-
鐩村嚮闈㈡澘鏁版嵁妯″瀷 - 杩炵帀鍚涳紝鏃堕暱锛?灏忔椂40鍒嗛挓 -
Stata 33 璁?- 杩炵帀鍚? 姣忚 15 鍒嗛挓. -
閮ㄥ垎鐩存挱璇?璇剧▼璧勬枡涓嬭浇 (PPT锛宒ofiles绛?
娓╅Θ鎻愮ず锛?/strong> 鏂囦腑閾炬帴鍦ㄥ井淇′腑鏃犳硶鐢熸晥銆傝鐐瑰嚮搴曢儴銆岄槄璇诲師鏂囥€?/span>銆?/p>
鈥?/p>
2020骞?鏈?9-31鏃?(姝ゆ椂鐐瑰悗浠嶅彲璐拱鍥炴斁瑙嗛) 鈥?/p>
杩炰韩浼?路 鎺ㄦ枃涓撹緫锛?br class="mq-669"> | | | 馃帵 杩炰韩浼氬皬绋嬪簭锛氭壂涓€鎵紝鐪嬫帹鏂囷紝鐪嬭棰戔€︹€?/p>
馃崏 鎵爜鍔犲叆杩炰韩浼氬井淇$兢锛屾彁闂氦娴佹洿鏂逛究
馃摍 涓昏鍢夊锛氳繛鐜夊悰 | 椴佹檽涓?| 寮犲畞
馃崗 锛歨ttps://gitee.com/arlionn/TE
鍏充簬鎴戜滑
| | | |
| | | |
| | |
璇剧▼, 鐩存挱, 瑙嗛, 瀹㈡湇, 妯″瀷璁惧畾, 鐮旂┒璁捐,
stata, plus锛孭rofile, 鎵嬪唽, SJ, 澶栭儴鍛戒护, profile, mata, 缁樺浘, 缂栫▼, 鏁版嵁, 鍙鍖?/code>
DID锛孯DD, PSM锛孖V锛孌ID, DDD, 鍚堟垚鎺у埗娉曪紝鍐呯敓鎬? 浜嬩欢鐮旂┒
浜や箻, 骞虫柟椤? 缂哄け鍊? 绂荤兢鍊? 缂╁熬, R2, 涔辩爜, 缁撴灉
Probit, Logit, tobit, MLE, GMM, DEA, Bootstrap, bs, MC, TFP
闈㈡澘, 鐩村嚮闈㈡澘鏁版嵁, 鍔ㄦ€侀潰鏉? VAR, 鐢熷瓨鍒嗘瀽, 鍒嗕綅鏁?/code>
绌洪棿, 绌洪棿璁¢噺, 杩炶€佸笀, 鐩存挱, 鐖櫕, 鏂囨湰, 姝e垯, python
Markdown, Markdown骞荤伅鐗? marp, 宸ュ叿, 杞欢, Sai2, gInk, Annotator, 鎵嬪啓鎵规敞
鐩堜綑绠$悊, 鐗规柉鎷? 鐢插3铏? 璁烘枃閲嶇幇
鏄撴噦鏁欑▼, 鐮佷簯, 鏁欑▼, 鐭ヤ箮
以上是关于鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇的主要内容,如果未能解决你的问题,请参考以下文章