我正在做PCA,我对哪些原始功能最重要感兴趣.让我用一个例子来说明这一点:
import numpy as np
from sklearn.decomposition import PCA
X = np.array([[1,-1, -1,-1], [1,-2, -1,-1], [1,-3, -2,-1], [1,1, 1,-1], [1,2,1,-1], [1,3, 2,-0.5]])
print(X)
Run Code Online (Sandbox Code Playgroud)
哪个输出:
[[ 1. -1. -1. -1. ]
[ 1. -2. -1. -1. ]
[ 1. -3. -2. -1. ]
[ 1. 1. 1. -1. ]
[ 1. 2. 1. -1. ]
[ 1. 3. 2. -0.5]]
Run Code Online (Sandbox Code Playgroud)
直观地,人们已经可以说特征1和特征4由于它们的低方差而不是非常重要.让我们在这个集合上应用pca:
pca = PCA(n_components=2)
pca.fit_transform(X)
comps = pca.components_
Run Code Online (Sandbox Code Playgroud)
输出:
array([[ 0. , 0.8376103 , 0.54436943, 0.04550712],
[-0. , 0.54564656, -0.8297757 , …Run Code Online (Sandbox Code Playgroud) 假设我已经训练了Tensorflow Estimator:
estimator = tf.contrib.learn.Estimator(
model_fn=model_fn,
model_dir=MODEL_DIR,
config=some_config)
Run Code Online (Sandbox Code Playgroud)
我适合一些火车数据:
estimator.fit(input_fn=input_fn_train, steps=None)
Run Code Online (Sandbox Code Playgroud)
我的想法是模型适合我的MODEL_DIR.此文件夹包含一个检查站和几个文件.meta和.index.
这非常有效.我想用我的函数做一些预测:
estimator = tf.contrib.Estimator(
model_fn=model_fn,
model_dir=MODEL_DIR,
config=some_config)
predictions = estimator.predict(input_fn=input_fn_test)
Run Code Online (Sandbox Code Playgroud)
我的解决方案完美无缺,但有一个很大的缺点:你需要知道model_fn,这是我在Python中定义的模型.但是,如果我通过在Python代码中添加密集层来更改模型,则此模型对于MODEL_DIR中保存的数据不正确,从而导致不正确的结果:
NotFoundError (see above for traceback): Key xxxx/dense/kernel not found in checkpoint
Run Code Online (Sandbox Code Playgroud)
我该如何应对?如何加载我的模型/估算器,以便我可以对一些新数据进行预测?如何从MODEL_DIR加载model_fn或估算器?
我想在特定地区/国家/地区获取Youtube视频的观看次数.通过这种方式,应该可以从哪些国家/地区了解视频中的观看结果.
我尝试使用Youtube搜索列表(API v3),其中可以给出参数location和locationradius.使用这些参数,您将获得在该区域中发布的视频,但此视频通常根本不相关.参数regioncode包含有关某个国家/地区是否允许特定视频的数据.所以这也不是正确的方法.
我尝试的另一件事是从渠道获取信息,但我无法获得我没有身份验证密钥的渠道的洞察数据.
任何人都可以帮助我获取特定地区/国家/地区Youtube视频的观看次数吗?
在我的带有iJulia的iPython笔记本中,是否可以调用(函数)其他文件?到目前为止,我使用所有方法在一个大的.ipynb文件中工作,但它变得太大了.有没有办法将一些功能传输到其他文件,以便从那里调用它们?
假设我正在训练一个 min_count=5 的(Gensim)Word2Vec 模型。文档告诉我们 min_count 的作用:
忽略总频率低于此的所有单词。
min_count 对上下文有什么影响?假设我有一个由频繁词 (min_count > 5) 和不常用词 (min_count < 5) 组成的句子,用 f 和 i 注释:
这 (f) 是 (f) a (f) 测试 (i) 句子 (i) 其中 (f) 是 (f) 显示 (i) 此处 (i)
我只是编造了哪个词经常使用,哪个词不用于演示目的。
如果我删除所有不常用的词,我们会得到一个完全不同的上下文,从中训练 word2vec。在此示例中,您的句子将是“This is a which is”,这将是 Word2Vec 的训练句子。而且,如果你有很多不常用的词,原本相距很远的词现在放在同一个上下文中。
这是对 Word2Vec 的正确解释吗?我们是否只是假设您的数据集中不应该有太多不常用的词(或设置较低的 min_count 阈值)?
假设我想要对文档进行注释。每个文档都可以使用多个标签进行注释。在这个例子中,我有 2 个注释器(a 和 b),他们每个都标记了两个文档。
from sklearn.metrics import cohen_kappa_score
annotator_a = [
["a","b","c"],
["d","e"]
]
annotator_b = [
["b","c"],
["f"]
]
Run Code Online (Sandbox Code Playgroud)
Annotator_a 用标签 a、b 和 c 标记文档 1。Annotator_b 用标签 b 和 c 标记文档 1。
我尝试使用以下方法计算注释者协议:
cohen_kappa_score(annotator_a, annotator_b)
Run Code Online (Sandbox Code Playgroud)
但这会导致错误:
ValueError: You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead.
Run Code Online (Sandbox Code Playgroud)
关于如何计算此集合上的注释者协议的任何想法?
假设我在一个字符串中有一个很大的数字,比如'555555555555555555555'.可以选择将其转换为int,float或甚至是numpy浮点数:
int('555555555555555555555')
float('555555555555555555555')
np.float('555555555555555555555')
Run Code Online (Sandbox Code Playgroud)
但是,当我使用pandas函数时pd.to_numeric,出现问题:
pd.to_numeric('555555555555555555555')
Run Code Online (Sandbox Code Playgroud)
有错误:
Traceback (most recent call last):
File "pandas/_libs/src/inference.pyx", line 1173, in pandas._libs.lib.maybe_convert_numeric
ValueError: Integer out of range.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\path_to_conda\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-34-6a735441ab7b>", line 1, in <module>
pd.to_numeric('555555555555555555555')
File "C:\path_to_conda\lib\site-packages\pandas\core\tools\numeric.py", line 133, in to_numeric
coerce_numeric=coerce_numeric)
File "pandas/_libs/src/inference.pyx", line 1185, in pandas._libs.lib.maybe_convert_numeric
ValueError: Integer out of range. at position 0
Run Code Online (Sandbox Code Playgroud)
出了什么问题?为什么大熊猫不能to_numeric …
我在Seaborn热图中存储标签时遇到问题.我拥有的标签很长.当我plt.show()用来显示我的情节时,我可以通过调整画布大小来查看完整标签.但是,当我保存到文件时,只存储标签的一小部分.我在Seaborn中使用了以下代码0.7.1:
ax = sns.heatmap(some_matrix)
ax.set_yticklabels(labels=some_labels,rotation=0)
fig = ax.get_figure()
fig.savefig("my_file.png",dpi=600)
Run Code Online (Sandbox Code Playgroud)
任何线索我如何增加画布的大小,以便完整的标签存储在我的.png文件中?减小字体大小可能不是一个好的解决方案,因为Y轴上有很多标签,导致标签变得不可读.
python ×6
scikit-learn ×2
api ×1
file ×1
gensim ×1
ipython ×1
julia ×1
kappa ×1
matplotlib ×1
numpy ×1
pandas ×1
pca ×1
plot ×1
seaborn ×1
tensorflow ×1
word2vec ×1
youtube ×1
youtube-api ×1