鏀寔鍚戦噺鏈猴細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>

涓昏鍢夊锛氱帇瀛樺悓鏁欐巿 (涓ぎ璐㈢粡澶у)

鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇
杩炰韩浼?鐢熷瓨鍒嗘瀽涓撻鐩存挱

鈥?/p>

2020骞?鏈?3鏃ワ紝19:00-21:00, 88鍏?br class="mq-58">涓昏鍢夊锛氬徃缁ф槬 锛?/p>

鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇

鈥?/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>

鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇

涓轰粈涔堣鍙綔鈥滆秴骞抽潰鈥濆憿锛熷洜涓烘牱鏈殑鐗瑰緛寰堝彲鑳芥槸楂樼淮鐨勶紝姝ゆ椂鏍锋湰绌洪棿鐨勫垝鍒嗗氨闇€瑕佲€滆秴骞抽潰鈥濄€傝繖涓秴骞抽潰鍦ㄤ簩缁村钩闈笂鐪嬪埌鐨勫氨鏄竴鏉$洿绾匡紝鍦ㄤ笁缁寸┖闂翠腑灏辨槸涓€涓钩闈紝鍥犳锛屾垜浠妸杩欎釜鍒掑垎鏁版嵁鐨勫喅绛栬竟鐣岀粺绉颁负瓒呭钩闈€傜杩欎釜瓒呭钩闈㈡渶杩戠殑鐐瑰氨鍙仛鏀寔鍚戦噺銆傛敮鎸佸悜閲忔満灏辨槸瑕佷娇瓒呭钩闈㈠拰鏀寔鍚戦噺涔嬮棿鐨勯棿闅斿敖鍙兘鐨勫ぇ锛岃繖鏍疯秴骞抽潰鎵嶅彲浠ュ皢涓ょ被鏍锋湰鍑嗙‘鐨勫垎寮€锛岃€屼繚璇侀棿闅斿敖鍙兘鐨勫ぇ灏辨槸淇濊瘉鍒嗙被鍣ㄨ宸敖鍙兘鐨勫皬銆?/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>

鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇
杩炰韩浼?鏂囨湰鍒嗘瀽涓庣埇铏?涓撻瑙嗛鏁欑▼

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
鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇

鍏嶈垂鍏紑璇撅細

  • 鐩村嚮闈㈡澘鏁版嵁妯″瀷 - 杩炵帀鍚涳紝鏃堕暱锛?灏忔椂40鍒嗛挓
  • Stata 33 璁?- 杩炵帀鍚? 姣忚 15 鍒嗛挓.
  • 閮ㄥ垎鐩存挱璇?璇剧▼璧勬枡涓嬭浇 (PPT锛宒ofiles绛?

娓╅Θ鎻愮ず锛?/strong> 鏂囦腑閾炬帴鍦ㄥ井淇′腑鏃犳硶鐢熸晥銆傝鐐瑰嚮搴曢儴銆岄槄璇诲師鏂囥€?/span>銆?/p>

鈥?/p>

2020骞?鏈?9-31鏃?(姝ゆ椂鐐瑰悗浠嶅彲璐拱鍥炴斁瑙嗛)
馃摍 涓昏鍢夊锛氳繛鐜夊悰 | 椴佹檽涓?| 寮犲畞
馃崗   锛歨ttps://gitee.com/arlionn/TE

杩炰韩浼?鏁堢巼鍒嗘瀽涓撻瑙嗛

鈥?/p>


鍏充簬鎴戜滑

  • 馃崕 杩炰韩浼?( 涓婚〉锛歭ianxh.cn ) 鐢变腑灞卞ぇ瀛﹁繛鐜夊悰鑰佸笀鍥㈤槦鍒涘姙锛屽畾鏈熷垎浜疄璇佸垎鏋愮粡楠屻€?
  • 馃憠 鐩磋揪杩炰韩浼氾細銆? 鐧惧害涓€涓嬶細 杩炰韩浼?/span>銆戝嵆鍙洿杈捐繛浜細涓婚〉銆備害鍙繘涓€姝ユ坊鍔? 涓婚〉锛岀煡涔庯紝闈㈡澘鏁版嵁锛岀爺绌惰璁?/span> 绛夊叧閿瘝缁嗗寲鎼滅储銆?
  • 馃搳 鍏紬鍙锋帹鏂囧垎绫伙細 鍘嗗彶鎺ㄦ枃鍒嗕负澶氫釜涓撹緫锛屼富娴佹柟娉曚粙缁嶄竴鐩簡鐒讹細DID, RDD, IV, GMM, FE, Probit 绛夈€?

    杩炰韩浼?路 鎺ㄦ枃涓撹緫锛?br class="mq-669"> | | |
    | | | |
    | |  |   |  
    | | |

  • 鉂? 鍏紬鍙峰叧閿瘝鎼滅储/鍥炲 鍔熻兘宸茬粡涓婄嚎銆傚ぇ瀹跺彲浠ュ湪鍏紬鍙峰乏涓嬭鐐瑰嚮閿洏鍥炬爣锛岃緭鍏ョ畝瑕佸叧閿瘝锛屼互渚垮揩閫熷憟鐜板巻鍙叉帹鏂囷紝鑾峰彇宸ュ叿杞欢鍜屾暟鎹笅杞姐€傚父瑙佸叧閿瘝锛?
    • 璇剧▼, 鐩存挱, 瑙嗛, 瀹㈡湇, 妯″瀷璁惧畾, 鐮旂┒璁捐,
    • 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 瀹炵幇
杩炰韩浼氫富椤? lianxh.cn

馃帵  杩炰韩浼氬皬绋嬪簭锛氭壂涓€鎵紝鐪嬫帹鏂囷紝鐪嬭棰戔€︹€?/p>


馃崏 鎵爜鍔犲叆杩炰韩浼氬井淇$兢锛屾彁闂氦娴佹洿鏂逛究


以上是关于鏀寔鍚戦噺鏈猴細Stata 鍜?Python 瀹炵幇的主要内容,如果未能解决你的问题,请参考以下文章

鏈哄櫒瀛︿範瀹炴垬锛?锛夛細鏀寔鍚戦噺鏈猴紙涓嬶級

鍏充簬璁粌闆?楠岃瘉闆?娴嬭瘯闆嗙殑鍒掑垎

鍩轰簬璇嶅吀鍜屾湸绱犺礉鍙舵柉涓枃鎯呮劅鍊惧悜鍒嗘瀽绠楁硶

Redis 鍜?Memcached 鐨勫尯鍒?Tair

Python澶氱嚎绋嬩箣姝婚攣

寰俊app鏀粯python浠g爜瀹炵幇

(c)2006-2024 SYSTEM All Rights Reserved IT常识