如果在二项分布中p成功的概率具有形状参数α> 0且β> 0的β分布,则分布是β二项式.形状参数定义成功的概率.我想从β二项分布的角度找到最能描述我的数据的α和β的值.我的数据集players 包括许多棒球运动员的命中数(H),击球次数(AB)和转换次数(H/AB)的数据.我在Python的Beta二项功能中借助JulienD的答案来估算PDF
from scipy.special import beta
from scipy.misc import comb
pdf = comb(n, k) * beta(k + a, n - k + b) / beta(a, b)
Run Code Online (Sandbox Code Playgroud)
接下来,我写了一个loglikelihood函数,我们将最小化.
def loglike_betabinom(params, *args):
"""
Negative log likelihood function for betabinomial distribution
:param params: list for parameters to be fitted.
:param args: 2-element array containing the sample data.
:return: negative log-likelihood to be …Run Code Online (Sandbox Code Playgroud) 在否定的语义范围内,情感词的行为非常不同。我想使用Das 和 Chen (2001)的稍微修改版本, 他们检测诸如no、not和never 之类的词,然后在否定和子句级标点符号之间出现的每个词后附加一个“neg”后缀。我想创建与 spaCy 的依赖解析类似的东西。
import spacy
from spacy import displacy
nlp = spacy.load('en')
doc = nlp(u'$AAPL is óóóóópen to ‘Talk’ about patents with GOOG definitely not the treatment #samsung got:-) heh')
options = {'compact': True, 'color': 'black', 'font': 'Arial'}
displacy.serve(doc, style='dep', options=options)
Run Code Online (Sandbox Code Playgroud)
可视化依赖路径:
不错,在依赖标签方案中存在一个否定修饰符; NEG
为了识别否定,我使用以下内容:
negation = [tok for tok in doc if tok.dep_ == 'neg']
Run Code Online (Sandbox Code Playgroud)
现在我想检索否定的范围。
import spacy
from spacy import displacy
import pandas as pd …Run Code Online (Sandbox Code Playgroud) 我想找到静态视频流的像素。通过这种方式,我可以检测视频流中的徽标和其他不动的项目。我的脚本背后的想法如下:
previousnp.stdx-和y-coordinates。我的脚本:
import math
import cv2
import numpy as np
video = cv2.VideoCapture(0)
previous = []
n_of_frames = 200
while True:
ret, frame = video.read()
if ret:
cropped_img = frame[0:150, 0:500]
gray = cv2.cvtColor(cropped_img, cv2.COLOR_BGR2GRAY)
if len(previous) == n_of_frames:
stdev_gray = np.std(previous, axis=2)
previous = previous[1:]
previous.append(gray)
else:
previous.append(gray)
cv2.imshow('frame', frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
video.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
这个过程非常缓慢,我很好奇是否有更快的方法来做到这一点。我对 Cython 等持开放态度。非常感谢!
我想收集包含以下词语的所有推文: 比特币、以太坊、莱特币或 Denarius
但是,我想排除可以归类为转推和包含链接的推文的推文。我从以下网站(https://www.followthehashtag.com/help/hidden-twitter-search-operators-extra-power-followthehashtag)知道我可以添加-filter:links以排除包含链接的推文。通过比较以下搜索词可以清楚地看到这一点;
https://twitter.com/search?f=tweets&vertical=news&q=Bitcoin&src=typd
与https://twitter.com/search?f=tweets&q=Bitcoin%20-filter%3Alinks&src=typd
这同样适用于转推,我可以使用-filter:retweets(参见https://twitter.com/search?f=tweets&q=Bitcoin%20-filter%3Aretweets&src=typd)
我想添加这些标准以确保我减少“噪音”并且不太可能违反任何 API 限制。我编写了以下 Python 脚本:
import sys
import time
import json
import pandas as pd
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
USER_KEY = ''
USER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_SECRET = ''
crypto_tickers = ['bitcoin', 'ethereum', 'litecoin', 'denarius', '-filter:links', '-filter:retweets']
class StdOutListener(StreamListener):
def on_data(self, data):
tweet = json.loads(data)
print(tweet)
def on_error(self, status):
if status == 420:
sys.stderr.write('Enhance …Run Code Online (Sandbox Code Playgroud) 我有一个带有 xy 坐标的文本文件,名为xy.txt.
Run Code Online (Sandbox Code Playgroud)29.66150677 -98.39336541 29.66150677 -98.39337576 29.66150651 -98.39336541 29.66150328 -98.39337576 29.66150677 -98.39336475 29.66150677 -98.39338611 29.66150393 -98.39338611 29.66150677 -98.39339646 29.66150659 -98.39339646 29.66150677 -98.39339693 29.66151576 -98.39334472 29.66151576 -98.39335506 29.66151511 -98.39334472 29.66151058 -98.39335506 29.66151576 -98.39334322 29.66151576 -98.39336541 29.66151576 -98.39337576 29.66151576 -98.39338611 29.66151576 -98.39339646 29.66151576 -98.39340681 29.66151067 -98.39340681 29.66151576 -98.39341515 29.66152475 -98.39332402 29.66152475 -98.39333437 29.66152443 -98.39332402 29.66151973 -98.39333437 29.66152475 -98.39332332 29.66152475 -98.39334472 29.66152475 -98.39335506 29.66152475 -98.39336541 29.66152475 -98.39337576 29.66152475 -98.39338611 29.66152475 -98.39339646 29.66152475 -98.39340681 29.66152475 -98.39341716 29.66151699 -98.39341716 29.66152475 -98.39342722 29.66153375 …
我有以下图片
我使用找到轮廓
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
contour = contours[0]
Run Code Online (Sandbox Code Playgroud)
接下来,我确定center轮廓的
def find_center(contour: np.ndarray) -> tuple:
M = cv2.moments(contour)
x = int(M["m10"] / M["m00"])
y = int(M["m01"] / M["m00"])
return x, y
Run Code Online (Sandbox Code Playgroud)
我想在网格中显示轮廓,其中center代表原点/(0,0) 点。所以,我减去 的center每个 xy 点的contour。
接下来,我想使用这些新坐标作为 的输入plt.contour。我需要创建一个网格
xs = new_contour[:,:,0].flatten()
ys = new_contour[:,:,1].flatten()
x = np.arange(int(min(xs)), int(max(xs)), 1)
y = np.arange(int(min(ys)), int(max(ys)), 1)
X, Y = np.meshgrid(x, y)
Run Code Online (Sandbox Code Playgroud)
如何定义/处理Z输出开始如下所示:
编辑
按照建议,我尝试使用patch.Polygon.
p = …Run Code Online (Sandbox Code Playgroud) python ×6
numpy ×2
opencv ×2
beta ×1
contour ×1
coordinates ×1
distribution ×1
matplotlib ×1
scipy ×1
spacy ×1
streaming ×1
tweepy ×1
twitter ×1