我是使用Elasticsearch的新手,在通过Python脚本运行Elasticsearch查询时,我无法将所有结果返回。我的目标是查询索引(下面的“ my_index”),获取结果,并将其放入通过Django应用程序并最终生成Word文档的pandas DataFrame中。
我的代码是:
es = Elasticsearch()
logs_index = "my_index"
logs = es.search(index=logs_index,body=my_query)
Run Code Online (Sandbox Code Playgroud)
它告诉我我有72次点击,但是当我这样做时:
df = logs['hits']['hits']
len(df)
Run Code Online (Sandbox Code Playgroud)
它说长度只有10。我看到有人对此问题有类似的问题,但是他们的解决方案对我不起作用。
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
es = Elasticsearch()
logs_index = "my_index"
search = Search(using=es)
total = search.count()
search = search[0:total]
logs = es.search(index=logs_index,body=my_query)
len(logs['hits']['hits'])
Run Code Online (Sandbox Code Playgroud)
len函数仍然说我只有10个结果。我做错了什么,还是可以采取其他措施来恢复全部72个结果?
ETA:我知道我可以在查询中添加“ size”:10000,以防止截断到仅10,但是由于用户将要输入搜索查询,因此我需要找到另一种方式搜索查询。
这可能是一个愚蠢的问题,但我找不到将目标标签与fetch_20newsgroups目标名称相匹配的方法。它是否像alt.atheism==一样明显1,这就是为什么我在任何地方都找不到它,或者是否有一种我只是找不到的匹配方法?
>>> from sklearn.datasets import fetch_20newsgroups
>>> newsgroups_train = fetch_20newsgroups(subset='train')
>>> from pprint import pprint
>>> pprint(list(newsgroups_train.target_names))
['alt.atheism',
'comp.graphics',
'comp.os.ms-windows.misc',
'comp.sys.ibm.pc.hardware',
'comp.sys.mac.hardware',
'comp.windows.x',
'misc.forsale',
'rec.autos',
'rec.motorcycles',
'rec.sport.baseball',
'rec.sport.hockey',
'sci.crypt',
'sci.electronics',
'sci.med',
'sci.space',
'soc.religion.christian',
'talk.politics.guns',
'talk.politics.mideast',
'talk.politics.misc',
'talk.religion.misc']
>>> newsgroups_train.target[:10]
array([12, 6, 9, 8, 6, 7, 9, 2, 13, 19])
Run Code Online (Sandbox Code Playgroud) 我正在做一项作业,我需要使用 sklearn 库进行 KNN 回归——但是,如果我丢失了数据(假设它是随机丢失的),我不应该归咎于它。相反,我必须将其保留为 null 并以某种方式在我的代码帐户中忽略其中一个值为 null 的比较。
例如,如果我的观察是 (1, 2, 3, 4, null, 6) 和 (1, null, 3, 4, 5, 6) 那么我将忽略第二个和第五个观察。
这可能与 sklearn 库有关吗?
ETA:我只会删除空值,但我不知道他们将要测试的数据是什么样的,最终可能会下降 0% 到 99% 的数据。
我有以下数据框:
bin_class = [0,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,1]
teams = ['A','B','B','A','A','B','B','A','A','B','B','A','A','B','B','A','B','B']
d = {'Team':teams,'Classification':bin_class}
df = pd.DataFrame(d)
Team Classification
0 A 0
1 B 1
2 B 1
3 A 1
4 A 0
5 B 0
6 B 0
7 A 0
8 A 1
9 B 1
10 B 0
11 A 0
12 A 0
13 B 0
14 B 0
15 A 0
16 B 0
17 B 1
Run Code Online (Sandbox Code Playgroud)
我需要找出每个团队每个bin_class的百分比。即,在团队A的所有行中,0%和1%是多少?我尝试了几种失败了并且过于复杂的方法,有没有简单的方法可以做到这一点?
我有下面的数据框,从那里我根据线性回归模型的系数贝塔计算了矩阵 b 。如何在 R 或 中创建方差-协方差矩阵s^2_b?
y <- c(42, 33, 75, 28, 91, 55)
int <- c(1, 1, 1, 1, 1, 1)
x1 <- c(7, 4, 16, 3, 21, 8)
x2 <- c(33, 41, 7, 49, 5, 31)
df <- data.frame(y, x1, x2)
mod1 <- lm(y ~ x1 + x2, data = df)
# b
iint <- summary(mod1)$coefficients[[1]]
xx1 <- summary(mod1)$coefficients[[2]]
xx2 <- summary(mod1)$coefficients[[3]]
b <- matrix(c(iint, xx1, xx2), nrow=3)
# matrices of x and y
Y <- …Run Code Online (Sandbox Code Playgroud)