不明白这个python代码

img


他怎么实现符号的打印的
这个符号和mn也没关系
他怎么知道怎么打印的

符号 就是 输入变量 char, 矩形的形状 跟 m 和 n有关系,
m行 和 n列, 每行每列的元素 就i是 char 变量,
循环m行和n列,这样 打印出来就是一个字符矩形
比如 3行 4列,符号是 #
####
####
####

你输入m和n之后,分别双重循环,外层控制行,使用m,内层控制列,使用n,然后在循环里边打印你输入的字符,就达到效果了呀

img

  • 看下这篇博客,也许你就懂了,链接:检测样本分布是不是正态分布,绘制其正态分布概率图及异常值检测-python代码实现
  • 除此之外, 这篇博客: 基于Python的随机森林(RF)回归与变量重要性影响程度分析中的 1.4 预测图像绘制、精度衡量指标计算与保存 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  •   首先,进行预测图像绘制,其中包括预测结果的拟合图与误差分布直方图。关于这一部分代码的解时,大家可以查看这篇博客2的2.9部分。

    # Draw test plot
    
    plt.figure(1)
    plt.clf()
    ax=plt.axes(aspect='equal')
    plt.scatter(test_Y,random_forest_predict)
    plt.xlabel('True Values')
    plt.ylabel('Predictions')
    Lims=[0,10000]
    plt.xlim(Lims)
    plt.ylim(Lims)
    plt.plot(Lims,Lims)
    plt.grid(False)
        
    plt.figure(2)
    plt.clf()
    plt.hist(random_forest_error,bins=30)
    plt.xlabel('Prediction Error')
    plt.ylabel('Count')
    plt.grid(False)
    

      以上两幅图的绘图结果如下所示。

    在这里插入图片描述
    在这里插入图片描述

      接下来,进行精度衡量指标的计算与保存。在这里,我们用皮尔逊相关系数、决定系数与RMSE作为精度的衡量指标,并将每一次模型运行的精度衡量指标结果保存在一个Excel文件中。这一部分大家同样查看这篇博客2的2.9部分即可。

    # Verify the accuracy
    
    random_forest_pearson_r=stats.pearsonr(test_Y,random_forest_predict)
    random_forest_R2=metrics.r2_score(test_Y,random_forest_predict)
    random_forest_RMSE=metrics.mean_squared_error(test_Y,random_forest_predict)**0.5
    print('Pearson correlation coefficient is {0}, and RMSE is {1}.'.format(random_forest_pearson_r[0],
                                                                            random_forest_RMSE))
    
    # Save key parameters
    
    excel_file=load_workbook(write_excel_path)
    excel_all_sheet=excel_file.sheetnames
    excel_write_sheet=excel_file[excel_all_sheet[0]]
    excel_write_sheet=excel_file.active
    max_row=excel_write_sheet.max_row
    excel_write_content=[random_forest_pearson_r[0],random_forest_R2,random_forest_RMSE,random_seed,random_forest_seed]
    for i in range(len(excel_write_content)):
            exec("excel_write_sheet.cell(max_row+1,i+1).value=excel_write_content[i]")
    excel_file.save(write_excel_path)