小编Dav*_*atu的帖子

Python:如何保存混淆矩阵

我尝试做的是将混淆矩阵保存在某种文本文件中(可能 HTML 看起来最好)。我需要从 csv 文件中获取数据,将其添加到数组中,然后创建混淆矩阵。代码:

import csv
import pandas as pd

data = csv.reader(open('results_date.csv', 'r'), delimiter=";", quotechar='|')
next(data)

true_data = []
pred_data = []

for row in data:
    if len(row) >= 2:
        true_data.append(row[0])
        pred_data.append(row[1])

true_data = [s.strip().split('_')[0] for s in true_data]
pred_data = [s.strip().split('=')[0] for s in pred_data]

y_true = pd.Series(true_data, name="Actual")
y_pred = pd.Series(pred_data, name="Predicted")
df_confusion = pd.crosstab(y_true, y_pred)
print (df_confusion)
Run Code Online (Sandbox Code Playgroud)

混淆矩阵如下所示:

Predicted  class1  class2  class3  class4  classX
Actual
class1          5       6       0       4       5
class2          1       0       4 …
Run Code Online (Sandbox Code Playgroud)

html python csv confusion-matrix

3
推荐指数
1
解决办法
1万
查看次数

Python: "AttributeError: 'Namespace' object has no attribute" argparse

My code looks like this:

parser.add_argument('-i', '--input', help='Input path/to/file.csv', required=True)
parser.add_argument('-oh', '--output-html', help='Output path/to/confusion_matrix.html', required=True)
parser.add_argument('-oc', '--output-csv', help='Output path/to/confusion_matrix.csv', required=True)
args = parser.parse_args()

....

y_true = pd.Series(true_data, name="Actual")
y_pred = pd.Series(pred_data, name="Predicted")
df_confusion = pd.crosstab(y_true, y_pred)
df_confusion.to_html(args.output-html)
df_confusion.to_csv(args.output-csv)
Run Code Online (Sandbox Code Playgroud)

When i try to run it, it gives me this error:

df_confusion.to_html(args.output-html)
AttributeError: 'Namespace' object has no attribute 'output'
Run Code Online (Sandbox Code Playgroud)

However, if i change from

df_confusion.to_html(args.output-html)
Run Code Online (Sandbox Code Playgroud)

To

df_confusion.to_html(args.output)
Run Code Online (Sandbox Code Playgroud)

It works as it should. Can anyone explain why it doesn't work, and how can …

python

3
推荐指数
1
解决办法
3429
查看次数

Bash:检查一个十进制数是否大于另一个十进制数

我有一个这样的案例:

string1="some_string"
string2="some_string"
int1="0.87"
int2="${var}"
Run Code Online (Sandbox Code Playgroud)

$var是其他脚本的输出,它具有0.9943431230.3454657或其他形式(从 0 开始,最大值约为0.9972343

现在,我不知道 bash 是如何工作的,但通常 string0.87永远不会小于或等于0.9999999,它们只是不同。

我需要这样的东西(伪代码):

if (string1 equals string2 and int1 is less than int2):
    do something;
else
    do something else.
Run Code Online (Sandbox Code Playgroud)

我期望的是0.87687大于0.87(正确??我从来不擅长数学......)

任何人都可以帮我解决这个问题的代码吗?

提前致谢!

bash

2
推荐指数
1
解决办法
6975
查看次数

按回车键,或者在 bash 脚本中写 yes

我想创建一个bash脚本(称为 install_conda.sh),用于在我的 Ubuntu 上安装 Anaconda Cloud。我已经使用 下载了软件包wget,我可以让它运行,但有些事情我不知道该怎么做。

  1. 运行 anaconda 脚本后的第一件事是:“为了继续安装过程,请查看许可协议。请按 ENTER 继续”。怎么让我install_conda.sh按那个Enter

  2. 按 Enter 后,会出现另一件事:“您同意许可条款吗?[是|否]”。在这里,我必须输入yes,然后按Enter。再次,如何做到这一点?

  3. 现在,这个东西出现了:“Anaconda3 现在将安装到这个位置:/path/to/anaconda3 Press ENTER to confirm the location”。我必须再次按Enter...

  4. 最后,我必须yes再次输入,为此:您是否希望安装程序在您的 /home/whatev/.bashrc 中将 Anaconda3 安装位置预先添加到 PATH 中?[是|否]”。

2 天搜索谷歌没有帮助。我已经阅读了一些关于xdotool,但我想避免从 Internet 安装其他东西,所以请只使用 bash。

提前致谢 :)

linux bash shell

0
推荐指数
1
解决办法
1110
查看次数

标签 统计

bash ×2

python ×2

confusion-matrix ×1

csv ×1

html ×1

linux ×1

shell ×1