我正在尝试获取数据库中包含最多条目的人员列表.
print db.points.aggregate(
[
{
"$group":
{
"_id": "$created.user",
"count":{"$sum":1}
}
},
{
"$sort":
{"count":-1}
}
]
)
Run Code Online (Sandbox Code Playgroud)
条目如下所示:
{
u'id': u'342902',
u'_id': ObjectId('555af76a029d3b1b0ff9a4be'),
u'type': u'node',
u'pos': [48.9979746, 8.3719741],
u'created': {
u'changeset': u'7105928',
u'version': u'4',
u'uid': u'163673',
u'timestamp': u'2011-01-27T18:05:54Z',
u'user': u'Free_Jan'
}
}
Run Code Online (Sandbox Code Playgroud)
我知道created.user存在并且可以访问.
我得到的输出仍然是:
<pymongo.command_cursor.CommandCursor object at 0x02ADD6B0>
我不应该得到一个排序列表?
windows 10,python 2.7 64位
您好,按照此步骤的指南:
pip install pipwin
pipwin install pycuda
Run Code Online (Sandbox Code Playgroud)
给了我这些选择
Package `pycuda` found in cache
Choose version to download.
[0] : 2014.1+cuda6514
[1] : 2015.1.3+cuda7518
Run Code Online (Sandbox Code Playgroud)
无论我选择什么,我都会收到以下错误(最后一行):
File "c:\users\skpok\anaconda2\lib\zipfile.py", line 811, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file
Run Code Online (Sandbox Code Playgroud)
谁知道这个错误?
在这里的初学者,想读入以p结尾的数据。
我的代码如下所示:
import pickle
training_file = "/home/sk/CarND-Traffic-Sign-Classifier-Project/train.p"
testing_file = "/home/sk/CarND-Traffic-Sign-Classifier-Project/test.p"
with open(training_file, mode='rb') as f:
train = pickle.load(f)
with open(testing_file, mode='rb') as f:
test = pickle.load(f)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError:不支持的泡菜协议:3
有人可以指出我如何解决它,通过更改协议或以其他方式读取数据吗?
我想small使用 总结每个不同 video.id 的数据dplyr。
small %>%
group_by(Video.ID) %>%
summarise(sumr = sum(Partner.Revenue),
len = mean(Video.Duration..sec.),
cat = mean(Category))
Run Code Online (Sandbox Code Playgroud)
Mean(Category) 显然是错误的方法。如何获取它只是为了使用重复多次的值(一个 video.id 始终具有相同的类别,无论它在数据帧中出现的频率如何)。
我的数据框如下所示:
small
# A tibble: 6 x 7
X1 X1_1 Video.ID Video.Duration..sec. Category Owned.Views Partner.Revenue
<int> <int> <chr> <int> <chr> <int> <dbl>
1 1 1 ---0zh9uzSE 1184 gadgets 6 0
2 2 2 ---0zh9uzSE 1184 gadgets 6 0
3 3 3 ---0zh9uzSE 1184 gadgets 2 0
4 4 4 ---0zh9uzSE 1184 gadgets 1 0
5 …Run Code Online (Sandbox Code Playgroud) 我有一个音频文件(30 秒),想使用谷歌将其转换为文本。
我正在遵循本指南:
https://realpython.com/python-speech-recognition/#working-with-audio-files
我的代码如下:
cut=sr.AudioFile("cutsound.wav") 以 cut 作为源:audio = r.record(source) r.recognize_google(audio)
现在我收到这个无休止的错误信息:
---------------------------------------------------------------------------
BrokenPipeError Traceback (most recent call last)
~/anaconda3/envs/tf/lib/python3.6/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
1317 h.request(req.get_method(), req.selector, req.data, headers,
-> 1318 encode_chunked=req.has_header('Transfer-encoding'))
1319 except OSError as err: # timeout error
~/anaconda3/envs/tf/lib/python3.6/http/client.py in request(self, method, url, body, headers, encode_chunked)
1238 """Send a complete request to the server."""
-> 1239 self._send_request(method, url, body, headers, encode_chunked)
1240
~/anaconda3/envs/tf/lib/python3.6/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
1284 body = _encode(body, 'body')
-> …Run Code Online (Sandbox Code Playgroud) 做一个深度学习教程,我的python找不到该模块.
from logistic_sgd import LogisticRegression, load_data
ImportError: No module named logistic_sgd
Run Code Online (Sandbox Code Playgroud)
我该如何安装?
想要使用Gridsearch查找最佳参数并使用f1作为评分指标.
如果我删除评分功能,一切正常,我没有错误.
这是我的代码:
from sklearn import grid_search
parameters = {'n_neighbors':(1,3,5,10,15),'weights':('uniform','distance'),'algorithm':('ball_tree','kd_tree','brute'),'leaf_size':(5,10,20,30,50)}
reg = grid_search.GridSearchCV(estimator=neigh,param_grid=parameters,scoring="f1")
train_classifier(reg, X_train, y_train)
train_f1_score = predict_labels(reg, X_train, y_train)
print reg.best_params_
print "F1 score for training set: {}".format(train_f1_score)
print "F1 score for test set: {}".format(predict_labels(reg, X_test, y_test))
Run Code Online (Sandbox Code Playgroud)
当我执行我得到页面上的页面为错误,我不能做它的正面或反面:(
ValueError Traceback (most recent call last)
<ipython-input-17-3083ff8a20ea> in <module>()
3 parameters = {'n_neighbors':(1,3,5,10,15),'weights':('uniform','distance'),'algorithm':('ball_tree','kd_tree','brute'),'leaf_size':(5,10,20,30,50)}
4 reg = grid_search.GridSearchCV(estimator=neigh,param_grid=parameters,scoring="f1")
----> 5 train_classifier(reg, X_train, y_train)
6 train_f1_score = predict_labels(reg, X_train, y_train)
7 print reg.best_params_
<ipython-input-9-b56ce25fd90b> in train_classifier(clf, X_train, y_train)
5 print "Training {}...".format(clf.__class__.__name__) …Run Code Online (Sandbox Code Playgroud) 试图class_weight开始。我知道其余的代码有效,它只是class_weight给了我错误:
parameters_to_tune = ['min_samples_split':[2,4,6,10,15,25], 'min_samples_leaf':[1,2,4,10],'max_depth':[None,4,10,15],
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
这是我的代码
clf1 = tree.DecisionTreeClassifier()
parameters_to_tune = ['min_samples_split':[2,4,6,10,15,25], 'min_samples_leaf':[1,2,4,10],'max_depth':[None,4,10,15],
'splitter' : ('best','random'),'max_features':[None,2,4,6,8,10,12,14],'class_weight':{1:10}]
clf=grid_search.GridSearchCV(clf1,parameters_to_tune)
clf.fit(features,labels)
print clf.best_params_
Run Code Online (Sandbox Code Playgroud)
有没有人发现我犯的错误?
当从 (0,0) 开始时,我的任务是计算骑士可以采取的所有潜在位置。我是初学者,所以我的代码很笨拙,但它似乎适用于较小的迭代集。一旦我深入 8-9 步,我就会耗尽内存。
def moves(pos):
re=[[]]
for i in range(0,len(pos)):
x,y=pos[i]
a=[x+2,y+1]
b=[x+2,y-1]
c=[x-2,y+1]
d=[x-2,y-1]
e=[x+1,y+2]
f=[x+1,y-2]
g=[x-1,y+2]
h=[x-1,y-2]
re.append(a)
re.append(b)
re.append(c)
re.append(d)
re.append(e)
re.append(f)
re.append(g)
re.append(h)
del re[0]
return re
def clean(a):
cmoves=[]
for i in range(0,len(a)):
if a[i][0]>-1 and a[i][1]>-1 and a[i][0]<9 and a[i][1]<9 :
cmoves.append(a[i])
return cmoves
def comb(a):
return clean(moves(a))
pos= [[0,0]]
a=comb(res)
steps_count=10
for step in range(steps_count):
res=comb(res)
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助或提示,谢谢。