小编Sti*_*cky的帖子

UndefinedMetricWarning:F-score定义不明确,在没有预测样本的标签中设置为0.0

我收到这个奇怪的错误:

classification.py:1113: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
'precision', 'predicted', average, warn_for)`
Run Code Online (Sandbox Code Playgroud)

但是它也会在我第一次运行时打印出f-score:

metrics.f1_score(y_test, y_pred, average='weighted')
Run Code Online (Sandbox Code Playgroud)

我第二次跑,它提供没有错误的分数.这是为什么?

>>> y_pred = test.predict(X_test)
>>> y_test
array([ 1, 10, 35,  9,  7, 29, 26,  3,  8, 23, 39, 11, 20,  2,  5, 23, 28,
       30, 32, 18,  5, 34,  4, 25, 12, 24, 13, 21, 38, 19, 33, 33, 16, 20,
       18, 27, 39, 20, 37, 17, 31, 29, 36,  7,  6, 24, 37, …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn

57
推荐指数
3
解决办法
7万
查看次数

AWS Load Balancer EC2运行状况检查请求超时失败

我正在尝试使用DevOps进行故障并且我遇到了运行状况检查请求超时失败.问题是我的Elastic Load Balancer向我的EC2实例发送运行状况检查并获得网络超时.我不确定我做错了什么.我正在学习本教程,并完成了所有步骤,包括"使用弹性负载均衡器".我的EC2实例似乎工作正常,我能够在EC2实例中成功地在端口9292上卷曲localhost.

EC2实例安全组设置: 描述

弹性负载均衡器设置: 在此输入图像描述

我的ELB路由目标组通过HTTP打开端口9292,这是我的目标组中目标组的目标屏幕截图,它不健康. 在此输入图像描述

健康检查配置:在此输入图像描述

我有一个VPC,我的EC2实例是其中的一部分,我的ELB连接到同一个VPC.我没有安装Apache,也没有安装nginx.据我了解,我不需要这些.我有一个Rails Puma服务器正在运行,我可以将成功的curl请求发送到服务器.

我的预感是我的ELB不允许到达我的EC2实例,导致网络超时和健康状况检查失败.我无法找到原因.有任何想法吗?这个SO帖子没什么用.我的安全组是否配置错误?还有什么可能阻止从ELB到我的EC2实例的路由请求?

另外,有没有办法查看我的EC2实例的网络请求/日志?我一直看到VPC流量记录,但我觉得有更简单的替代品.

这是我在AWS论坛上发布的内容,但无济于事.

更新:我可以从EC2实例中精确地卷曲目标的私有IP.我认为这不是目标实例,我认为这与安全组设置有关.我无法确定原因,因为我基本上允许从Load Balancer到EC2实例的所有流量.

ruby-on-rails amazon-ec2 amazon-web-services elastic-load-balancer

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

尽管作为 VM 运行,Minikube Kubernetes 不允许在 Mac 上进入

我跑了minikube start --vm=true哪个输出:

  minikube v1.12.2 on Darwin 10.15.5
?  Using the docker driver based on existing profile
?  Your system has 16384MB memory but Docker has only 1991MB. For a better performance increase to at least 3GB.

    Docker for Desktop  > Settings > Resources > Memory


  Starting control plane node minikube in cluster minikube
  Restarting existing docker container for "minikube" ...
  Preparing Kubernetes v1.18.3 on Docker 19.03.8 ...
  Verifying Kubernetes components...
  Enabled addons: dashboard, default-storageclass, storage-provisioner
  Done! kubectl …
Run Code Online (Sandbox Code Playgroud)

docker kubernetes minikube kubernetes-ingress

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

Rails 6 您是否尝试打开与非 SSL Puma 的 SSL 连接?

我正在尝试在 AWS ECS 上设置 Rails 并进行 HTTPS 访问。当我的 ECS 服务部署时,这些是日志:

=> Rails 6.1.3.2 application starting in production
=> Booting Puma
* Listening on http://0.0.0.0:3000
* PID: 1
* Environment: production
* Max threads: 5
* Min threads: 5
* Puma version: 5.3.2 (ruby 3.0.1-p64) ("Sweetnighter")
Puma starting in single mode...
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop

2021-08-06 06:21:21 +0000 HTTP parse error, malformed request: 
  #<Puma::HttpParserError: Invalid HTTP format, parsing fails. Are you trying to open an SSL connection …
Run Code Online (Sandbox Code Playgroud)

ssl ruby-on-rails amazon-ecs ruby-on-rails-6

6
推荐指数
0
解决办法
903
查看次数

Ember JS教程:TypeError:无法读取undefined的属性'maps'

我目前正在他们的网站上浏览官方的EmberJS教程,我就是这个部分.当我运行时,一切都在应用程序本身完美运行,ember serve但问题是我运行新服务的单元测试.我正在运行ember test --server,我收到一个错误,我截取了以下截图:

在此输入图像描述

单元测试代码:

import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';

const DUMMY_ELEMENT = {};

let MapUtilStub = Ember.Object.extend({
  createMap(element, location) {
    this.assert.ok(element, 'createMap called with element');
    this.assert.ok(location, 'createMap called with location');
    return DUMMY_ELEMENT;
  }
});

moduleFor('service:maps', 'Unit | Service | maps', {
  needs: ['util:google-maps']
});

test('should create a new map if one isnt cached for location', function (assert) {
  assert.expect(4);
  let stubMapUtil = MapUtilStub.create({ assert });
  let mapService …
Run Code Online (Sandbox Code Playgroud)

javascript ember.js ember-testing

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

想知道为什么 matplotlib pyplot 不会调整边距

我想在绘图中添加边距,以便不是将其放置0.0在边角处,而是0.0稍微远离角点。我正在查看文档,似乎添加这一行plt.margins(x_margin, y_margin)应该添加填充。然而,无论该函数调用如何,我下面的输出仍然是相同的,并且仍然缺少边距填充。

在此输入图像描述

生成的示例代码:

import matplotlib.pyplot as plt
plt.plot([0, 0.1, 0.3, 0.5, 0.7, 0.9, 1], [0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22], 'ro')
plt.axis([0, 1, 0.15, 0.3])
# Create a 10% (0.1) and 10% (0.1) padding in the
# x and y directions respectively.
plt.margins(0.1, 0.1)
plt.show()
Run Code Online (Sandbox Code Playgroud)

python matplotlib

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

alpha(n)的大时间复杂度

O(alpha(n))是什么意思?我最近偶然发现了2048年,但就运行时间而言,其中一个块就是这样.谢谢!

big-o time-complexity

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

使用Microsoft Face API的Python POST请求错误"图像格式不受支持"

我正在尝试发送二进制映像文件来测试Microsoft Face API.使用POSTMAN工作得很好,我faceId按预期回来了.但是,我尝试将其转换为Python代码,它目前给我这个错误:

{"error": {"code": "InvalidImage", "message": "Decoding error, image format unsupported."}}
Run Code Online (Sandbox Code Playgroud)

我读了这篇SO帖子,但没有用.这是我发送请求的代码.我试图模仿POSTMAN正在做的事情,比如用标题标记它application/octet-stream但它不起作用.有任何想法吗?

url = "https://api.projectoxford.ai/face/v1.0/detect"

headers = {
  'ocp-apim-subscription-key': "<key>",
  'content-type': "application/octet-stream",
  'cache-control': "no-cache",
}

data = open('IMG_0670.jpg', 'rb')
files = {'IMG_0670.jpg': ('IMG_0670.jpg', data, 'application/octet-stream')}

response = requests.post(url, headers=headers, files=files)

print(response.text)
Run Code Online (Sandbox Code Playgroud)

python azure python-requests azure-api-apps microsoft-cognitive

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

Keras LSTM层实现背后的架构是什么?

如何将输入尺寸转换为Keras中LSTM层的输出尺寸?通过阅读Colah的博客文章,似乎"timesteps"(AKA the input_dim或中的第一个值input_shape)的数量应等于神经元的数量,这应等于该LSTM层的输出数量(由该层的units参数描述LSTM) 。

通过阅读这篇文章,我了解了输入形状。我困惑的是Keras如何将输入插入每个LSTM“智能神经元”。

Keras LSTM参考

令我感到困惑的示例代码:

model = Sequential()
model.add(LSTM(32, input_shape=(10, 64)))
model.add(Dense(2))
Run Code Online (Sandbox Code Playgroud)

由此看来,我认为LSTM层有10个神经元,每个神经元都被喂以长度为64的向量。但是,似乎它有32个神经元,我不知道每个神经元都被喂食什么。我知道,要使LSTM连接到Dense层,我们只需将所有32个输出插入2个神经元的每一个即可。令我感到困惑的是LSTM的InputLayer。

类似的帖子,但不是我所需要的

python lstm keras

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

未捕获的 ReferenceError: $$ 未定义

我正在尝试以编程方式创建一个饼图,希望将其转换为可重用的 React 组件。基本上我需要一个可点击的饼图,每个切片在点击时扩展成一个完整的饼图。我正在尝试按照本教程制作饼图,在底部,我尝试测试一段JS。我最终得到Uncaught Reference Error: $$ is not defined.了错误消息的屏幕截图。

在此处输入图片说明

我的理解是这不是jQuery,而只是 Vanilla JS。我不确定这是否属实。我通过CDN导入了jQuery,但仍然出现相同的错误。我读了这篇SO post,我在想这只是一种变量名表示法。$$

这是我的代码index.html,没有任何开创性。

<body>
  <div class="pie">20%</div>
  <div class="pie">60%</div>
  <script src="https://code.jquery.com/jquery-2.2.4.js" integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI=" crossorigin="anonymous"></script>
  <script type="text/javascript">
    $$('.pie').forEach(function(pie) {
      var p = parseFloat(pie.textContent);
      var NS = "http://www.w3.org/2000/svg";
      var svg = document.createElementNS(NS, "svg");
      var circle = document.createElementNS(NS, "circle");
      var title = document.createElementNS(NS, "title");
      circle.setAttribute("r", 16);
      circle.setAttribute("cx", 16);
      circle.setAttribute("cy", 16);
      circle.setAttribute("stroke-dasharray", p + …
Run Code Online (Sandbox Code Playgroud)

javascript css jquery svg

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

无法使用 Spring Boot REST API 设置基本身份验证

我正在尝试使用 Spring Boot 设置 RESTful API,并且我正在尝试启用基本身份验证。为什么我一直遇到 403 Access Denied 错误?我将我的凭据作为 Postman 中的标头发送(见附图)。如果我删除.anyRequest.authenticated(),它工作正常。我不想删除它,因为我希望每个端点都进行基本身份验证。我究竟做错了什么?

Application.java

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

SecurityConfiguration.java

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/h2-console/*").permitAll()
                .anyRequest().authenticated();

        http.csrf().disable();
        http.headers().frameOptions().disable();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser("user").password("password").roles("USER");
    }
}
Run Code Online (Sandbox Code Playgroud)

Controller.java

@RestController
public class Controller {

    @RequestMapping("/test")
    public String index() {
        return "Greetings from …
Run Code Online (Sandbox Code Playgroud)

spring spring-security spring-boot

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

在 AWS ECS 上设置 Rails 6 的正确方法

我在 AWS ECS 上部署了 Rails 6(与 Puma 一起运行)。有一个 ECS 服务和一个 ECS 任务,该任务启动托管我的应用程序的 EC2 实例。我还使用我的 ECS 服务创建了一个应用程序负载均衡器。我向负载均衡器添加了一个 HTTPS 侦听器。我的侦听器指向专门通过HTTP协议接受流量的目标组。

我对请求流程的理解:

HTTPS request from internet:
  --> hits AWS load balancer 
    --> hits HTTPS listener
      --> passes traffic using HTTP to Target Group
        --> request finally reaches Rails app on Target Group EC2 targets *over HTTP*
Run Code Online (Sandbox Code Playgroud)

这是一个有效的设置吗?我读了这个StackOverflow 答案,我的解释是,我们只需要 HTTPS 作为我们的负载均衡器,而不是 Puma,因此也不需要目标组。

我还通过 HTTP 为我的目标组设置了运行状况检查,该目标组期望 301 状态代码响应作为健康目标(因为我config.force_ssl在 Rails 配置中已启用)。问题是,为什么来自负载均衡器的流量没有被重定向?为什么健康检查的流量会被重定向?他们不是都针对同一个目标群体吗?为什么一个请求的结果是 200,而另一个请求的结果是 301?

我画了一张图来尝试捕捉我的问题/困惑/当前的理解:

在此输入图像描述

这是我的负载均衡器和目标组设置:

在此输入图像描述

在此输入图像描述

不确定这是 AWS 问题还是 Puma 问题或其他问题。采纳所有想法!谢谢你!!

ruby-on-rails amazon-web-services amazon-ecs aws-application-load-balancer

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