本文整理汇总了Python中sklearn.manifold.TSNE.max方法的典型用法代码示例。如果您正苦于以下问题:Python TSNE.max方法的具体用法?Python TSNE.max怎么用?Python TSNE.max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.manifold.TSNE
的用法示例。
在下文中一共展示了TSNE.max方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coords_func
# 需要导入模块: from sklearn.manifold import TSNE [as 别名]
# 或者: from sklearn.manifold.TSNE import max [as 别名]
def coords_func(lib, opts, args):
if opts.type:
seq_features_file = config["blackbird"]["seq_features"].get("unicode")
seq_features = cPickle.load(open(seq_features_file, "rb"))
keys = seq_features.keys()
if opts.type == "mean":
features = np.empty((len(seq_features), 20))
for idx, key in enumerate(seq_features):
length = seq_features[key].shape[1]
features[idx, :] = seq_features[key][:, int(0.1 * length):int(0.9 * length)].mean(axis=1)
elif opts.type == "lstm":
print("Loading network...")
model = LSTMSeq2Seq(config["blackbird"]["lstm"]["arch"].get("unicode"),
config["blackbird"]["lstm"]["weights"].get("unicode"),
config["blackbird"]["lstm"]["output"].get())
# Pad sequences
maxlen = 150
padded_seq_features = np.empty((len(seq_features), maxlen, 20))
for idx, key in enumerate(seq_features):
padded_seq_features[idx, :, :] = sequence.pad_sequences(seq_features[key], maxlen=maxlen, dtype="float32").T
print("Getting vectors...")
features = model.predict(padded_seq_features)
else:
print("Provide a valid --type [mean, lstm]")
sys.exit(1)
print("Reducing dimensions...")
features_2d = TSNE(n_components=2).fit_transform(features)
print("Writing to db...")
conn = sqlite3.connect(config["blackbird"]["db"].get("unicode"))
cur = conn.cursor()
cur.execute("DELETE FROM coords")
to_insert = []
for idx in xrange(features_2d.shape[0]):
to_insert.append((keys[idx],
features_2d[idx, 0],
features_2d[idx, 1]))
cur.executemany("INSERT INTO coords VALUES (?, ?, ?)", to_insert)
conn.commit()
conn.close()
# Fill leftovers
ids_to_fill = []
for item in lib.items():
if item.id not in keys:
ids_to_fill.append(item.id)
self.fill(ids_to_fill, features_2d.min(axis=0), features_2d.max(axis=0))
else:
print("Provide a valid --type [mean, lstm]")