第100+13步 ChatGPT學習:R實現決策樹分類

基于R 4.2.2版本演示

一、寫在前面

有不少大佬問做機器學習分類能不能用R語言,不想學Python咯。

答曰:可!用GPT或者Kimi轉一下就得了唄。

加上最近也沒啥內容寫了,就幫各位搬運一下吧。

二、R代碼實現決策樹分類

(1)導入數據

我習慣用RStudio自帶的導入功能:

(2)建立決策樹模型(默認參數)

# Load necessary libraries
library(caret)
library(pROC)
library(ggplot2)# Assume 'data' is your dataframe containing the data
# Set seed to ensure reproducibility
set.seed(123)# Split data into training and validation sets (80% training, 20% validation)
trainIndex <- createDataPartition(data$X, p = 0.8, list = FALSE)
trainData <- data[trainIndex, ]
validData <- data[-trainIndex, ]# Convert the target variable to a factor for classification
trainData$X <- as.factor(trainData$X)
validData$X <- as.factor(validData$X)# Define control method for training with cross-validation
trainControl <- trainControl(method = "cv", number = 10)
# Fit Decision Tree model on the training set
model <- train(X ~ ., data = trainData, method = "rpart", trControl = trainControl)# Print the best parameters found by the model
best_params <- model$bestTune
cat("The best parameters found are:\n")
print(best_params)# Predict on the training and validation sets
trainPredict <- predict(model, trainData, type = "prob")[,2]
validPredict <- predict(model, validData, type = "prob")[,2]# Convert true values to factor for ROC analysis
trainData$X <- as.factor(trainData$X)
validData$X <- as.factor(validData$X)# Calculate ROC curves and AUC values
trainRoc <- roc(response = trainData$X, predictor = trainPredict)
validRoc <- roc(response = validData$X, predictor = validPredict)# Plot ROC curves with AUC values
ggplot(data = data.frame(fpr = trainRoc$specificities, tpr = trainRoc$sensitivities), aes(x = 1 - fpr, y = tpr)) +geom_line(color = "blue") +geom_area(alpha = 0.2, fill = "blue") +geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") +ggtitle("Training ROC Curve") +xlab("False Positive Rate") +ylab("True Positive Rate") +annotate("text", x = 0.5, y = 0.1, label = paste("Training AUC =", round(auc(trainRoc), 2)), hjust = 0.5, color = "blue")ggplot(data = data.frame(fpr = validRoc$specificities, tpr = validRoc$sensitivities), aes(x = 1 - fpr, y = tpr)) +geom_line(color = "red") +geom_area(alpha = 0.2, fill = "red") +geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") +ggtitle("Validation ROC Curve") +xlab("False Positive Rate") +ylab("True Positive Rate") +annotate("text", x = 0.5, y = 0.2, label = paste("Validation AUC =", round(auc(validRoc), 2)), hjust = 0.5, color = "red")# Calculate confusion matrices based on 0.5 cutoff for probability
confMatTrain <- table(trainData$X, trainPredict >= 0.5)
confMatValid <- table(validData$X, validPredict >= 0.5)# Function to plot confusion matrix using ggplot2
plot_confusion_matrix <- function(conf_mat, dataset_name) {conf_mat_df <- as.data.frame(as.table(conf_mat))colnames(conf_mat_df) <- c("Actual", "Predicted", "Freq")p <- ggplot(data = conf_mat_df, aes(x = Predicted, y = Actual, fill = Freq)) +geom_tile(color = "white") +geom_text(aes(label = Freq), vjust = 1.5, color = "black", size = 5) +scale_fill_gradient(low = "white", high = "steelblue") +labs(title = paste("Confusion Matrix -", dataset_name, "Set"), x = "Predicted Class", y = "Actual Class") +theme_minimal() +theme(axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(hjust = 0.5))print(p)
}
# Now call the function to plot and display the confusion matrices
plot_confusion_matrix(confMatTrain, "Training")
plot_confusion_matrix(confMatValid, "Validation")# Extract values for calculations
a_train <- confMatTrain[1, 1]
b_train <- confMatTrain[1, 2]
c_train <- confMatTrain[2, 1]
d_train <- confMatTrain[2, 2]a_valid <- confMatValid[1, 1]
b_valid <- confMatValid[1, 2]
c_valid <- confMatValid[2, 1]
d_valid <- confMatValid[2, 2]# Training Set Metrics
acc_train <- (a_train + d_train) / sum(confMatTrain)
error_rate_train <- 1 - acc_train
sen_train <- d_train / (d_train + c_train)
sep_train <- a_train / (a_train + b_train)
precision_train <- d_train / (b_train + d_train)
F1_train <- (2 * precision_train * sen_train) / (precision_train + sen_train)
MCC_train <- (d_train * a_train - b_train * c_train) / sqrt((d_train + b_train) * (d_train + c_train) * (a_train + b_train) * (a_train + c_train))
auc_train <- roc(response = trainData$X, predictor = trainPredict)$auc# Validation Set Metrics
acc_valid <- (a_valid + d_valid) / sum(confMatValid)
error_rate_valid <- 1 - acc_valid
sen_valid <- d_valid / (d_valid + c_valid)
sep_valid <- a_valid / (a_valid + b_valid)
precision_valid <- d_valid / (b_valid + d_valid)
F1_valid <- (2 * precision_valid * sen_valid) / (precision_valid + sen_valid)
MCC_valid <- (d_valid * a_valid - b_valid * c_valid) / sqrt((d_valid + b_valid) * (d_valid + c_valid) * (a_valid + b_valid) * (a_valid + c_valid))
auc_valid <- roc(response = validData$X, predictor = validPredict)$auc# Print Metrics
cat("Training Metrics\n")
cat("Accuracy:", acc_train, "\n")
cat("Error Rate:", error_rate_train, "\n")
cat("Sensitivity:", sen_train, "\n")
cat("Specificity:", sep_train, "\n")
cat("Precision:", precision_train, "\n")
cat("F1 Score:", F1_train, "\n")
cat("MCC:", MCC_train, "\n")
cat("AUC:", auc_train, "\n\n")cat("Validation Metrics\n")
cat("Accuracy:", acc_valid, "\n")
cat("Error Rate:", error_rate_valid, "\n")
cat("Sensitivity:", sen_valid, "\n")
cat("Specificity:", sep_valid, "\n")
cat("Precision:", precision_valid, "\n")
cat("F1 Score:", F1_valid, "\n")
cat("MCC:", MCC_valid, "\n")
cat("AUC:", auc_valid, "\n")

在R語言中,還是使用caret包來訓練決策樹模型,可以調整多種參數來優化模型的性能:

①cp (Complexity Parameter): 用來控制樹的生長。cp 值越大,生成的模型越簡單。如果 cp 設置得太高,可能導致模型欠擬合。

②maxdepth:?決定了樹的最大深度。較深的樹可以更好地捕捉數據中的復雜關系,但也可能導致過擬合。

③minsplit:?定義了節點在嘗試分裂之前所需的最小樣本數。增加這個值可以讓樹更加穩健,但也可能導致欠擬合。

④minbucket: 葉節點最少包含的樣本數。這個參數可以幫助防止模型過于復雜,從而避免過擬合。

結果輸出(默認參數):

在默認參數中,caret包只會默默幫我們找幾個合適的cp值進行測試。其他三個參數就一個默認值。

三、決策樹調參方法(僅cp值)

如前所述,決策樹的關鍵參數就是有4個,但是caret包做網格搜索的話,只能提供對于cp值的遍歷,其余三個不提供。

比如我設置cp值從0.001到0.1,步長是0.001;而maxdepth = 20, minsplit = 10, minbucket = 10:

# Load necessary libraries
library(caret)
library(pROC)
library(ggplot2)
library(rpart)# Assume 'data' is your dataframe containing the data
# Set seed to ensure reproducibility
set.seed(123)# Split data into training and validation sets (80% training, 20% validation)
trainIndex <- createDataPartition(data$X, p = 0.8, list = FALSE)
trainData <- data[trainIndex, ]
validData <- data[-trainIndex, ]# Convert the target variable to a factor for classification
trainData$X <- as.factor(trainData$X)
validData$X <- as.factor(validData$X)# 定義交叉驗證控制方法
trainControl <- trainControl(method = "cv", number = 10)# 定義參數網格,只包括 cp
tuneGrid <- expand.grid(cp = seq(0.001, 0.1, by = 0.001))# 定義 rpart.control,固定其他參數
rpartControl <- rpart.control(maxdepth = 20, minsplit = 10, minbucket = 10)# 使用 rpart 方法訓練決策樹模型
model <- train(X ~ ., data = trainData, method = "rpart", trControl = trainControl, tuneGrid = tuneGrid,control = rpartControl)# 打印找到的最佳參數
best_params <- model$bestTune
cat("The best parameters found are:\n")
print(best_params)# Predict on the training and validation sets
trainPredict <- predict(model, trainData, type = "prob")[,2]
validPredict <- predict(model, validData, type = "prob")[,2]# Convert true values to factor for ROC analysis
trainData$X <- as.factor(trainData$X)
validData$X <- as.factor(validData$X)# Calculate ROC curves and AUC values
trainRoc <- roc(response = trainData$X, predictor = trainPredict)
validRoc <- roc(response = validData$X, predictor = validPredict)# Plot ROC curves with AUC values
ggplot(data = data.frame(fpr = trainRoc$specificities, tpr = trainRoc$sensitivities), aes(x = 1 - fpr, y = tpr)) +geom_line(color = "blue") +geom_area(alpha = 0.2, fill = "blue") +geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") +ggtitle("Training ROC Curve") +xlab("False Positive Rate") +ylab("True Positive Rate") +annotate("text", x = 0.5, y = 0.1, label = paste("Training AUC =", round(auc(trainRoc), 2)), hjust = 0.5, color = "blue")ggplot(data = data.frame(fpr = validRoc$specificities, tpr = validRoc$sensitivities), aes(x = 1 - fpr, y = tpr)) +geom_line(color = "red") +geom_area(alpha = 0.2, fill = "red") +geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") +ggtitle("Validation ROC Curve") +xlab("False Positive Rate") +ylab("True Positive Rate") +annotate("text", x = 0.5, y = 0.2, label = paste("Validation AUC =", round(auc(validRoc), 2)), hjust = 0.5, color = "red")# Calculate confusion matrices based on 0.5 cutoff for probability
confMatTrain <- table(trainData$X, trainPredict >= 0.5)
confMatValid <- table(validData$X, validPredict >= 0.5)# Function to plot confusion matrix using ggplot2
plot_confusion_matrix <- function(conf_mat, dataset_name) {conf_mat_df <- as.data.frame(as.table(conf_mat))colnames(conf_mat_df) <- c("Actual", "Predicted", "Freq")p <- ggplot(data = conf_mat_df, aes(x = Predicted, y = Actual, fill = Freq)) +geom_tile(color = "white") +geom_text(aes(label = Freq), vjust = 1.5, color = "black", size = 5) +scale_fill_gradient(low = "white", high = "steelblue") +labs(title = paste("Confusion Matrix -", dataset_name, "Set"), x = "Predicted Class", y = "Actual Class") +theme_minimal() +theme(axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(hjust = 0.5))print(p)
}
# Now call the function to plot and display the confusion matrices
plot_confusion_matrix(confMatTrain, "Training")
plot_confusion_matrix(confMatValid, "Validation")# Extract values for calculations
a_train <- confMatTrain[1, 1]
b_train <- confMatTrain[1, 2]
c_train <- confMatTrain[2, 1]
d_train <- confMatTrain[2, 2]a_valid <- confMatValid[1, 1]
b_valid <- confMatValid[1, 2]
c_valid <- confMatValid[2, 1]
d_valid <- confMatValid[2, 2]# Training Set Metrics
acc_train <- (a_train + d_train) / sum(confMatTrain)
error_rate_train <- 1 - acc_train
sen_train <- d_train / (d_train + c_train)
sep_train <- a_train / (a_train + b_train)
precision_train <- d_train / (b_train + d_train)
F1_train <- (2 * precision_train * sen_train) / (precision_train + sen_train)
MCC_train <- (d_train * a_train - b_train * c_train) / sqrt((d_train + b_train) * (d_train + c_train) * (a_train + b_train) * (a_train + c_train))
auc_train <- roc(response = trainData$X, predictor = trainPredict)$auc# Validation Set Metrics
acc_valid <- (a_valid + d_valid) / sum(confMatValid)
error_rate_valid <- 1 - acc_valid
sen_valid <- d_valid / (d_valid + c_valid)
sep_valid <- a_valid / (a_valid + b_valid)
precision_valid <- d_valid / (b_valid + d_valid)
F1_valid <- (2 * precision_valid * sen_valid) / (precision_valid + sen_valid)
MCC_valid <- (d_valid * a_valid - b_valid * c_valid) / sqrt((d_valid + b_valid) * (d_valid + c_valid) * (a_valid + b_valid) * (a_valid + c_valid))
auc_valid <- roc(response = validData$X, predictor = validPredict)$auc# Print Metrics
cat("Training Metrics\n")
cat("Accuracy:", acc_train, "\n")
cat("Error Rate:", error_rate_train, "\n")
cat("Sensitivity:", sen_train, "\n")
cat("Specificity:", sep_train, "\n")
cat("Precision:", precision_train, "\n")
cat("F1 Score:", F1_train, "\n")
cat("MCC:", MCC_train, "\n")
cat("AUC:", auc_train, "\n\n")cat("Validation Metrics\n")
cat("Accuracy:", acc_valid, "\n")
cat("Error Rate:", error_rate_valid, "\n")
cat("Sensitivity:", sen_valid, "\n")
cat("Specificity:", sep_valid, "\n")
cat("Precision:", precision_valid, "\n")
cat("F1 Score:", F1_valid, "\n")
cat("MCC:", MCC_valid, "\n")
cat("AUC:", auc_valid, "\n")

結果輸出:

似乎好了一點了,那么,如果我先把其余三個參數也納入遍歷呢?那只能用循環語句了。

四、決策樹調參方法(4個值)

設置cp值從0.001到0.1,步長是0.001;maxdepth從10到30,步長是5;minsplit取值10、20、30、40;minbucket取值5、10、15、20:

# Load necessary libraries
library(caret)
library(pROC)
library(ggplot2)
library(rpart)# Assume 'data' is your dataframe containing the data
# Set seed to ensure reproducibility
set.seed(123)# Split data into training and validation sets (80% training, 20% validation)
trainIndex <- createDataPartition(data$X, p = 0.8, list = FALSE)
trainData <- data[trainIndex, ]
validData <- data[-trainIndex, ]# Convert the target variable to a factor for classification
trainData$X <- as.factor(trainData$X)
validData$X <- as.factor(validData$X)# 參數網格定義
cp_values <- seq(0.001, 0.01, by = 0.001)
maxdepth_values <- seq(10, 30, by = 5)
minsplit_values <- c(10, 20, 30, 40)
minbucket_values <- c(5, 10, 15, 20)# 用于存儲結果的列表
results <- list()# 網格搜索實現
for (cp in cp_values) {for (maxdepth in maxdepth_values) {for (minsplit in minsplit_values) {for (minbucket in minbucket_values) {# 訓練模型model <- rpart(X ~ ., data = trainData, control = rpart.control(cp = cp, maxdepth = maxdepth,minsplit = minsplit, minbucket = minbucket))# 預測驗證集predictions <- predict(model, validData, type = "class")# 計算性能指標,這里使用準確度accuracy <- sum(predictions == validData$X) / nrow(validData)# 存儲結果results[[length(results) + 1]] <- list(cp = cp, maxdepth = maxdepth, minsplit = minsplit, minbucket = minbucket,accuracy = accuracy)}}}
}# 找到最高準確度的模型參數
best_model <- results[[which.max(sapply(results, function(x) x$accuracy))]]
print(best_model)# Predict on the training and validation sets
trainPredict <- predict(model, trainData, type = "prob")[,2]
validPredict <- predict(model, validData, type = "prob")[,2]# Convert true values to factor for ROC analysis
trainData$X <- as.factor(trainData$X)
validData$X <- as.factor(validData$X)# Calculate ROC curves and AUC values
trainRoc <- roc(response = trainData$X, predictor = trainPredict)
validRoc <- roc(response = validData$X, predictor = validPredict)# Plot ROC curves with AUC values
ggplot(data = data.frame(fpr = trainRoc$specificities, tpr = trainRoc$sensitivities), aes(x = 1 - fpr, y = tpr)) +geom_line(color = "blue") +geom_area(alpha = 0.2, fill = "blue") +geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") +ggtitle("Training ROC Curve") +xlab("False Positive Rate") +ylab("True Positive Rate") +annotate("text", x = 0.5, y = 0.1, label = paste("Training AUC =", round(auc(trainRoc), 2)), hjust = 0.5, color = "blue")ggplot(data = data.frame(fpr = validRoc$specificities, tpr = validRoc$sensitivities), aes(x = 1 - fpr, y = tpr)) +geom_line(color = "red") +geom_area(alpha = 0.2, fill = "red") +geom_abline(slope = 1, intercept = 0, linetype = "dashed", color = "black") +ggtitle("Validation ROC Curve") +xlab("False Positive Rate") +ylab("True Positive Rate") +annotate("text", x = 0.5, y = 0.2, label = paste("Validation AUC =", round(auc(validRoc), 2)), hjust = 0.5, color = "red")# Calculate confusion matrices based on 0.5 cutoff for probability
confMatTrain <- table(trainData$X, trainPredict >= 0.5)
confMatValid <- table(validData$X, validPredict >= 0.5)# Function to plot confusion matrix using ggplot2
plot_confusion_matrix <- function(conf_mat, dataset_name) {conf_mat_df <- as.data.frame(as.table(conf_mat))colnames(conf_mat_df) <- c("Actual", "Predicted", "Freq")p <- ggplot(data = conf_mat_df, aes(x = Predicted, y = Actual, fill = Freq)) +geom_tile(color = "white") +geom_text(aes(label = Freq), vjust = 1.5, color = "black", size = 5) +scale_fill_gradient(low = "white", high = "steelblue") +labs(title = paste("Confusion Matrix -", dataset_name, "Set"), x = "Predicted Class", y = "Actual Class") +theme_minimal() +theme(axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(hjust = 0.5))print(p)
}
# Now call the function to plot and display the confusion matrices
plot_confusion_matrix(confMatTrain, "Training")
plot_confusion_matrix(confMatValid, "Validation")# Extract values for calculations
a_train <- confMatTrain[1, 1]
b_train <- confMatTrain[1, 2]
c_train <- confMatTrain[2, 1]
d_train <- confMatTrain[2, 2]a_valid <- confMatValid[1, 1]
b_valid <- confMatValid[1, 2]
c_valid <- confMatValid[2, 1]
d_valid <- confMatValid[2, 2]# Training Set Metrics
acc_train <- (a_train + d_train) / sum(confMatTrain)
error_rate_train <- 1 - acc_train
sen_train <- d_train / (d_train + c_train)
sep_train <- a_train / (a_train + b_train)
precision_train <- d_train / (b_train + d_train)
F1_train <- (2 * precision_train * sen_train) / (precision_train + sen_train)
MCC_train <- (d_train * a_train - b_train * c_train) / sqrt((d_train + b_train) * (d_train + c_train) * (a_train + b_train) * (a_train + c_train))
auc_train <- roc(response = trainData$X, predictor = trainPredict)$auc# Validation Set Metrics
acc_valid <- (a_valid + d_valid) / sum(confMatValid)
error_rate_valid <- 1 - acc_valid
sen_valid <- d_valid / (d_valid + c_valid)
sep_valid <- a_valid / (a_valid + b_valid)
precision_valid <- d_valid / (b_valid + d_valid)
F1_valid <- (2 * precision_valid * sen_valid) / (precision_valid + sen_valid)
MCC_valid <- (d_valid * a_valid - b_valid * c_valid) / sqrt((d_valid + b_valid) * (d_valid + c_valid) * (a_valid + b_valid) * (a_valid + c_valid))
auc_valid <- roc(response = validData$X, predictor = validPredict)$auc# Print Metrics
cat("Training Metrics\n")
cat("Accuracy:", acc_train, "\n")
cat("Error Rate:", error_rate_train, "\n")
cat("Sensitivity:", sen_train, "\n")
cat("Specificity:", sep_train, "\n")
cat("Precision:", precision_train, "\n")
cat("F1 Score:", F1_train, "\n")
cat("MCC:", MCC_train, "\n")
cat("AUC:", auc_train, "\n\n")cat("Validation Metrics\n")
cat("Accuracy:", acc_valid, "\n")
cat("Error Rate:", error_rate_valid, "\n")
cat("Sensitivity:", sen_valid, "\n")
cat("Specificity:", sep_valid, "\n")
cat("Precision:", precision_valid, "\n")
cat("F1 Score:", F1_valid, "\n")
cat("MCC:", MCC_valid, "\n")
cat("AUC:", auc_valid, "\n")

結果輸出:

以上是找到的相對最優參數組合,看看具體性能:

哈哈,又給調回去了,矯枉過正。思路就是這么個思路,大家自行食用了。

五、最后

看到這里,我覺得還是Python的sk-learn提供的調參簡單些,至少不用寫循環。

數據嘛:

鏈接:https://pan.baidu.com/s/1rEf6JZyzA1ia5exoq5OF7g?pwd=x8xm

提取碼:x8xm

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/37392.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/37392.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/37392.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【漏洞復現】宏景HCM人力資源信息管理系統——任意文件讀取漏洞

聲明&#xff1a;本文檔或演示材料僅供教育和教學目的使用&#xff0c;任何個人或組織使用本文檔中的信息進行非法活動&#xff0c;均與本文檔的作者或發布者無關。 文章目錄 漏洞描述漏洞復現測試工具 漏洞描述 宏景HCM人力資源信息管理系統是一款全面覆蓋人力資源管理各模塊…

docker pull 鏡像的時候遇到Pulling fs layer問題

最近遇到一個很奇怪的問題,docker pull 鏡像的時候,總是出現Pulling fs layer問題,導致鏡像拉取不成功,以前是安裝好docker,正常拉取鏡像都是沒什么問題的,在這里記錄一下這個問題的解決方法,當然,可能并不通用。 1、進入阿里云容器服務 地址:https://cr.console.aliy…

Spring Boot中的熱部署配置

Spring Boot中的熱部署配置 大家好&#xff0c;我是免費搭建查券返利機器人省錢賺傭金就用微賺淘客系統3.0的小編&#xff0c;也是冬天不穿秋褲&#xff0c;天冷也要風度的程序猿&#xff01;今天我們將探討如何在Spring Boot項目中實現熱部署配置&#xff0c;提升開發效率和項…

C++實現Qt的信號+槽功能

在 Visual Studio (VS) 上使用 C 實現類似 Qt 的信號和槽機制是完全可能的&#xff0c;但 Qt 的信號和槽系統是基于其特定的元對象系統&#xff08;Meta-Object System, MOC&#xff09;的&#xff0c;這需要一些特定的預處理器和代碼生成步驟。 如果你不想使用 Qt&#xff0c;…

vue路由傳參和react 路由傳參

路由跳轉的方式 1、聲明式導航 <router-link to"導航的地址"> 2、編程式導航 編程式導航有三種方法來進行導航 router.push router.replace router.go params傳參和query傳參 1、 params 傳參(不在URL中顯示參數) 在父路由跳轉到子路由時&#xff0c;也可…

【Django】網上蛋糕項目商城-熱銷和新品

概念 本文將完成實現項目的熱銷和新品兩個分類的商品列表進行分頁展示。 熱銷和新品功能實現步驟 在head.html頭部頁面中點擊這兩個超鏈接向服務器發送請求。 在urls.py文件中定義該請求地址 path(goodsrecommend_list/,views.goodsrecommend_list) 在views.py文件中定義g…

JDBC中的批處理是什么?如何使用?

JDBC中的批處理是指將多個關聯的SQL語句組合成一個批處理&#xff0c;并將它們作為一個調用提交給數據庫。這種方法可以減少通信的資源消耗&#xff0c;從而提高性能。以下是關于JDBC批處理的具體使用和步驟&#xff1a; 1. JDBC批處理的基本概念 批處理定義&#xff1a;將多…

英飛凌TC3xx之一起認識GTM(十五)GTM常見配置問題總結

英飛凌TC3xx之一起認識GTM(十五)GTM常見配置問題總結 1 關于TGC/AGC的配置注意事項2 關于HOST_TRIG的使用3 關于SOMC模式中MCS與ARU的合并使用配置4 深入理解SOMP模式中RST_CCU0的配置5 關于CCUx中斷的使用6 TIM如何捕獲ATOM的輸出7 總結前面幾篇關鍵文章信息鏈接匯總如下: …

AV Foundation學習筆記二 - 播放器

ASSets AVFoundation框架的最核心的類是AVAsset&#xff0c;該類是整個AVFoundation框架設計的中心。AVAsset是一個抽象的&#xff08;意味著你不能調用AVAsset的alloc或者new方法來創建一個AVAsset實例對象&#xff0c;而是通過該類的靜態方法來創建實例對象&#xff09;、不…

DevOps CMDB平臺整合Jira工單

背景 在DevOps CMDB平臺建設的過程中&#xff0c;我們可以很容易的將業務應用所涉及的云資源&#xff08;WAF、K8S、虛擬機等&#xff09;、CICD工具鏈&#xff08;Jenkins、ArgoCD&#xff09;、監控、日志等一次性的維護到CMDB平臺&#xff0c;但隨著時間的推移&#xff0c;…

Stirling PDF 部署 - 強大的PDF Web在線編輯工具箱

簡介 這是一個強大的、可本地托管的、基于 Web 的 PDF 操作工具&#xff0c;可使用 Docker部署。它使您能夠對 PDF 文件執行各種操作&#xff0c;包括拆分、合并、轉換、重組、添加圖像、旋轉、壓縮等。這個本地托管的 Web 應用程序已經發展到包含一套全面的功能&#xff0c;可…

PHP爬蟲類的并發與多線程處理技巧

PHP爬蟲類的并發與多線程處理技巧 引言&#xff1a; 隨著互聯網的快速發展&#xff0c;大量的數據信息存儲在各種網站上&#xff0c;獲取這些數據已經成為很多業務場景下的需求。而爬蟲作為一種自動化獲取網絡信息的工具&#xff0c;被廣泛應用于數據采集、搜索引擎、輿情分析…

關于組織赴俄羅斯(莫斯科)第 28 屆國際汽車零部件、汽車維修設備和商品展覽會商務考察的通知

關于組織赴俄羅斯&#xff08;莫斯科&#xff09; 第 28 屆國際汽車零部件、汽車維修設備和商品展覽會商務考察的通知 展會名稱&#xff1a;俄羅斯&#xff08;莫斯科&#xff09;第 28 屆國際汽車零部件、汽車零部件、汽車維修設備和商品展覽會 時間&#xff1a;2024 年 8 月…

Python | Leetcode Python題解之第204題計數質數

題目&#xff1a; 題解&#xff1a; MX5000000 is_prime [1] * MX is_prime[0]is_prime[1]0 for i in range(2, MX):if is_prime[i]:for j in range(i * i, MX, i):#循環每次增加iis_prime[j] 0 class Solution:def countPrimes(self, n: int) -> int:return sum(is_prim…

【MongoDB】分布式數據庫入門級學習

SueWakeup 個人主頁&#xff1a;SueWakeup 系列專欄&#xff1a;為祖國的科技進步添磚Java 個性簽名&#xff1a;保留赤子之心也許是種幸運吧 本文封面由 凱楠&#x1f4f8;友情提供 凱楠&#x1f4f8; - 不夜長安 目錄 MongoDB 相關 數據庫排行榜單 MongoDB 中文官網 菜鳥…

如何把mkv轉成mp4?介紹一下將mkv轉成MP4的幾種方法

如何把mkv轉成mp4&#xff1f;如果你有一個MKV格式的視頻文件&#xff0c;但是需要將其轉換為MP4格式以便更廣泛地在各種設備和平臺上播放和共享&#xff0c;你可以通過進行簡單的文件格式轉換來實現。轉換MKV到MP4格式可以提供更好的兼容性&#xff0c;并確保你的視頻文件能夠…

在預訓練語言模型主流架構

文章目錄 編碼器-解碼器架構因果解碼器架構前綴解碼器架構在預訓練語言模型時代,自然語言處理領域廣泛采用了預訓練 + 微調的范式,并誕生了以 BERT 為代表的編碼器(Encoder-only)架構、以 GPT 為代表的解碼器(Decoder-only)架構和以 T5 為代表的編碼器-解碼器(Encoder-d…

華為OD機試C卷(100分)-執行任務賺積分(c語言)

題目描述 現有N個任務需要處理&#xff0c;同一時間只能處理一個任務&#xff0c;處理每個任務所需要的時間固定為1。 每個任務都有最晚處理時間限制和積分值&#xff0c;在最晚處理時間點之前處理完成任務才可獲得對應的積分獎勵。 可用于處理任務的時間有限&#xff0c;請問…

AI學習指南機器學習篇-隨機森林超參數選擇與調優

AI學習指南機器學習篇-隨機森林超參數選擇與調優 隨機森林是一種強大的機器學習算法&#xff0c;它能夠處理復雜的數據集&#xff0c;并且對于大部分實際問題都表現出色。然而&#xff0c;要充分發揮隨機森林的性能&#xff0c;需要對其超參數進行合理選擇和調優。本文將介紹隨…

React:tabs或標簽頁自定義右擊菜單內容,支持內嵌iframe關閉菜單方案

React&#xff1a;tabs或標簽頁自定義右擊菜單內容&#xff0c;支持內嵌iframe關閉菜單方案 不管是react、vue還是原生js&#xff0c;原理是一樣的。 注意如果內嵌iframe情況下&#xff0c;iframe無法使用事件監聽&#xff0c;但是可以使用iframe的任何點擊行為都會往父級wind…