分类错误率的确切定义是什么?为什么有些研究人员使用错误率而不是准确性来报告他们的结果?我试图将我的文本分类结果与文献中的其他方法进行比较,但他们使用错误率而不是准确性,我找不到确切的定义/方程来找到我的方法的错误率。
分析自行车道的时间序列数据,我想知道每个高原、上升和下降的时间间隔。此处上传示例 csv 文件。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.dates as mdates
df = pd.read_csv(r'C:\Data\Sample.csv', parse_dates=['dateTime'])
feature_used='Cycle_Alt'
print("Eliminating null values..")
df=df[df[feature_used].notnull()]
plt.figure(figsize=(8,6))
x=df['dateTime']
y=df['Cycle_Alt']
plt.plot(x,y,c='b',linestyle=':',label="Altitude")
plt.xticks(rotation='vertical')
plt.gcf().autofmt_xdate()
plt.legend(loc='best', bbox_to_anchor=(1, 0.5))
Run Code Online (Sandbox Code Playgroud)
可以做些什么来对时间序列数据进行分类以检测每个高原、上升和下降,并假设一个变量可能比样本中呈现的变量多。
python classification time-series matplotlib timeserieschart
我正在研究multi-label图像分类问题,并根据F1-score系统预测和真实标签之间的评估进行评估。
鉴于这种情况,我应该使用loss="binary_crossentropy"或loss=keras_metrics.f1_score()地方keras_metrics.f1_score()就是从这里取:https://pypi.org/project/keras-metrics/?我有点困惑,因为我在网上找到的所有关于multi-label分类的教程都是基于binary_crossentropy损失函数的,但在这里我必须针对F1-score.
此外,我应该设置metrics=["accuracy"]还是metrics=[keras_metrics.f1_score()]应该将其完全留空?
python classification multilabel-classification keras tensorflow
有没有一种简单的方法来检查模型实例是否解决了 scikit-learn 库中的分类或回归任务?
在test set为 a 运行 6 个模型后,我在 上有以下评估指标binary classification problem:
accuracy logloss AUC
1 19% 0.45 0.54
2 67% 0.62 0.67
3 66% 0.63 0.68
4 67% 0.62 0.66
5 63% 0.61 0.66
6 65% 0.68 0.42
Run Code Online (Sandbox Code Playgroud)
我有以下问题:
1在logloss(logloss最接近于 0)方面是最好的,因为它的表现最差(就 而言accuracy)。这意味着什么 ?6具有较低的AUC比如模型得分5,当模型6具有更好accuracy。这意味着什么 ?Sigmoid 函数输出一个介于 0 和 1 之间的数字。这是一个概率还是仅仅是一个“是或否”,取决于它是高于还是低于 0.5?
最小的例子:
猫与狗的二元分类。0是猫,1是狗。
我可以对 sigmoid 输出值执行以下解释吗:
或者这是否是解释结果的正确方法:
请注意,在第一种情况下,我们如何利用数值来表示概率,而在第二种情况下,我们完全忽略了概率解释并将答案折叠为二进制。哪个是正确的?你能解释一下为什么吗?
背景上下文,请随意跳过:
我发现许多来源表明是的,sigmoid 输出可以解释为概率:
tf.sigmoid(logits)给你概率。许多来源表明相反,sigmoid 输出不能解释为概率:
classification machine-learning probability neural-network sigmoid
所附模型显示了如何在不平衡分类问题的情况下添加偏差initial_bias = np.log([pos/neg])。如果你有不平衡数据的多类分类,有没有办法增加偏差,比如说 5 个类,其中类具有分布(0.4,0.3,0.2.0.08 and 0.02)
2)在这种情况下如何计算和使用班级权重?
I found a way to apply weights, still not sure how to use bias
#####adding weights 20 Feb
weight_for_0 = ( 1/ 370)*(370+ 977+ 795)/3
weight_for_1 = ( 1/ 977)*(370+ 977+ 795)/3
weight_for_2 = (1 / 795)*(370+ 977+ 795)/3
#array([0, 1, 2]), array([370, 977, 795])
class_weights_dict = {0: weight_for_0, 1: weight_for_1, 2:weight_for_2}
class_weights_dict
Dcnn.fit(train_dataset,
epochs=NB_EPOCHS,
callbacks=[MyCustomCallback()],verbose=2,validation_data=test_dataset, class_weight=class_weights_dict)
Run Code Online (Sandbox Code Playgroud) 我需要将图像分类为癌性或非癌性。
为此,我构建了一个经典的 CNN,但我在使用两列向量标记我的数据集之间犹豫不决,如下所示:
cancerous: [0, 1]
not cancerous: [1, 0]
Run Code Online (Sandbox Code Playgroud)
并使用具有 2 个输出神经元的 softmax 激活函数。
model.add(Dense(2, activation='softmax'))
Run Code Online (Sandbox Code Playgroud)
或者
cancerous: [1]
not cancerous: [0]
Run Code Online (Sandbox Code Playgroud)
并使用带有一个输出神经元的 sigmoid 激活函数。
model.add(Dense(1, activation='sigmoid'))
Run Code Online (Sandbox Code Playgroud)
鉴于我需要使用患癌症的概率作为患者的最终指标并绘制 ROC 曲线,哪种模型更好?
假设我创建了一个模型,我的目标变量是0,1或2。似乎如果我使用predict,答案是 0、1 或 2。但是如果我使用predict_proba,我会得到一行,每行有 3 个列,如下所示,例如
model = ... Classifier # It could be any classifier
m1 = model.predict(mytest)
m2= model.predict_proba(mytest)
# Now suppose m1[3] = [0.6, 0.2, 0.2]
Run Code Online (Sandbox Code Playgroud)
假设我同时使用 predict 和predict_proba. 如果在索引 3 中,我得到了上面的结果predict_proba,在 predict 结果的索引 3 中,我应该看到 0。是这种情况吗?我试图了解如何在同一模型上使用predict和使用两者predict_proba相互关联。
python classification machine-learning prediction scikit-learn
我想计算我的模型的 F1 分数。但我收到警告并得到 0.0 F1 分数,但我不知道该怎么办。
这是源代码:
def model_evaluation(dict):
for key,value in dict.items():
classifier = Pipeline([('tfidf', TfidfVectorizer()),
('clf', value),
])
classifier.fit(X_train, y_train)
predictions = classifier.predict(X_test)
print("Accuracy Score of" , key , ": ", metrics.accuracy_score(y_test,predictions))
print(metrics.classification_report(y_test,predictions))
print(metrics.f1_score(y_test, predictions, average="weighted", labels=np.unique(predictions), zero_division=0))
print("---------------","\n")
dlist = { "KNeighborsClassifier": KNeighborsClassifier(3),"LinearSVC":
LinearSVC(), "MultinomialNB": MultinomialNB(), "RandomForest": RandomForestClassifier(max_depth=5, n_estimators=100)}
model_evaluation(dlist)
Run Code Online (Sandbox Code Playgroud)
这是结果:
Accuracy Score of KNeighborsClassifier : 0.75
precision recall f1-score support
not positive 0.71 0.77 0.74 13
positive 0.79 0.73 0.76 15
accuracy 0.75 28
macro avg …Run Code Online (Sandbox Code Playgroud) classification ×10
python ×6
keras ×3
scikit-learn ×3
tensorflow ×2
auc ×1
layer ×1
loss ×1
matplotlib ×1
metrics ×1
model ×1
prediction ×1
probability ×1
regression ×1
sigmoid ×1
time-series ×1