print("%s = %f" % (predictions_list[i][0], predictions_list[i][1]))
时间: 2023-12-12 15:03:37 浏览: 37
predictions_list 是一个包含预测结果的列表,每个元素都是一个包含两个值的元组。第一个值表示预测结果的名称,第二个值表示预测结果的数值。上述代码使用了字符串格式化来打印预测结果,将预测结果的名称和数值插入到格式化字符串中。
具体来说,"%s" 表示要插入一个字符串,"%f" 表示要插入一个浮点数。通过使用 "% (predictions_list[i][0], predictions_list[i][1])" 将预测结果的名称和数值传递给格式化字符串,然后使用 print 函数打印出来。
请注意,这个代码片段只是提供了一个打印预测结果的示例,并没有提供完整的上下文。如果您需要更多帮助,请提供更多相关的代码或详细说明。
相关问题
将这部分代码改为分步循环执行:for obj in tf.classify(net, img, roiL,min_scale=1, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5): print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect()) img.draw_rectangle(obj.rect()) predictions_list = list(zip(labels, obj.output())) for i in range(len(predictions_list)): print("%s = %f" % (predictions_list[i][0], predictions_list[i][1])) num1=ord(predictions_list[i][0])-48 if predictions_list[i][1]>0.7 and num1==num: uart.write('1') print('11') B0=1 C1=1 C0=0 roiR=(89,77,40,40) for obj in tf.classify(net, img, roiR,min_scale=1, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5): print("**********\nPredictions2 at [x=%d,y=%d,w=%d,h=%d]" % obj.rect()) img.draw_rectangle(obj.rect()) predictions_list2 = list(zip(labels, obj.output())) for p in range(len(predictions_list2)): print("%s = %f" % (predictions_list2[p][0], predictions_list2[p][1])) num2=ord(predictions_list2[p][0])-48 if predictions_list2[p][1]>0.7 and num2 == num: uart.write('2') print("22") B0=1 C1=1 C0=0
以下是将代码改为分步循环执行的示例:
```python
# 第一个循环
for obj in tf.classify(net, img, roiL, min_scale=1, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
print("**********\nPredictions at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
img.draw_rectangle(obj.rect())
predictions_list = list(zip(labels, obj.output()))
for i in range(len(predictions_list)):
print("%s = %f" % (predictions_list[i][0], predictions_list[i][1]))
num1 = ord(predictions_list[i][0]) - 48
if predictions_list[i][1] > 0.7 and num1 == num:
uart.write('1')
print('11')
B0 = 1
C1 = 1
C0 = 0
# 第二个循环
roiR = (89, 77, 40, 40)
for obj in tf.classify(net, img, roiR, min_scale=1, scale_mul=0.8, x_overlap=0.5, y_overlap=0.5):
print("**********\nPredictions2 at [x=%d,y=%d,w=%d,h=%d]" % obj.rect())
img.draw_rectangle(obj.rect())
predictions_list2 = list(zip(labels, obj.output()))
for p in range(len(predictions_list2)):
print("%s = %f" % (predictions_list2[p][0], predictions_list2[p][1]))
num2 = ord(predictions_list2[p][0]) - 48
if predictions_list2[p][1] > 0.7 and num2 == num:
uart.write('2')
print("22")
B0 = 1
C1 = 1
C0 = 0
```
这样,原来的代码被分成了两个循环,分别执行不同的操作。注意,我只是将代码进行了分块并进行了调整,具体的语义和逻辑仍然需要根据实际需求来确认。
results <- list() for(i in 1:1) { print(paste(i,"fold")) train_index <- unlist(cvlist[-i]) test_index <- cvlist[[i]] m_train = Markers_2[train_index,] m_test = Markers_2[test_index,] Pheno_train = pheno[train_index,] Pheno_test = pheno[test_index,] class(m_test) TS <- as.numeric(Pheno_train) ETA<-list(list(X= m_train ,model='BayesB')) fit_BB=BGLR(y=TS,ETA=ETA,nIter=nIter,burnIn=burnIn,thin=thin,saveAt=saveAt,df0=5,S0=S0,weights=weights,R2=R2) str(fit_BB) pre_eta <- list(list(X= m_test ,model='BayesB')) predictions <- predict( fit_BB, pre_eta ) # predictions[predictions < 0] <- 0.1 obversion <- Pheno_test results[[i]] <- data.frame( test_index,predictions, obversion) };如该代码所示,predict时候结果是训练集的数量
根据你提供的代码,问题出在predict()函数的调用上。在predict()函数中,你应该使用与训练集相同的ETA对象,而不是使用不同的ETA对象去进行预测。因此,你需要将预测数据的ETA对象设置为与训练数据相同的ETA对象。具体来说,你需要在predict()函数中使用和拟合模型时相同的ETA值。
修改后的代码如下:
```
results <- list()
for(i in 1:1) {
print(paste(i,"fold"))
train_index <- unlist(cvlist[-i])
test_index <- cvlist[[i]]
m_train = Markers_2[train_index,]
m_test = Markers_2[test_index,]
Pheno_train = pheno[train_index,]
Pheno_test = pheno[test_index,]
TS <- as.numeric(Pheno_train)
ETA<-list(list(X= m_train ,model='BayesB'))
fit_BB=BGLR(y=TS,ETA=ETA,nIter=nIter,burnIn=burnIn,thin=thin,saveAt=saveAt,df0=5,S0=S0,weights=weights,R2=R2)
str(fit_BB)
# 使用相同的ETA对象进行预测
predictions <- predict(fit_BB, list(list(X=m_test, model='BayesB', ETA=ETA)), nIter=nIter, burnIn=burnIn, thin=thin)
obversion <- Pheno_test
results[[i]] <- data.frame(test_index, predictions, obversion)
}
```
这样修改后,predict()函数将会使用相同的ETA对象去进行预测,而不是使用不同的ETA对象。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)