小编All*_*uin的帖子

如何清除NPM的https代理设置?

如何清除NPM之前的ssl代理设置?好吧,我搜索了很多,但我得到的所有帖子主要是关于如何set在企业网络中代理.

我尝试将代理设置为空:

npm config set http-proxy
npm config set https-proxy
Run Code Online (Sandbox Code Playgroud)

第一个命令通过,第二个命令警告:

npm WARN invalid config proxy=""
npm WARN invalid config Must be a full url with 'http://'
Run Code Online (Sandbox Code Playgroud)

警告是否可以忽略,我已成功清除代理设置?

proxy node.js

241
推荐指数
18
解决办法
31万
查看次数

sklearn auc ValueError:y_true中只有一个类

我搜索了Google,看到了一些有关此错误的StackOverflow帖子.他们不是我的情况.

我使用keras训练一个简单的神经网络,并对分裂的测试数据集做出一些预测.但是当用于roc_auc_score计算AUC时,我得到以下错误:

"ValueError: Only one class present in y_true. ROC AUC score is not defined in that case.".

我检查目标标签分布,它们是高度不平衡的.一些标签(总共29个标签中)只有一个实例.因此,它们可能在测试标签中没有正面标签实例.所以sklearn的roc_auc_score函数报告了唯一的一个类问题.那是合理的.

但我很好奇,因为当我使用sklearn的cross_val_score功能时,它可以毫无错误地处理AUC计算.

my_metric = 'roc_auc' 
scores = cross_validation.cross_val_score(myestimator, data,
                                   labels, cv=5,scoring=my_metric)
Run Code Online (Sandbox Code Playgroud)

我不知道发生了什么cross_val_score,是不是因为cross_val_score使用了分层的交叉验证数据?


更新
我继续做一些挖掘,但仍然无法找到背后的差异.我看到cross_val_score调用check_scoring(estimator, scoring=None, allow_none=False)返回一个得分手,check_scoring并将调用get_scorer(scoring)将返回scorer=SCORERS[scoring]

SCORERS['roc_auc']roc_auc_scorer;
roc_auc_scorer被由

roc_auc_scorer = make_scorer(roc_auc_score, greater_is_better=True,
                                 needs_threshold=True)
Run Code Online (Sandbox Code Playgroud)

所以,它仍然使用roc_auc_score函数.我不明白为什么cross_val_score与直接调用roc_auc_score的行为不同.

scikit-learn

12
推荐指数
1
解决办法
1万
查看次数

如何使Unirest(java)忽略证书错误

我正在使用Unirest(java版本)来发出GET和POST请求.但是我在访问SSL加密站点时遇到问题,因为我的程序在公司网络后面,网络管理员为我设置了防火墙映射.例如foobar.com映射到56.1.89.12:4444.但是当我向地址发出请求时,我将收到以下ssl证书错误:

com.mashape.unirest.http.exceptions.UnirestException: javax.net.ssl.SSLException: hostname in certificate didn't match: <56.1.89.12> != <www.foobar.com>
    at com.mashape.unirest.http.HttpClientHelper.request(HttpClientHelper.java:131)
    at com.mashape.unirest.request.BaseRequest.asString(BaseRequest.java:52)
Run Code Online (Sandbox Code Playgroud)

我看到Unirest有使用自定义的高级配置httpclient.所以我使用

Unirest.setHttpClient(MyHttpClient.makeClient());
HttpResponse<String> res = null;
try {
    res = Unirest.get(urlstr).asString();
} catch (UnirestException e) {
    e.printStackTrace();
}
String jsonstr = res.getBody();
Run Code Online (Sandbox Code Playgroud)

所述makeClient的方法MyHttpClient为:

public static HttpClient makeClient(){
 SSLContextBuilder builder = new SSLContextBuilder();
 CloseableHttpClient httpclient = null;
    try {
        // builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
        builder.loadTrustMaterial(null, new TrustStrategy(){
            public boolean isTrusted(X509Certificate[] chain, String authType)
                throws CertificateException …
Run Code Online (Sandbox Code Playgroud)

java apache-httpclient-4.x unirest

10
推荐指数
3
解决办法
1万
查看次数

为什么我不能在nodejs HTTP响应中写中文字符?

这是我的小代码:

var http = require('http');
var port = 9002;
var host_ip = '<my_ip>';
http.createServer(function (req, res) {
    var content = new Buffer("Hello ??", "utf-8")
    console.log('request arrived');
    res.writeHead(200, {
        'Content-Encoding':'utf-8',
        'charset' : 'utf-8',
        'Content-Length': content.length,
        'Content-Type': 'text/plain'});
    res.end(content.toString('utf-8'),'utf-8');
}).listen(port, host_ip);
console.log('server running at http://' + host_ip + ':' + port);
Run Code Online (Sandbox Code Playgroud)

以前我只是res.end发送"你好世界",它运作良好.然后我想调整一点,将'世界'改成中文等同的'世界',然后将标题中的'charset''内容类型'改为'utf-8'.但在Chrome和Firefox中我看到了这个:

hello ???
Run Code Online (Sandbox Code Playgroud)

然而,令人惊讶的歌剧(11.61)确实显示了正确的结果hello ??.我想知道我是否错过了代码中的某些内容,以及为什么会发生这种情况.感谢你们.

我认为这篇文章与我的情况类似,但并不完全相同.

utf-8 cjk node.js

8
推荐指数
1
解决办法
7873
查看次数

为什么在曼彻斯特编码中,比特率是波特率的一半?

我认为波特率是符号的速率,如果每个符号包含 n 位,那么比特率应该是 n x baud rate

在以太网(曼彻斯特编码)中,如果比特率是波特率的一半,那么一个符号包含 1/2 位?据我所知,比特率至少应该不低于符号率(波特率)。

关于波特率和比特率的关系,我的理解是没有问题的,但是说到曼彻斯特码,就完全违反直觉了,谁能解释一下?

ethernet baud-rate

5
推荐指数
2
解决办法
1万
查看次数

如何在mongodb中拉出数组元素(文档)?

假设集合是这样的:

db.mytests.find()
{ "_id" : ObjectId("4fb277b89b8295a790efde44"), 
"mylist": [ 
    { "foo1" :"bar1", "foo2" : "bar2" }, 
    {"foo1" : "bar3", "foo2" : "bar4" } 
], 
"nonlist" : "nonlistVal" }
Run Code Online (Sandbox Code Playgroud)

我想删除一个文件mylist,其foo1等于bar1,看完之后有关更新MongoDB的文件我用这个:

db.mytests.update({},{$pull:{'mylist':{'mylist.$.foo1':'bar1'}}})
Run Code Online (Sandbox Code Playgroud)

但它失败了.为了找出问题,我mytests使用这个插入一个新数组:

db.mytests.update({},{$set:{'anotherList':[1,2,3,4]}})
Run Code Online (Sandbox Code Playgroud)

然后使用db.mytests.update({},{$pull:{'anotherList':{$gt:3}}})拉取4数组中的元素 anotherList,它成功.

我认为问题出在mylist.$.foo1哪?你能告诉我删除数组中文档元素的正确方法吗?

mongodb

3
推荐指数
1
解决办法
6575
查看次数

Python线程无法按预期工作

好吧,我写了一个小snappet试图知道如何使用python线程.但奇怪的是,以下代码在没有预期输出的情况下快速退出.是因为我不应该通过覆盖run()方法来生成线程吗?

import threading
from time import sleep
class mythread(threading.Thread):
    def __init__(self,target=None,thread_num=5):
        threading.Thread.__init__(self,target=None)
        self.thn = thread_num

    def run(self):
        for i in range(self.thn):
            t = threading.Thread(target=self.myfunc)
            t.start()
            t.join()
        myfunc(self.thn)

    def myfunc(num):
        print num,'\tI am doing sth.'
        sleep(0.5)
        print num,'\tI have done it.'

mythread()
Run Code Online (Sandbox Code Playgroud)

python multithreading

2
推荐指数
1
解决办法
1918
查看次数

为什么python reduce()会跳过None元素?

我试图获得一个网址的主页.首先,我使用for循环并实现目标.

home = ''
my_url = 'http://www.mysite.com/subdir/subdir2/index.html'
for item in my_url.split('/')[:3]:
    home += item + '/'
print  home
Run Code Online (Sandbox Code Playgroud)

而且我能得到

'http://www.mysite.com/' 
Run Code Online (Sandbox Code Playgroud)

然后我遇到了之前从未使用过的reduce().所以我试了一下,这是代码:

my_url = 'http://www.mysite.com/subdir/subdir2/index.html'
home = ''
home = reduce(lambda x,y : x + y + '/',my_url.split('/')[:3])
print home
Run Code Online (Sandbox Code Playgroud)

这次我得到了

'http:/www.mysite.com/'
Run Code Online (Sandbox Code Playgroud)

是否减少只是忽略其中的无?对结果的解释是什么?

是的,我从这个主题知道我可以使用urllib的解析器函数来做到这一点,所以我希望这里的讨论集中在reduce()

python reduce

2
推荐指数
1
解决办法
229
查看次数

erlang如何解析http请求?

我正在学习erlang,下面是解释如何使用gen_tcp的一个例子的一部分.但是,几乎所有的toturials都只显示echo服务器,我发现没有人正在解析真正的世界http请求.

    handle_connect(Socket, BinaryList, Count) ->
    io:format("handle_connect ~p~n", [self()]),
    case gen_tcp:recv(Socket, 0) of
    {ok, Binary} ->
        io:format("request is :~s~n", Binary),
        case gen_tcp:send(Socket, Binary) of
            ok ->
                handle_connect(Socket, BinaryList, Count);
            {error, Reason} ->
                io:format("send failed~n"),
                gen_tcp:close(Socket)
        end;
Run Code Online (Sandbox Code Playgroud)

我很好奇erlang如何解析收到的数据gen_tcp:recv.我已经浏览了一些代码,lib/inets-5.7.1/src/http_server但是有太多的模块,我仍然无法弄清楚解析http请求的基本方向是什么.任何人都可以告诉我如何解析http请求,以及这些Web框架采取的方法是什么.谢谢〜

erlang http

1
推荐指数
1
解决办法
2201
查看次数