是否可以在python中选择HDBSCAN算法中的簇数?或者唯一的方法是使用输入参数,例如 alpha、min_cluster_size?
谢谢
更新: 这是使用 fcluster 和 hdbscan 的代码
import hdbscan
from scipy.cluster.hierarchy import fcluster
clusterer = hdbscan.HDBSCAN()
clusterer.fit(X)
Z = clusterer.single_linkage_tree_.to_numpy()
labels = fcluster(Z, 2, criterion='maxclust')
Run Code Online (Sandbox Code Playgroud) 我正在尝试访问我的 Watson Data Platform 目录中的 csv 文件。我使用了 DSX 笔记本中的代码生成功能:Insert to code> Insert StreamingBody object。
生成的代码是:
import os
import types
import pandas as pd
import boto3
def __iter__(self): return 0
# @hidden_cell
# The following code accesses a file in your IBM Cloud Object Storage. It includes your credentials.
# You might want to remove those credentials before you share your notebook.
os.environ['AWS_ACCESS_KEY_ID'] = '******'
os.environ['AWS_SECRET_ACCESS_KEY'] = '******'
endpoint = 's3-api.us-geo.objectstorage.softlayer.net'
bucket = 'catalog-test'
cos_12345 = boto3.resource('s3', endpoint_url=endpoint) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
class Note:
def __init__(self, note=None, duration=None, start_time=None):
self.note = note
self.duration = duration
self.start_time = start_time
Run Code Online (Sandbox Code Playgroud)
我想根据NumPy文档字符串样式为该类生成文档字符串,但它不会自动完成。我在下面的设置中选择了NumPy格式File | Settings | Tools | Python Integrated Tools
自动完成适用于def __init__()。当我在其后开始新行并键入时,'''将自动插入以下内容:
'''
Parameters
----------
note :
duration :
start_time :
'''
Run Code Online (Sandbox Code Playgroud)
但是,当我在下面执行相同的操作时,class Note:它不会执行该操作。我正在使用PyCharm 2017.3.3
To reproduce my problem, try this first (mapping with py_func):
import tensorflow as tf
import numpy as np
def image_parser(image_name):
a = np.array([1.0,2.0,3.0], dtype=np.float32)
return a
images = [[1,2,3],[4,5,6]]
im_dataset = tf.data.Dataset.from_tensor_slices(images)
im_dataset = im_dataset.map(lambda image:tuple(tf.py_func(image_parser, [image], [tf.float32])), num_parallel_calls = 2)
im_dataset = im_dataset.prefetch(4)
iterator = im_dataset.make_initializable_iterator()
print(im_dataset.output_shapes)
Run Code Online (Sandbox Code Playgroud)
It will give you (TensorShape(None),)
However, if you try this (using direct tensorflow mapping instead of py_func):
import tensorflow as tf
import numpy as np
def image_parser(image_name)
return image_name
images = [[1,2,3],[4,5,6]] …Run Code Online (Sandbox Code Playgroud) 我遵循了 sentdex 的 Tensorflow 对象检测教程。参考网站.... https://pythonprogramming.net/introduction-use-tensorflow-object-detection-api-tutorial/
我已经成功得到了结果。现在我想在训练后可视化权重。像这样.... https://medium.com/@awjuliani/visualizing-neural-network-layer-activation-tensorflow-tutorial-d45f8bf7bbc4 ..或.. https://gist.github.com/kukuruza/03731dc494603ceab0c5 .. 我尝试从 model_ckpt_meta 文件中获取一些权重信息。Model_ckpt_meta 文件有很多信息,但我不知道该选择哪一个。所以我选择其中一个信息。并尝试可视化权重。这是我的代码和结果?
import tensorflow as tf
import numpy as np
from tensorflow.python import pywrap_tensorflow
from matplotlib import pyplot as plt
with tf.Session() as sess:
new_saver = tf.train.import_meta_graph(checkpoint_path + '.meta')
new_saver.restore(sess, tf.train.latest_checkpoint(checkpoint_path))
weightArray=sess.run('BoxPredictor_5/ClassPredictor/weights:0')
weightArray = weightArray.reshape(-1,1,32,3)
x_min = np.min(weightArray)
x_max = np.max(weightArray)
wing=255.0*(weightArray.squeeze() - x_min) / (x_max - x_min)
plt.imshow(wing.astype('uint8'))
plt.axis('off')
Run Code Online (Sandbox Code Playgroud)
结果有什么办法显示的更清楚吗?如果使用 ssd_mobilenet 模型无法获得可视化权重。希望能告诉我。非常感谢。
我是一名大学生,并且已经通过我的大学电子邮件地址注册为Office 365教育版用户。我通常使用我的电子邮件帐户登录https://www.office.comalice@abc.edu。我的个人资料的路径如下:https : //abcedu-my.sharepoint.com/personal/alice_abc_edu
我的Office 365中有一个Excel(.xlsx)文件。并且我想使用Python以编程方式访问(或下载)Excel文件。我已经搜索了一些解决方案。但是其中大多数都需要NTLM凭据。但是我只有我的电子邮件帐户和密码。我不知道我的NTLM凭证。是alice@abc.edu还是alice_abc_edu?或电子邮件用户名和NTLM是完全不同的身份验证方式。而且我不能使用NTLM?
看来我用来登录的电子邮件地址被正式称为Work or School Account或Azure Active Directory Credential。但是我不知道如何使用这样的帐户来实现我的要求?此外,我需要在Python中执行此操作。RESTful也可以。但是我只是停留在第一步验证中。谢谢!
我在这里遵循了Microsoft Graph教程,它告诉我注册一个Python应用程序。然后我得到一个应用程序ID和应用程序秘密。但是当我使用官方python-sample-send-mail
"""send-email sample for Microsoft Graph"""
# Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
# See LICENSE in the project root for license information.
import base64
import mimetypes
import os
import pprint
import uuid
import flask
from flask_oauthlib.client import OAuth
import config
APP = flask.Flask(__name__, template_folder='static/templates')
APP.debug …Run Code Online (Sandbox Code Playgroud) 我正在使用 H2O 的机器学习包(随机森林)。
有时,我会收到此错误:
H2OConnectionError: Unexpected HTTP error: HTTPConnectionPool(host='localhost', port=54321): Max retries exceeded with url: /3/PostFile (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f176f9f39d0>: Failed to establish a new connection: [Errno 111] Connection refused',))
重新启动 H2O 服务器和/或重试我的命令(我不确定是哪一个,因为它深埋在我的代码中,但它是在h2o.init()构建 H2O 数据帧之后和之前)的某种组合似乎最终解决了该错误。
有没有办法提高最大重试次数?
我的配置。Ubuntu 16.04-2 x86_64 GNU/Linux。我正在使用Python API。
水:
Checking whether there is an H2O instance running at http://localhost:54321..... not found.
Attempting to start a local H2O server...
Java Version: openjdk version "1.8.0_151"; OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12); OpenJDK 64-Bit Server VM (build …Run Code Online (Sandbox Code Playgroud) 我已经从 URL 下载了一个文件到 AWS Lambda 的 /tmp 目录中(因为这是 Lambda 中唯一可写的路径)。
我的动机是创建一个 Alexa Skill,它将从 URL 下载文件。因此我创建了一个 lambda 函数。
如何从 lambda 中的 /tmp 文件夹访问下载的文件?
我的代码是:-
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import xml.etree.ElementTree as etree
from datetime import datetime as dt
import os
import urllib
import requests
from urllib.parse import urlparse
def lambda_handler(event, context):
""" Route the incoming request based on type (LaunchRequest, IntentRequest,
etc.) The JSON body of the request is provided in the event parameter.
""" …Run Code Online (Sandbox Code Playgroud) 我是本指南的新vim用户,以自动使vim缩进python代码并标记不必要的空格:https ://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/# vim扩展
我在.py文件上启动vim时遇到的问题是: Error detected while processing BufRead Auto commands for "*.py":
E28: No such highlight group name: BadWhitespace
我将此错误注释掉以下几行:
" Flag unnecessary whitespace
au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/ <- this line
" UTF8 Support
set encoding=utf-8
" Proper PEP8 Identation
au BufNewFile,BufRead *.py
\ set tabstop=4
" \ set softtabstop=4 <-- this line
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
Run Code Online (Sandbox Code Playgroud)
如何解决此错误?这是我完整的.vimrc文件:
set nocompatible " required
filetype off " …Run Code Online (Sandbox Code Playgroud) 似乎格式是,对于每一行,字符串就像“字号……”。所以很容易分裂。但是当我用下面的脚本分割它们时
import numpy as np
def loadGloveModel(gloveFile):
print "Loading Glove Model"
f = open(gloveFile,'r')
model = {}
for line in f:
splitLine = line.split()
word = splitLine[0]
embedding = np.array([float(val) for val in splitLine[1:]])
model[word] = embedding
print "Done.",len(model)," words loaded!"
return model
Run Code Online (Sandbox Code Playgroud)
我加载手套 840B 300d.txt。但是得到错误,我打印了我得到的 splitLine
['contact', 'name@domain.com', '0.016426', '0.13728', '0.18781', '0.75784', '0.44012', '0.096794' ... ]
Run Code Online (Sandbox Code Playgroud)
或者
['.', '.', '.', '.', '0.033459', '-0.085658', '0.27155', ...]
Run Code Online (Sandbox Code Playgroud)
请注意,此脚本在 glove.6b.* 中运行良好
python ×10
tensorflow ×2
aws-lambda ×1
docstring ×1
excel ×1
h2o ×1
ibm-cloud ×1
nlp ×1
office365 ×1
pycharm ×1
sharepoint ×1
stanford-nlp ×1
stub ×1
vim ×1
word2vec ×1