我正在尝试将django-rest应用与docker-compose结合使用。当我自己运行它时,python manage.py runserver它运行良好。
如果我尝试使用docker-compose,sudo docker-compose up它也会运行服务器,但是当我在浏览器中打开页面时,会出现错误。
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
Run Code Online (Sandbox Code Playgroud)
我已经有了数据库,所以我只是在使用这行 settings.py
MONGODB_DATABASES = {
"default": {
"name": 'api',
"host": 'localhost',
"port": 27017
},
}
Run Code Online (Sandbox Code Playgroud)
这是我的Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY . /code
RUN pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
我的docker-compose.yml:
version: '3.0'
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
mongo:
image: mongo
Run Code Online (Sandbox Code Playgroud)
已经尝试过:
我正在尝试使用LinearSVC分类器
更新:添加了导入
import nltk
from nltk.tokenize import word_tokenize
from nltk.classify.scikitlearn import SklearnClassifier
from sklearn.svm import LinearSVC, SVC
LinearSVC_classifier = SklearnClassifier(LinearSVC())
LinearSVC_classifier.train(featuresets)
Run Code Online (Sandbox Code Playgroud)
但是当我试图用概率对它进行分类时
LinearSVC_classifier.prob_classify(feats)
Run Code Online (Sandbox Code Playgroud)
发生AttributeError:
AttributeError:'LinearSVC' object has no attribute 'predict_proba'
Run Code Online (Sandbox Code Playgroud)
我检查了sklearn文档,它告诉我这个函数存在.
如何解决?