99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀R語言利用nnet包訓練神經(jīng)網(wǎng)絡模型
R語言利用nnet包訓練神經(jīng)網(wǎng)絡模型
2018-05-23
收藏

R語言利用nnet包訓練神經(jīng)網(wǎng)絡模型

R語言提供了另外一個能夠處理人工神經(jīng)網(wǎng)絡的算法包nnet,該算法提供了傳統(tǒng)的前饋反向傳播神經(jīng)網(wǎng)絡算法的實現(xiàn)。
操作
安裝包與數(shù)據(jù)分類:
library(nnet)
data("iris")
set.seed(2)
ind = sample(2,nrow(iris),replace = TRUE,prob = c(0.7,0.3))
trainset = iris[ind == 1,]
testset = iris[ind == 2,]
使用nnet包訓練神經(jīng)網(wǎng)絡

iris.nn = nnet(Species ~ .,data = trainset,size = 2,rang = 0.1,decay = 5e-4,maxit = 200)
# weights:  19
initial  value 114.539765
iter  10 value 52.100312
iter  20 value 50.231442
iter  30 value 49.526599
iter  40 value 49.402229
iter  50 value 44.680338
iter  60 value 5.254389
iter  70 value 2.836695
iter  80 value 2.744315
iter  90 value 2.687069
iter 100 value 2.621556
iter 110 value 2.589096
iter 120 value 2.410539
iter 130 value 2.096461
iter 140 value 1.938717
iter 150 value 1.857105
iter 160 value 1.825393
iter 170 value 1.817409
iter 180 value 1.815591
iter 190 value 1.815030
iter 200 value 1.814746
final  value 1.814746
stoppedafter 200 iterations

調(diào)用summary( )輸出訓練好的神經(jīng)網(wǎng)絡

summary(iris.nn)
a 4-2-3 network with 19 weights
options were - softmax modelling  decay=5e-04
 b->h1 i1->h1 i2->h1 i3->h1 i4->h1
-20.60   0.31  -3.84   3.36   7.72
 b->h2 i1->h2 i2->h2 i3->h2 i4->h2
 -7.15   1.50   2.49  -4.14   5.59
 b->o1 h1->o1 h2->o1
 -7.28  -3.67  13.16
 b->o2 h1->o2 h2->o2
 15.90 -16.64 -19.40
 b->o3 h1->o3 h2->o3
 -8.62  20.31   6.24
在應用函數(shù)時可以實現(xiàn)分類觀測,數(shù)據(jù)源,隱蔽單元個數(shù)(size參數(shù)),初始隨機數(shù)權值(rang參數(shù)),權值衰減參數(shù)(decay參數(shù)),最大迭代次數(shù)(maxit),整個過程會一直重復直至擬合準則值與衰減項收斂。
使用模型iris.nn模型完成對測試數(shù)據(jù)集的預測

iris.predict = predict(iris.nn,testset,type = "class")
nn.table = table(testset$Species,iris.predict)
nn.table
            iris.predict
             setosa versicolor virginica
  setosa         17          0         0
  versicolor      0         13         1
  virginica       0          2        13

基于分類表得到混淆矩陣

confusionMatrix(nn.table)
Confusion Matrix and Statistics

            iris.predict
             setosa versicolor virginica
  setosa         17          0         0
  versicolor      0         13         1
  virginica       0          2        13

Overall Statistics

               Accuracy : 0.9348         
                 95% CI : (0.821, 0.9863)
    No Information Rate : 0.3696         
    P-Value [Acc > NIR] : 1.019e-15      

                  Kappa : 0.9019         
 Mcnemar's Test P-Value : NA             

Statistics by Class:

                     Class: setosa Class: versicolor Class: virginica
Sensitivity                 1.0000            0.8667           0.9286
Specificity                 1.0000            0.9677           0.9375
Pos Pred Value              1.0000            0.9286           0.8667
Neg Pred Value              1.0000            0.9375           0.9677
Prevalence                  0.3696            0.3261           0.3043
Detection Rate              0.3696            0.2826           0.2826
Detection Prevalence        0.3696            0.3043           0.3261
Balanced Accuracy           1.0000            0.9172           0.9330
在調(diào)用predict函數(shù)時,我們明確了type參數(shù)為class,因此輸出的是預測的類標號而非概率矩陣。接下來調(diào)用table函數(shù)根據(jù)預測結果和testset的實際類標號生成分類表,最后利用建立的分類表使用table函數(shù)根據(jù)caret中的confusionMatrix方法對訓練好的神經(jīng)網(wǎng)絡預測性能評估。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗證碼對象,之后可以使用它調(diào)用相應的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗服務器是否宕機 new_captcha: data.new_captcha, // 用于宕機時表示是新驗證碼的宕機 product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }