我使用MongoDB的地理空间查询- $near,geoNear等等-我想知道如何打开dis的结果geoNear命令还有radius用于参数$within从可读单位,比如英里或公里查询/.
我正在使用scikit-learn来构建一些支持SVM的预测模型.我有一个包含大约5000个示例和大约700个功能的数据集.我在我的训练集上使用18x17网格搜索进行5次交叉验证,然后使用我的测试集的最佳参数.这些运行时间比我预期的要长很多,我注意到以下几点:
1)一些单独的SVM训练迭代似乎只需要一分钟,而其他人可能需要长达15分钟.预计会有不同的数据和参数(C和gamma,我正在使用rbf内核)?
2)我正在尝试在Windows上使用64位python来利用额外的内存,但我的任务管理器中所有的python进程似乎都是1 gig,我不知道这是否与运行.
3)我之前使用的是32位并在大约相同的数据集上运行,我记得(虽然我没有保存结果)但是速度要快得多.我使用第三方构建的scikit-learn用于64位窗口,所以我不知道在32位python上尝试这个是否更好?(来源http://www.lfd.uci.edu/~gohlke/pythonlibs/)
关于如何减少运行时的任何建议都将非常感激.我想减少网格搜索的搜索空间会有所帮助,但由于我不确定最佳参数的范围,我想保持它尽可能大.如果还有更快的SVM实现,请告诉我,我可以试试.
附录:我回去试图再次运行32位版本.由于某种原因,速度要快得多.花了大约3个小时到达64位版本在16小时内到达的地方.为什么会有这样的差异?
我已经安装了python2.7并且在执行我的应用程序时遇到错误
/usr/local/lib/python2.7/site-packages/PIL/_imaging.so: undefined symbol:PyUnicodeUCS2_AsLatin1String
我也通过构建检查并显示为'UCS2'
我们如何解决这个问题.
有谁知道如何使用 Tweepy(Python Twitter api 包装器)找到所有收藏/喜欢给定推文 ID 的推文的用户?
我可以得到转发,但不能得到收藏。我看到它api.favorite存在,但那里的响应是二进制的。
我正在尝试将搜索与django-haystack集成,
虽然它适用于"示例"后端,但当用whoosh替换后端时,它总是返回0结果.
settings.py:
HAYSTACK_DEFAULT_OPERATOR = 'AND'
HAYSTACK_SITECONF = 'search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 20
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'search_index')
Run Code Online (Sandbox Code Playgroud)
search_sites.py
import haystack
haystack.autodiscover()
Run Code Online (Sandbox Code Playgroud)
配置文件/ search_indexes.py:
from haystack import indexes
from haystack import site
from profiles.models import Profile
class ProfileIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Profile.objects.all()
site.register(Profile, ProfileIndex)
Run Code Online (Sandbox Code Playgroud)
模板/搜索/索引/型材/ profile_text.txt:
{{ profile.name }}
{{ profile.description }}
Run Code Online (Sandbox Code Playgroud)
运行python manage.py rebuild_index回报:
All documents removed.
Indexing 60 profiles.
Run Code Online (Sandbox Code Playgroud)
在shell中运行以下代码时:
>>> from …Run Code Online (Sandbox Code Playgroud) 我有一个基于函数的视图,看起来像这样:
def account_details(request, acc_id):
account = get_object_or_404(Account, pk=acc_id, person__user=request.user)
# ...
Run Code Online (Sandbox Code Playgroud)
其中显示了您的帐户成功的详细信息,如果您没有访问该帐户的权限或它不存在,则显示404.
我试图使用基于类的视图(扩展DetailView)来实现相同的功能,并提出了这个:
class AccountDetailView(DetailView):
def get_object(self, queryset=None):
obj = super(AccountDetailView, self).get_object(queryset)
if obj.person.user != self.request.user:
raise Http404()
return obj
Run Code Online (Sandbox Code Playgroud)
urlconf:
url(r'^account_details/(?P<pk>[0-9a-f]{24})$',
login_required(AccountDetailView.as_view(model=Account)),
name='account_details'),
Run Code Online (Sandbox Code Playgroud)
这种态度有效,但引入了2个额外的查询,看起来不对.
是否有标准或更优雅的方式来实现相同的结果?
有一个xml文件:
<body>
<entry>
I go to <hw>to</hw> to school.
</entry>
</body>
Run Code Online (Sandbox Code Playgroud)
由于某种原因,我在使用 lxml 解析器解析它之前将其更改<hw>为<hw>和</hw>to 。</hw>
<body>
<entry>
I go to <hw>to</hw> to school.
</entry>
</body>
Run Code Online (Sandbox Code Playgroud)
但是修改解析的xml数据后,我想获取一个<hw>元素,而不是<hw>. 我怎样才能做到这一点?
在kickstarter.com上,当您向Twitter发布有关项目的内容时,该推文包含一个iframe,其中包含嵌入媒体内容的一些Kickstarter项目详细信息,例如:
https://twitter.com/asfaltboy/status/211421708639416322
要重新创建此类推文,请转到某个ks页面,然后点击视频下方的"推文"链接.推文内容似乎是一些带有项目页面链接的简单文本.
这可能意味着iframe内容在该页面的某个元标记中被引用..但我不能为我的生活图中哪个元标记是...
如何才能做到这一点?
我有一个具有地理索引的MongoDB集合:
> db.coll.getIndexes()
[
// ...
{
"v" : 1,
"key" : {
"location" : "2dsphere"
},
"ns" : "test.coll",
"dropDups" : false,
"name" : "location_2dsphere",
"background" : false
}
]
db.coll.findOne({location: {'$exists': true}}, {'location': 1})
{
"_id" : ObjectId("52cd72ae2ac170aa3eaace6e"),
"location" : [
55.4545177559,
11.5767419669
]
}
Run Code Online (Sandbox Code Playgroud)
我在其上运行map reduce,看起来像这样:
var map = function() {
var value = 0;
// ... various calculations on the value here
var distance = 0; // < This is the problematic part
if (distance < …Run Code Online (Sandbox Code Playgroud) 我目前在django上收到此错误消息:[“'on'值必须为True或False。”]
views.py
from django.shortcuts import render, redirect
from .models import Comment
from .forms import sign
def index(request):
return render(request, 'submits/index.html')
def sign_list(request):
if request.method == 'POST':
form = sign(request.POST)
if form.is_valid():
new_contact = Comment(email=request.POST['email'], message=request.POST['message'], checkbox=request.POST['checkbox'])
new_contact.save()
return redirect('index')
else:
form = sign()
context = {'form' : form}
return render(request, 'submits/sign.html', context)
Run Code Online (Sandbox Code Playgroud)
表格
from django import forms
from .models import Comment
class sign(forms.Form):
email = forms.CharField(max_length=500,
widget=forms.TextInput(attrs={ 'type' : 'email', 'class' : 'form-control', 'placeholder' : 'Enter your email', 'aria-describedby' : …Run Code Online (Sandbox Code Playgroud) 我想在应用程序生命周期中只显示一次启动画面.这是我的代码:
SplashScreenActivity.java:
final int welcomeScreenDisplay = 3000;
Thread welcomeThread = new Thread() {
int wait = 0;
@Override
public void run() {
try {
super.run();
while (wait < welcomeScreenDisplay) {
sleep(1000);
wait += 1000;
}
} catch (Exception e) {
System.out.println("EXc=" + e);
} finally {
// Start other Activity
startActivity(new Intent(SplashScreenActivity.this,
MainActiviey.class));
finish();
}
}
};
welcomeThread.start();
Run Code Online (Sandbox Code Playgroud)
表现:
<activity android:name=".SplashScreenActivity" android:label="test"
android:noHistory="true"
android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|keyboard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActiviey" android:label="test"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|keyboard">
<intent-filter> …Run Code Online (Sandbox Code Playgroud) 我不知道如何使用isinstance,但这是我尝试过的:
age = int(input("Enter your Age: "))
if isinstance(age,int):
continue
else:
print ("Not an integer")
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?这也会使我的程序终止吗?或者让我重新输入我的年龄?
如果输入不是整数,我希望它不断要求我重新输入。
我在我的应用程序上有这个结构:
|-App
|
|-functions
|
|-ui
|--ui.py
|
|images
|
|main.py
Run Code Online (Sandbox Code Playgroud)
我有一个带有一些脚本的函数文件夹和一个带有Pyi在ui.py文件上生成的代码的ui文件夹.
和一个main.py文件加载ui.py以显示接口,ui.py从根目录下的"images"文件夹加载一些图像.
如果我直接在python上执行我的脚本(main.py文件上的双clic),图像将不显示..
但是,如果我使用带有"python main.py"的终端,图像会正确显示.
关于ui.py的参考文献如下:
icon.addPixmap(QtGui.QPixmap(_fromUtf8("images/flags/MXN.png"))
Run Code Online (Sandbox Code Playgroud)