我正在尝试使用sklearn评估多个机器学习算法,以获得几个指标(准确度,召回率,精度等等).
对于我从这里的文档和源代码(我使用sklearn 0.17)中理解的内容,cross_val_score函数只为每次执行接收一个记分器.因此,为了计算多个分数,我必须:
实施我的(耗时且容易出错的)得分手
我用这段代码执行了多次:
from sklearn.svm import SVC
from sklearn.naive_bayes import GaussianNB
from sklearn.tree import DecisionTreeClassifier
from sklearn.cross_validation import cross_val_score
import time
from sklearn.datasets import load_iris
iris = load_iris()
models = [GaussianNB(), DecisionTreeClassifier(), SVC()]
names = ["Naive Bayes", "Decision Tree", "SVM"]
for model, name in zip(models, names):
print name
start = time.time()
for score in ["accuracy", "precision", "recall"]:
print score,
print " : ",
print cross_val_score(model, iris.data, iris.target,scoring=score, cv=10).mean()
print time.time() - start
Run Code Online (Sandbox Code Playgroud)我得到这个输出: …
我正在使用 aws sso 登录,但我不知道如何确定我是否已经登录或者是否需要再次登录,我发现执行此操作的唯一方法是运行我知道的命令权限并检查是否发生错误。
aws sso logout
aws sqs list-queues # error
aws sso login # brower accept
aws sqs list-queues # success
Run Code Online (Sandbox Code Playgroud)
我的目标是自动化一些脚本,并且仅在需要时要求登录。
我正在运行一个简单的 Django 应用程序,没有任何复杂的设置(大多数默认设置,Django allauth 和 Django Rest Framework)。
用于本地和远程运行的基础设施位于 docker-compose 文件中:
version: "3"
services:
web:
image: web_app
build:
context: .
dockerfile: Dockerfile
command: gunicorn my_service.wsgi --reload --bind 0.0.0.0:80 --workers 3
env_file: .env
volumes:
- ./my_repo/:/app:z
depends_on:
- db
environment:
- DOCKER=1
nginx:
image: nginx_build
build:
context: nginx
dockerfile: Dockerfile
volumes:
- ./my_repo/:/app:z
ports:
- "7000:80"
... # db and so on
Run Code Online (Sandbox Code Playgroud)
如您所见,我使用 Gunicorn 为应用程序提供服务,并使用 Nginx 作为代理(用于静态文件和 Let's Encrypt 设置。Nginx 容器有一些自定义功能:
FROM nginx:1.21-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
Run Code Online (Sandbox Code Playgroud)
nginx.conf 文件是一个具有静态映射的反向代理: …
我正在使用 pydantic 来验证 Json/Dict 输入。但我还使用 mypy 来验证代码的类型完整性。
当使用该pydantic.constr类型(其中包括验证给定字符串是否遵循正则表达式)时,我收到 mypy 错误。
这是代码:
from typing import List
import pydantic
Regex = pydantic.constr(regex="[0-9a-z_]*")
class Data(pydantic.BaseModel):
regex: List[Regex]
data = Data(**{"regex":["abc", "123", "etc"]})
print(data, data.json())
Run Code Online (Sandbox Code Playgroud)
这是 mypy 的输出:
$ mypy main.py
main.py:9: error: Variable "main.Regex" is not valid as a type
main.py:9: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
Run Code Online (Sandbox Code Playgroud)
我检查了文档,但找不到处理此问题的方法。我知道我可以为该正则表达式创建一个静态类型,但这违背了 pydantic 的目的。我能通过的唯一方法是使用一个# type: ignore远非理想的方法。
那么有没有一种方法可以同时具有 pydantic 和 mypy 的优点来处理这个问题呢?
我正在尝试在 Windows(主机和来宾)中设置自动构建容器。现在我在容器内执行简单的 powershell 时遇到问题。我做了以下事情:
创建了这个 DockerFile:
# escape=`
FROM microsoft/windowsservercore
SHELL ["cmd", "/S", "/C"]
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Run Code Online (Sandbox Code Playgroud)
执行此构建命令:
docker build -t test:latest .
Run Code Online (Sandbox Code Playgroud)
使用以下命令启动 docker:
docker run test
Run Code Online (Sandbox Code Playgroud)
PowerShell 打印此内容并且容器退出:
PS C:\>
D:\repo\docker\Teste
Run Code Online (Sandbox Code Playgroud)
使用此命令再次尝试:
docker start d05ee -ai
Run Code Online (Sandbox Code Playgroud)
PowerShell 打印相同的输出:
PS C:\>
D:\repo\docker\Teste
Run Code Online (Sandbox Code Playgroud)
我希望首先以交互方式使用容器来验证我将在其上安装的工具,但我无法做到这一点。我现在不知道哪个错误阻止了我这样做,这就是我的问题。
Obs1:具有相同参数的 Windows cmd 中的 powershell 工作正常。
Obs2:我的 DockerFile 基于本教程中的 DockerFile。
Obs3:运行它效果很好:
docker run -it microsoft/windowsservercore powershell -NoLogo -ExecutionPolicy Bypass
Run Code Online (Sandbox Code Playgroud)
因此我认为问题出在图像生成上。
我有一个项目需要使用mocker夹具来模拟属性。它使用 pytest 和 pytest-mock:
pip install pytest pytest-mock
Run Code Online (Sandbox Code Playgroud)
问题的一个简单例子:
我foo在foo.py文件中有该类:
class Foo:
@property
def bar(self):
return "x"
Run Code Online (Sandbox Code Playgroud)
我必须测试它模拟该属性bar:
pip install pytest pytest-mock
Run Code Online (Sandbox Code Playgroud)
但是当我修补它时,该栏的行为就像可调用的而不像属性,如何解决这个问题?
python ×3
aws-cli ×1
django ×1
docker ×1
dockerfile ×1
mypy ×1
nginx ×1
powershell ×1
pydantic ×1
pytest ×1
pytest-mock ×1
scikit-learn ×1