主頁 > 企業開發 > 如何生成嵌套ifelse()陳述句來評估R中混淆矩陣的三個分類二進制級別的預測

如何生成嵌套ifelse()陳述句來評估R中混淆矩陣的三個分類二進制級別的預測

2022-06-03 06:13:04 企業開發

問題:

我有一個名為 的預測模型的匯總輸出結果,該模型pred_model_Tree1 (three columns; 6 obs; 3 variables)是由我使用使用and包的gbm方法構建的分類器生成的。是通過預測我( )呼叫的分類模型的結果(參見下面的 R 代碼)產生的Caretgbmpred_model_Tree1gbmFit1test.datatest.data$Country

我想撰寫一個nested ifelse()模型來評估預測,并且我想使用評估結果confusionMatrix()e1701 pacakge.

我的資料有nine continuous independent variables,一個dependent variable叫做“國家”。這個問題也與我在這里問的一個問題有關。我之前遇到過一條錯誤訊息,可以通過我上一個問題中的鏈接查看。這是混淆矩陣的輸出錯誤。

Error: `data` and `reference` should be factors with the same levels.

因此,我需要評估模型中的每個預測,這樣......

#i.e. if the predicted likelihood that the country is France is '0.9'and the likelihood #it's Holland is '0.1', then the prediction is "France"

#Example
# Evaluate each prediction, i.e. if the predicted likelihood that the country is France is '0.9'
# and the likelihood it's Holland is '0.1', then the prediction is "France"
pred_model_Tree1$evaluation <- ifelse(pred_model_Tree1$France >= 0.5, "France", "Holland")

# Now you can print the confusionMatrix (make sure each factor has the same levels)
confusionMatrix(factor(pred_model_Tree1$evaluation, levels = unique(test.data$Country)),
                factor(test.data$Country, levels = unique(test.data$Country)))

但是,我three categorical binary levelsdependent variable預測資料有“法國”、“意大利”和“西班牙”。因此,我假設我需要nested ifelse()為三元評估撰寫一個陳述句。

如何應用此邏輯來評估可進一步用于混淆矩陣的預測,以輸出分類器模型準確性的匯總統計資訊?由于存在三個級別,我是否還需要使用 >= 大于或等于 0.33 的值?我試圖使用嵌套的 ifelse 函式,如下所示:

 pred_model_Tree1$evaluation <- ifelse(pred_model_Tree1$France >= 0.5, "France", "Holland",
                                   ifelse(pred_model_Tree1$France >= 0.5, "France", "Spain",
                                   ifelse(pred_model_Tree1$Spain >= 0.5,"Spain", "Holland")))
    
    pred_model_Tree1$evaluation

#The output results only show two countries, not three
1] "France"  "France"  "Holland" "Holland" "Holland" "France" 

期望結果:pred_model_Tree1$evaluation輸出應包含三個國家/地區,在評估預測后重復 3 次,因此 的級別和結構與pred_model_Tree1$evaluation的預測輸出相同pred_model_Tree1 model

1] "France"  "France"  "Holland" "Holland" "Holland" "France" "Spain" "Spain "Spain"

與往常一樣,我非常感謝伸出援助之手。

R代碼

#install packages
library(gbm)
library(caret)
library(e1701)

set.seed(45L)

#Produce a new version of the data frame 'Clusters_Dummy' with the rows shuffled
NewClusters=Cluster_Dummy_2[sample(1:nrow(Cluster_Dummy_2)),]

#Produce a dataframe
NewCluster<-as.data.frame(NewClusters)

#Split the training and testing data 70:30
training.parameters <- Cluster_Dummy_2$Country %>% 
createDataPartition(p = 0.7, list = FALSE)
train.data <- NewClusters[training.parameters, ]
test.data <- NewClusters[-training.parameters, ]

dim(train.data)
#259  10

dim(test.data)
#108  10

#Auxiliary function for controlling model fitting
#10 fold cross validation; 10 times
fitControl <- trainControl(## 10-fold CV
                          method = "repeatedcv",
                          number = 10,
                          ## repeated ten times
                          repeats = 10,
                          classProbs = TRUE)
#Fit the model
gbmFit1 <- train(Country ~ ., data=train.data, 
                 method = "gbm", 
                 trControl = fitControl,
                 ## This last option is actually one
                 ## for gbm() that passes through
                 verbose = FALSE)
gbmFit1
summary(gbmFit1)

#Predict the model with the test data
pred_model_Tree1 = predict(gbmFit1, newdata = head(test.data$Country), type = "prob")
pred_model_Tree1

print(pred_model_Tree1)

#Attempt at a nested ifelse() statement

# Evaluate each prediction, i.e. if the predicted likelihood that the country is France is '0.9'
# and the likelihood it's Holland is '0.1', then the prediction is "France"
#>= greater than or equal to
pred_model_Tree1$evaluation <- ifelse(pred_model_Tree1$France >= 0.5, "France", "Holland",
                               ifelse(pred_model_Tree1$France >= 0.5, "France", "Spain",
                               ifelse(pred_model_Tree1$Spain >= 0.5,"Spain", "Holland")))

pred_model_Tree1$evaluation

#The problem is here. The output should contain three countries repeated three times so the levels and structure of the prediction evaluation are the same as the predicted output.

1] "France"  "France"  "Holland" "Holland" "Holland" "France" 

# Now you can print the confusionMatrix (make sure each factor has the same levels)
confusionMatrix(factor(pred_model_Tree1$evaluation, levels = unique(test.data$Country)),
                factor(test.data$Country, levels = unique(test.data$Country)))

資料

structure(list(Low.Freq = c(435L, 94103292L, 1L, 2688L, 8471L, 
28818L, 654755585L, 468628164L, 342491L, 2288474L, 3915L, 411L, 
267864894L, 3312618L, 5383L, 8989443L, 1894L, 534981L, 9544861L, 
3437614L, 475386L, 7550764L, 48744L, 2317845L, 5126197L, 2445L, 
8L, 557450L, 450259742L, 21006647L, 9L, 7234027L, 59L, 9L, 605L, 
9199L, 3022L, 30218156L, 46423L, 38L, 88L, 396396244L, 28934316L, 
7723L, 95688045L, 679354L, 716352L, 76289L, 332826763L, 6L, 90975L, 
83103577L, 9529L, 229093L, 42810L, 5L, 18175302L, 1443751L, 5831L, 
8303661L, 86L, 778L, 23947L, 8L, 9829740L, 2075838L, 7434328L, 
82174987L, 2L, 94037071L, 9638653L, 5L, 3L, 65972L, 0L, 936779338L, 
4885076L, 745L, 8L, 56456L, 125140L, 73043989L, 516476L, 7L, 
4440739L, 612L, 3966L, 8L, 9255L, 84127L, 96218L, 5690L, 56L, 
3561L, 78738L, 1803363L, 809369L, 7131L, 0L), High.Freq = c(6071L, 
3210L, 6L, 7306092L, 6919054L, 666399L, 78L, 523880161L, 4700783L, 
4173830L, 30L, 811L, 341014L, 780L, 44749L, 91L, 201620707L, 
74L, 1L, 65422L, 595L, 89093186L, 946520L, 6940919L, 655350L, 
4L, 6L, 618L, 2006697L, 889L, 1398L, 28769L, 90519642L, 984L, 
0L, 296209525L, 487088392L, 5L, 894L, 529L, 5L, 99106L, 2L, 926017L, 
9078L, 1L, 21L, 88601017L, 575770L, 48L, 8431L, 194L, 62324996L, 
5L, 81L, 40634727L, 806901520L, 6818173L, 3501L, 91780L, 36106039L, 
5834347L, 58388837L, 34L, 3280L, 6507606L, 19L, 402L, 584L, 76L, 
4078684L, 199L, 6881L, 92251L, 81715L, 40L, 327L, 57764L, 97668898L, 
2676483L, 76L, 4694L, 817120L, 51L, 116712L, 666L, 3L, 42841L, 
9724L, 21L, 4L, 359L, 2604L, 22L, 30490L, 5640L, 34L, 51923625L, 
35544L), Peak.Freq = c(87005561L, 9102L, 994839015L, 42745869L, 
32840L, 62737133L, 2722L, 24L, 67404881L, 999242982L, 3048L, 
85315406L, 703037627L, 331264L, 8403609L, 3934064L, 50578953L, 
370110665L, 3414L, 12657L, 40L, 432L, 7707L, 214L, 68588962L, 
69467L, 75L, 500297L, 704L, 1L, 102659072L, 60896923L, 4481230L, 
94124925L, 60164619L, 447L, 580L, 8L, 172L, 9478521L, 20L, 53L, 
3072127L, 2160L, 27301893L, 8L, 4263L, 508L, 712409L, 50677L, 
522433683L, 112844L, 193385L, 458269L, 93578705L, 22093131L, 
6L, 9L, 1690461L, 0L, 4L, 652847L, 44767L, 21408L, 5384L, 304L, 
721L, 651147L, 2426L, 586L, 498289375L, 945L, 6L, 816L, 46207L, 
39135L, 6621028L, 66905L, 26905085L, 4098L, 0L, 14L, 88L, 530L, 
97809006L, 90L, 6L, 260792844L, 9L, 833205723L, 99467321L, 5L, 
8455640L, 54090L, 2L, 309L, 299161148L, 4952L, 454824L), Delta.Freq = c(5L, 
78L, 88553L, 794L, 5L, 3859122L, 782L, 36L, 8756801L, 243169338L, 
817789L, 8792384L, 7431L, 626921743L, 9206L, 95789L, 7916L, 8143453L, 
6L, 4L, 6363L, 181125L, 259618L, 6751L, 33L, 37960L, 0L, 2L, 
599582228L, 565585L, 19L, 48L, 269450424L, 70676581L, 7830566L, 
4L, 86484313L, 21L, 90899794L, 2L, 72356L, 574280L, 869544L, 
73418L, 6468164L, 2259L, 5938505L, 31329L, 1249L, 354L, 8817L, 
3L, 2568L, 82809L, 29836269L, 5230L, 37L, 33752014L, 79307L, 
1736L, 8522076L, 40L, 2289135L, 862L, 801448L, 8026L, 5L, 15L, 
4393771L, 405914L, 71098L, 950288L, 8319L, 1396973L, 832L, 70L, 
1746L, 61907L, 8709547L, 300750537L, 45862L, 91417085L, 79892L, 
47765L, 5477L, 18L, 4186L, 2860L, 754038591L, 375L, 53809223L, 
72L, 136L, 509L, 232325L, 13128104L, 1692L, 8581L, 23L), Delta.Time = c(1361082L, 
7926L, 499L, 5004L, 3494530L, 213L, 64551179L, 70L, 797L, 5L, 
72588L, 86976L, 5163L, 635080L, 3L, 91L, 919806257L, 81443L, 
3135427L, 4410972L, 5810L, 8L, 46603718L, 422L, 1083626L, 48L, 
15699890L, 7L, 90167635L, 446459879L, 2332071L, 761660L, 49218442L, 
381L, 46L, 493197L, 46L, 798597155L, 45342274L, 6265842L, 6L, 
3445819L, 351L, 1761227L, 214L, 959L, 908996387L, 6L, 3855L, 
9096604L, 152664L, 7970052L, 32366926L, 31L, 5201618L, 114L, 
7806411L, 70L, 239L, 5065L, 2L, 1L, 14472831L, 122042249L, 8L, 
495604L, 29L, 8965478L, 2875L, 959L, 39L, 9L, 690L, 933626665L, 
85294L, 580093L, 95934L, 982058L, 65244056L, 137508L, 29L, 7621L, 
7527L, 72L, 2L, 315L, 6L, 2413L, 8625150L, 51298109L, 851L, 890460L, 
160736L, 6L, 850842734L, 2L, 7L, 76969113L, 190536L), Peak.Time = c(1465265L, 
452894L, 545076172L, 8226275L, 5040875L, 700530L, 1L, 3639L, 
20141L, 71712131L, 686L, 923L, 770569738L, 69961L, 737458636L, 
122403L, 199502046L, 6108L, 907L, 108078263L, 7817L, 4L, 6L, 
69L, 721L, 786353L, 87486L, 1563L, 876L, 47599535L, 79295722L, 
53L, 7378L, 591L, 6607935L, 954L, 6295L, 75514344L, 5742050L, 
25647276L, 449L, 328566184L, 4L, 2L, 2703L, 21367543L, 63429043L, 
708L, 782L, 909820L, 478L, 50L, 922L, 579882L, 7850L, 534L, 2157492L, 
96L, 6L, 716L, 5L, 653290336L, 447854237L, 2L, 31972263L, 645L, 
7L, 609909L, 4054695L, 455631L, 4919894L, 9L, 72713L, 9997L, 
84090765L, 89742L, 5L, 5028L, 4126L, 23091L, 81L, 239635020L, 
3576L, 898597785L, 6822L, 3798L, 201999L, 19624L, 20432923L, 
18944093L, 930720236L, 1492302L, 300122L, 143633L, 5152743L, 
417344L, 813L, 55792L, 78L), Center_Freq = c(61907L, 8709547L, 
300750537L, 45862L, 91417085L, 79892L, 47765L, 5477L, 18L, 4186L, 
2860L, 754038591L, 375L, 53809223L, 72L, 136L, 4700783L, 4173830L, 
30L, 811L, 341014L, 780L, 44749L, 91L, 201620707L, 74L, 1L, 65422L, 
595L, 89093186L, 946520L, 6940919L, 48744L, 2317845L, 5126197L, 
2445L, 8L, 557450L, 450259742L, 21006647L, 9L, 7234027L, 59L, 
9L, 651547554L, 45554L, 38493L, 91055218L, 38L, 1116474L, 2295482L, 
3001L, 9L, 3270L, 141L, 53644L, 667983L, 565598L, 84L, 971L, 
555498297L, 60431L, 6597L, 856943893L, 607815536L, 4406L, 79L, 
4885076L, 745L, 8L, 56456L, 125140L, 73043989L, 516476L, 7L, 
4440739L, 754038591L, 375L, 53809223L, 72L, 136L, 509L, 232325L, 
13128104L, 1692L, 8581L, 23L, 5874213L, 4550L, 644668065L, 3712371L, 
5928L, 8833L, 7L, 2186023L, 61627221L, 37297L, 716427989L, 21387L
), Start.Freq = c(426355L, 22073538L, 680374L, 41771L, 54L, 6762844L, 
599171L, 108L, 257451851L, 438814L, 343045L, 4702L, 967787L, 
1937L, 18L, 89301735L, 366L, 90L, 954L, 7337732L, 70891703L, 
4139L, 10397931L, 940000382L, 7L, 38376L, 878528819L, 6287L, 
738366L, 31L, 47L, 5L, 6L, 77848L, 2366508L, 45L, 3665842L, 7252260L, 
6L, 61L, 3247L, 448348L, 1L, 705132L, 144L, 7423637L, 2L, 497L, 
844927639L, 78978L, 914L, 131L, 7089563L, 927L, 9595581L, 2774463L, 
1651L, 73509280L, 7L, 35L, 18L, 96L, 1L, 92545512L, 27354947L, 
7556L, 65019L, 7480L, 71835L, 8249L, 64792L, 71537L, 349389666L, 
280244484L, 82L, 6L, 40L, 353872L, 0L, 103L, 1255L, 4752L, 29L, 
76L, 81185L, 14L, 9L, 470775630L, 818361265L, 57947209L, 44L, 
24L, 41295L, 4L, 261449L, 9931404L, 773556640L, 930717L, 65007421L
), End.Freq = c(71000996L, 11613579L, 71377155L, 1942738L, 8760748L, 
79L, 455L, 374L, 8L, 5L, 2266932L, 597833L, 155488L, 3020L, 4L, 
554L, 4L, 16472L, 1945649L, 668181101L, 649780L, 22394365L, 93060602L, 
172146L, 20472L, 23558847L, 190513L, 22759044L, 44L, 78450L, 
205621181L, 218L, 69916344L, 23884L, 66L, 312148L, 7710564L, 
4L, 422L, 744572L, 651547554L, 45554L, 38493L, 91055218L, 38L, 
1116474L, 2295482L, 3001L, 9L, 3270L, 141L, 55595L, 38451L, 8660867L, 
14L, 96L, 345L, 6L, 44L, 8235824L, 910517L, 1424326L, 87102566L, 
53644L, 667983L, 565598L, 84L, 971L, 555498297L, 60431L, 6597L, 
856943893L, 607815536L, 4406L, 79L, 7L, 28978746L, 7537295L, 
6L, 633L, 345860066L, 802L, 1035131L, 602L, 2740L, 8065L, 61370968L, 
429953765L, 981507L, 8105L, 343787257L, 44782L, 64184L, 12981359L, 
123367978L, 818775L, 123745614L, 25345654L, 3L), Country = c("Holland", 
"Holland", "Holland", "Holland", "Holland", "Holland", "Spain", 
"Spain", "Spain", "Spain", "Spain", "Spain", "Spain", "Spain", 
"Spain", "Spain", "Spain", "Spain", "Holland", "Holland", "Holland", 
"Holland", "Holland", "Holland", "France", "France", "France", 
"France", "France", "France", "France", "France", "France", "France", 
"France", "Spain", "Spain", "Spain", "Spain", "Spain", "Spain", 
"Spain", "Spain", "France", "France", "France", "France", "Holland", 
"Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
"Holland", "Holland", "Holland", "Holland", "Holland", "Holland", 
"Spain", "Spain", "Spain", "Spain", "Spain", "Spain", "Spain", 
"Holland", "Holland", "Holland", "Holland", "France", "France", 
"France", "France", "France", "France", "France", "Spain", "Spain", 
"Spain", "Spain", "Spain", "Spain", "Spain", "Spain", "Spain", 
"Spain", "Spain", "Spain", "Spain", "Spain", "Spain", "Spain", 
"Spain", "Spain", "France", "France", "France")), row.names = c(NA, 
99L), class = "data.frame")

uj5u.com熱心網友回復:

您可以為每個觀察選擇具有最高預測概率的國家:

pred_model_Tree1 = predict(gbmFit1, newdata = test.data, type = "prob")

pred_model_Tree1$evaluation <- names(pred_model_Tree1)[apply(pred_model_Tree1, 1, which.max)]

table(pred_model_Tree1$evaluation)

這使:

 France Holland   Spain 
      1      11      16 

然后該confusionMatrix()函式使用給定的代碼。

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/485416.html

標籤:r if 语句 机器学习 分类 混淆矩阵

上一篇:CodeIgniter4:自定義助手給出“呼叫未定義函式”錯誤

下一篇:從保存的模型機器學習中檢索指標

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • IEEE1588PTP在數字化變電站時鐘同步方面的應用

    IEEE1588ptp在數字化變電站時鐘同步方面的應用 京準電子科技官微——ahjzsz 一、電力系統時間同步基本概況 隨著對IEC 61850標準研究的不斷深入,國內外學者提出基于IEC61850通信標準體系建設數字化變電站的發展思路。數字化變電站與常規變電站的顯著區別在于程序層傳統的電流/電壓互 ......

    uj5u.com 2020-09-10 03:51:52 more
  • HTTP request smuggling CL.TE

    CL.TE 簡介 前端通過Content-Length處理請求,通過反向代理或者負載均衡將請求轉發到后端,后端Transfer-Encoding優先級較高,以TE處理請求造成安全問題。 檢測 發送如下資料包 POST / HTTP/1.1 Host: ac391f7e1e9af821806e890 ......

    uj5u.com 2020-09-10 03:52:11 more
  • 網路滲透資料大全單——漏洞庫篇

    網路滲透資料大全單——漏洞庫篇漏洞庫 NVD ——美國國家漏洞庫 →http://nvd.nist.gov/。 CERT ——美國國家應急回應中心 →https://www.us-cert.gov/ OSVDB ——開源漏洞庫 →http://osvdb.org Bugtraq ——賽門鐵克 →ht ......

    uj5u.com 2020-09-10 03:52:15 more
  • 京準講述NTP時鐘服務器應用及原理

    京準講述NTP時鐘服務器應用及原理京準講述NTP時鐘服務器應用及原理 安徽京準電子科技官微——ahjzsz 北斗授時原理 授時是指接識訓通過某種方式獲得本地時間與北斗標準時間的鐘差,然后調整本地時鐘使時差控制在一定的精度范圍內。 衛星導航系統通常由三部分組成:導航授時衛星、地面檢測校正維護系統和用戶 ......

    uj5u.com 2020-09-10 03:52:25 more
  • 利用北斗衛星系統設計NTP網路時間服務器

    利用北斗衛星系統設計NTP網路時間服務器 利用北斗衛星系統設計NTP網路時間服務器 安徽京準電子科技官微——ahjzsz 概述 NTP網路時間服務器是一款支持NTP和SNTP網路時間同步協議,高精度、大容量、高品質的高科技時鐘產品。 NTP網路時間服務器設備采用冗余架構設計,高精度時鐘直接來源于北斗 ......

    uj5u.com 2020-09-10 03:52:35 more
  • 詳細解讀電力系統各種對時方式

    詳細解讀電力系統各種對時方式 詳細解讀電力系統各種對時方式 安徽京準電子科技官微——ahjzsz,更多資料請添加VX 衛星同步時鐘是我京準公司開發研制的應用衛星授時時技術的標準時間顯示和發送的裝置,該裝置以M國全球定位系統(GLOBAL POSITIONING SYSTEM,縮寫為GPS)或者我國北 ......

    uj5u.com 2020-09-10 03:52:45 more
  • 如何保證外包團隊接入企業內網安全

    不管企業規模的大小,只要企業想省錢,那么企業的某些服務就一定會采用外包的形式,然而看似美好又經濟的策略,其實也有不好的一面。下面我通過安全的角度來聊聊使用外包團的安全隱患問題。 先看看什么服務會使用外包的,最常見的就是話務/客服這種需要大量重復性、無技術性的服務,或者是一些銷售外包、特殊的職能外包等 ......

    uj5u.com 2020-09-10 03:52:57 more
  • PHP漏洞之【整型數字型SQL注入】

    0x01 什么是SQL注入 SQL是一種注入攻擊,通過前端帶入后端資料庫進行惡意的SQL陳述句查詢。 0x02 SQL整型注入原理 SQL注入一般發生在動態網站URL地址里,當然也會發生在其它地發,如登錄框等等也會存在注入,只要是和資料庫打交道的地方都有可能存在。 如這里http://192.168. ......

    uj5u.com 2020-09-10 03:55:40 more
  • [GXYCTF2019]禁止套娃

    git泄露獲取原始碼 使用GET傳參,引數為exp 經過三層過濾執行 第一層過濾偽協議,第二層過濾帶引數的函式,第三層過濾一些函式 preg_replace('/[a-z,_]+\((?R)?\)/', NULL, $_GET['exp'] (?R)參考當前正則運算式,相當于匹配函式里的引數 因此傳遞 ......

    uj5u.com 2020-09-10 03:56:07 more
  • 等保2.0實施流程

    流程 結論 ......

    uj5u.com 2020-09-10 03:56:16 more
最新发布
  • 使用Django Rest framework搭建Blog

    在前面的Blog例子中我們使用的是GraphQL, 雖然GraphQL的使用處于上升趨勢,但是Rest API還是使用的更廣泛一些. 所以還是決定回到傳統的rest api framework上來, Django rest framework的官網上給了一個很好用的QuickStart, 我參考Qu ......

    uj5u.com 2023-04-20 08:17:54 more
  • 記錄-new Date() 我忍你很久了!

    這里給大家分享我在網上總結出來的一些知識,希望對大家有所幫助 大家平時在開發的時候有沒被new Date()折磨過?就是它的諸多怪異的設定讓你每每用的時候,都可能不小心踩坑。造成程式意外出錯,卻一下子找不到問題出處,那叫一個煩透了…… 下面,我就列舉它的“四宗罪”及應用思考 可惡的四宗罪 1. Sa ......

    uj5u.com 2023-04-20 08:17:47 more
  • 使用Vue.js實作文字跑馬燈效果

    實作文字跑馬燈效果,首先用到 substring()截取 和 setInterval計時器 clearInterval()清除計時器 效果如下: 實作代碼如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta ......

    uj5u.com 2023-04-20 08:12:31 more
  • JavaScript 運算子

    JavaScript 運算子/運算子 在 JavaScript 中,有一些運算子可以使代碼更簡潔、易讀和高效。以下是一些常見的運算子: 1、可選鏈運算子(optional chaining operator) ?.是可選鏈運算子(optional chaining operator)。?. 可選鏈操 ......

    uj5u.com 2023-04-20 08:02:25 more
  • CSS—相對單位rem

    一、概述 rem是一個相對長度單位,它的單位長度取決于根標簽html的字體尺寸。rem即root em的意思,中文翻譯為根em。瀏覽器的文本尺寸一般默認為16px,即默認情況下: 1rem = 16px rem布局原理:根據CSS媒體查詢功能,更改根標簽的字體尺寸,實作rem單位隨螢屏尺寸的變化,如 ......

    uj5u.com 2023-04-20 08:02:21 more
  • 我的第一個NPM包:panghu-planebattle-esm(胖虎飛機大戰)使用說明

    好家伙,我的包終于開發完啦 歡迎使用胖虎的飛機大戰包!! 為你的主頁添加色彩 這是一個有趣的網頁小游戲包,使用canvas和js開發 使用ES6模塊化開發 效果圖如下: (覺得圖片太sb的可以自己改) 代碼已開源!! Git: https://gitee.com/tang-and-han-dynas ......

    uj5u.com 2023-04-20 08:01:50 more
  • 如何在 vue3 中使用 jsx/tsx?

    我們都知道,通常情況下我們使用 vue 大多都是用的 SFC(Signle File Component)單檔案組件模式,即一個組件就是一個檔案,但其實 Vue 也是支持使用 JSX 來撰寫組件的。這里不討論 SFC 和 JSX 的好壞,這個仁者見仁智者見智。本篇文章旨在帶領大家快速了解和使用 Vu ......

    uj5u.com 2023-04-20 08:01:37 more
  • 【Vue2.x原始碼系列06】計算屬性computed原理

    本章目標:計算屬性是如何實作的?計算屬性快取原理以及洋蔥模型的應用?在初始化Vue實體時,我們會給每個計算屬性都創建一個對應watcher,我們稱之為計算屬性watcher ......

    uj5u.com 2023-04-20 08:01:31 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:01:10 more
  • http1.1與http2.0

    一、http是什么 通俗來講,http就是計算機通過網路進行通信的規則,是一個基于請求與回應,無狀態的,應用層協議。常用于TCP/IP協議傳輸資料。目前任何終端之間任何一種通信方式都必須按Http協議進行,否則無法連接。tcp(三次握手,四次揮手)。 請求與回應:客戶端請求、服務端回應資料。 無狀態 ......

    uj5u.com 2023-04-20 08:00:32 more