我想从字典中返回最大值及其键,我知道下面的内容应该可以解决问题
max(list.iteritems(), key=operator.itemgetter(1))
Run Code Online (Sandbox Code Playgroud)
但是,如果字典中的最大值为6,并且多个键具有相同的值,则它将始终返回第一个值!如何让它返回所有具有最大数字的键以及值.以下是具有相同最大值的字典示例:
dic={0: 1.4984074067880424, 1: 1.0984074067880423, 2: 1.8984074067880425, 3: 2.2984074067880425, 4: 2.2984074067880425}
Run Code Online (Sandbox Code Playgroud) 我想找到以下列表的所有可能组合:
data = ['a','b','c','d']
Run Code Online (Sandbox Code Playgroud)
我知道这看起来很简单,可以通过以下代码实现:
comb = [c for i in range(1, len(data)+1) for c in combinations(data, i)]
Run Code Online (Sandbox Code Playgroud)
但我想要的实际上是一种给列表数据的每个元素两种可能性('a'或'-a')的方法.
组合的一个例子可以是['a','b'],['-a','b'],['a','b','-c'],等,而不像当然下面的情况 ['-a','a'].
我正在做一个二进制分类..我有一个不平衡的数据,我已经使用了svm权重来试图缓解这种情况......正如你所看到的,我已经计算并绘制了每个类的roc曲线和我有以下情节:
它看起来像两个类一些...我不确定我是否正在做正确的事情因为它是我第一次绘制我自己的roc曲线......我正在使用Scikit学会绘图...是否单独绘制每个类是正确的..并且分类器在分类蓝色类时失败了吗?
这是我用来获取情节的代码:
y_pred = clf.predict_proba(X_test)[:,0] # for calculating the probability of the first class
y_pred2 = clf.predict_proba(X_test)[:,1] # for calculating the probability of the second class
fpr, tpr, thresholds = metrics.roc_curve(y_test, y_pred)
auc=metrics.auc(fpr, tpr)
print "auc for the first class",auc
fpr2, tpr2, thresholds2 = metrics.roc_curve(y_test, y_pred2)
auc2=metrics.auc(fpr2, tpr2)
print "auc for the second class",auc2
# ploting the roc curve
plt.plot(fpr,tpr)
plt.plot(fpr2,tpr2)
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.0])
plt.title('Roc curve')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.legend(loc="lower right")
plt.show()
Run Code Online (Sandbox Code Playgroud)
我知道有一种更好的方式来编写字典作为例子,但我只是想先看看曲线
我正在使用Scikit-learn构建SVM分类器...并且在运行分类器时..我想通过检查分类错误的实例并试图找出分类错误的原因来提高分类器的准确性...所以有没有办法显示分类错误的实例?
正如标题所说,我使用fit_transform与CountVectorizer训练数据..然后我使用tranform只能用测试数据... ...将这个给了我一样使用fit只在训练和tranform只对测试数据?