ROC 全称是“受试者工作特征”(Receiver Operating Characteristic)曲线。体现了不同算法在不同任务下“期望泛化性能”的好坏。
ROC 曲线与画 P-R 曲线的方法完全一样,唯一的区别排序计算的坐标轴改为了“真正例率”(True Postitve Rate,TPR) 和“假正例率”(False Positive Rate,FPR):
真实情况 | 预测结果 | 预测结果 |
---|---|---|
正例 | 反例 | |
正例 | TP(真正例) | FN(假反例) |
import numpy as np | |
from scipy.signal import triang, tukey | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.set(context='paper', | |
style='ticks', | |
font_scale=1, | |
rc={'figure.figsize': (8, 5), | |
'figure.dpi': 100, # need fixed |
ROC 全称是“受试者工作特征”(Receiver Operating Characteristic)曲线。体现了不同算法在不同任务下“期望泛化性能”的好坏。
ROC 曲线与画 P-R 曲线的方法完全一样,唯一的区别排序计算的坐标轴改为了“真正例率”(True Postitve Rate,TPR) 和“假正例率”(False Positive Rate,FPR):
真实情况 | 预测结果 | 预测结果 |
---|---|---|
正例 | 反例 | |
正例 | TP(真正例) | FN(假反例) |
def GroupNeighbor(l): | |
""" | |
Eg: Input <= np.array | |
l = np.array([58,59, | |
87,98, | |
101,102,103,104, | |
111,122, | |
133,134,135,136]) | |
GroupNeighbor(l) = [[58, 59], | |
[101, 102, 103, 104], |
## Spiral Memory | |
# You come across an experimental new kind of memory stored on an infinite two-dimensional grid. | |
# Each square on the grid is allocated in a spiral pattern starting at a location marked 1 and then counting up while spiraling outward. For example, the first few squares are allocated like this: | |
# 17 16 15 14 13 | |
# 18 5 4 3 12 | |
# 19 6 1 2 11 | |
# 20 7 8 9 10 |
#! usr/bin/python | |
#coding=utf-8 | |
# http://gree2.github.io/python/2016/05/14/python-with-docker-redis | |
from __future__ import print_function | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import sys, os, time |
""" | |
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
BSD License | |
""" | |
import numpy as np | |
# data I/O 输入训练数据 | |
data = open('input.txt', 'r').read() # should be simple plain text file | |
chars = list(set(data)) | |
data_size, vocab_size = len(data), len(chars) # 字符数目和单词数目 |
import numpy as np | |
import S_Dbw as sdbw | |
from sklearn.cluster import KMeans | |
from sklearn.datasets.samples_generator import make_blobs | |
from sklearn.metrics.pairwise import pairwise_distances_argmin | |
np.random.seed(0) | |
S_Dbw_result = [] | |
batch_size = 45 |
def S_Dbw_result(self): | |
""" | |
compute the final result | |
""" | |
return self.Dens_bw()+self.Scat() |
def Scat(self): | |
# 分母部分: | |
sigma_s = np.std(self.data,axis=0) | |
sigma_s_2norm = np.sqrt(np.dot(sigma_s.T,sigma_s)) | |
# 分子部分: | |
sum_sigma_2norm = 0 | |
for i in range(self.k): | |
matrix_data_i = self.data[self.data_cluster == i] | |
sigma_i = np.std(matrix_data_i,axis=0) |