This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
from matplotlib.font_manager import FontProperties | |
font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=14) # 解决windows环境下画图汉字乱码问题 | |
from sklearn.learning_curve import learning_curve | |
from sklearn.metrics import make_scorer, mean_absolute_error # 评分函数 | |
''' | |
- 用sklearn的learning_curve得到training_score和cv_score,使用matplotlib画出learning curve | |
- 画出data在某模型上的learning curve. | |
参数解释 | |
---------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_embedding_look_up(): | |
input_ids = tf.placeholder(dtype=tf.int32, shape=[3,2]) | |
#embedding = tf.get_variable('test', shape=[5,5]) | |
embedding = tf.Variable(np.identity(5, dtype=np.int32)) | |
input_embedding = tf.nn.embedding_lookup(embedding, input_ids) | |
sess = tf.InteractiveSession() | |
sess.run(tf.global_variables_initializer()) | |
print("embeding:\n", embedding.eval()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
def timeit(func): | |
""" | |
装饰器,计算函数执行时间 | |
""" | |
def wrapper(*args, **kwargs): | |
time_start = time.time() | |
result = func(*args, **kwargs) | |
time_end = time.time() |