有什么办法可以在附魔中使用多个字典。我就是这样
import enchant
d = enchant.Dict("en_US")
d.check("materialise")
>> False
Run Code Online (Sandbox Code Playgroud)
但是如果我使用enchant.Dict("en_UK"),我会得到True。组合多个字典的最佳方法是什么,以便True无论返回materialise还是materialize作为输入参数返回?
我正在研究一种ML算法,在该算法中,我试图将连续目标值转换为较小的bin,以更好地理解问题。因此可以做出更好的预测。我最初的问题是回归,但是我通过制作带有标签的小垃圾箱将其转换为分类。
我做了如下
from sklearn.preprocessing import KBinsDiscretizer
est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform')
s = est.fit(target)
Xt = est.transform(s)
Run Code Online (Sandbox Code Playgroud)
它显示一个值错误,如下所示。然后,我将数据重塑为2D。但我无法解决。
ValueError:预期的2D数组,而是1D数组:
from sklearn.preprocessing import KBinsDiscretizer
myData = pd.read_csv("train.csv", delimiter=",")
target = myData.iloc[:,-5] # this is a continuous data which must be
# converted into bins with a new column.
xx = target.values.reshape(21263,1)
est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform')
s = est.fit(xx)
Xt = est.transform(s)
Run Code Online (Sandbox Code Playgroud)
您可以看到我的目标有21263行。我必须将它们分成10个相等的bin,并将其写入数据框的新列中。感谢您的指导。
PS:最高目标值:185.0
最低目标值:0.00021
numpy machine-learning python-3.x scikit-learn sklearn-pandas
我正在 Google Colab 中运行 python 文件并收到错误。我正在关注此链接中的 bert 文本分类示例;
https://appliedmachinelearning.blog/2019/03/04/state-of-the-art-text-classification-using-bert-model-predict-the-happiness-hackerearth-challenge/
Run Code Online (Sandbox Code Playgroud)
我按照描述的教程进行操作,现在是在 colab 中运行下面的代码片段的最后一步,
python run_classifier.py
--task_name=cola
--do_train=true
--do_eval=true
--do_predict=true
--data_dir=./data/
--vocab_file=./cased_L-12_H-768_A-12/vocab.txt
--bert_config_file=./cased_L-12_H-768_A-12/bert_config.json
--init_checkpoint=./cased_L-12_H-768_A-12/bert_model.ckpt
--max_seq_length=400
--train_batch_size=8
--learning_rate=2e-5
--num_train_epochs=3.0
--output_dir=./bert_output/
--do_lower_case=False
Run Code Online (Sandbox Code Playgroud)
我知道在 Colab 中我必须像这样运行 python 文件;
!python run_classifier.py
Run Code Online (Sandbox Code Playgroud)
但我如何像脚本中那样设置其他参数。它会经历错误。感谢您的帮助。
我必须通过命令行输入几个参数。例如 tileGridSize、clipLimit 等通过命令行。这就是我的代码的样子;
#!/usr/bin/env python
import numpy as np
import cv2 as cv
import sys #import Sys.
import matplotlib.pyplot as plt
img = cv.imread(sys.argv[1], 0) # reads image as grayscale
clipLimit = float(sys.argv[2])
tileGridSize = tuple(sys.argv[3])
clahe = cv.createCLAHE(clipLimit, tileGridSize)
cl1 = clahe.apply(img)
# show image
cv.imshow('image',cl1)
cv.waitKey(0)
cv.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
如果我传递如下参数(我想给出 (8, 8) 元组);
python testing.py 图片.jpg 3.0 8 8
我收到以下错误。我理解错误,但不知道如何修复它。
TypeError: function takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud) 我在曼哈顿距离工作.它适用于简单的for循环.但我试图避免这种循环.
import numpy as np
import random
A = np.random.randint(5, size=(10, 5))
B = [1, 3, 5, 2, 4]
for i in range(10):
dist = sum(abs(A[i]-B))
print("Distances: ", dist)
Run Code Online (Sandbox Code Playgroud)
有没有比这更好的方法?比如使用高级索引..谢谢你的指导.
我有一个列表列表如下:
list_of_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
Run Code Online (Sandbox Code Playgroud)
我想file.txt用下面的格式把它写下来。
1 2 3
4 5 6
7 8 9
10 11 12
Run Code Online (Sandbox Code Playgroud)
请注意,逗号和括号不在file.txt. 我试图压平list_of_list并写入,file.txt但得到以下输出:
1
2
3
etc.
Run Code Online (Sandbox Code Playgroud) 我是新手python.我确信这是一个非常基本的问题,但我仍然没有在python中得到它.
我有两个1D-arrays,长度为50的A和B.我想找到给定的用户输入,A [0],我必须返回B [0],A [1] - > B [1]等等.
我已经为这个任务创建了一个函数.
A = [10, 20,.... 500]
B = [1, 4,.... 2500]
def func():
x = input("enter a value from the array A: ") #user input
for i in range(50):
if A[i] == x:
print(B[i])
else:
print("do nothing")
func()
Run Code Online (Sandbox Code Playgroud)
但是,如果我调用该函数,我什么也得不到.如果有人能帮助我,我将不胜感激.谢谢.
我是Python世界的新手。我正在尝试从https://github.com/aimacode/aima-python/blob/master/logic.ipynb学习一阶逻辑
我只是按照上述相同的步骤操作,但出现以下错误。
ModuleNotFoundError: No module named 'utils'
Run Code Online (Sandbox Code Playgroud)
我使用 Jupyter 笔记本进行测试。我可以看到有与此错误相关的问题。但我仍然无法解决它。感谢您的任何意见。
我想square box (not filled, just line around)从给定的图像中绘制 a center (x,y)。我可以在 C++ 中看到类似的 opencv 实现。比如这个.. OpenCV 从中心 x,y 绘制矩形
我如何在 Python 中做到这一点?我可以从中心绘制一个圆,而不是一个方框。
im = cv2.imread("path_to_/img.png")
cv2.circle(im, (270, 2422), 50, (0, 255, 0), -1)
cv2.imwrite("path_to_write/img_test.png", im)
Run Code Online (Sandbox Code Playgroud)
我想指定正方形的中心坐标和长度。
我string在 Python 中有一个,例如;
'00000001890573'
Run Code Online (Sandbox Code Playgroud)
我想提取1890573(从第一个非零字符到字符串中的最后一个字符)。
我试着像这样分裂;
'00000001890573'.split('0')..它给了我['', '', '', '', '', '', '', '189', '573']
但这不是我想要的!!因为如果我结合最后两个字符串,我将不会得到1890573.
我有一个包含很多元组的 Python 列表。我想找到最好的两个元组,以便其中具有最好的两个最大范围值。
list_ = [(55, 55), (77, 81), (95, 129)]
Run Code Online (Sandbox Code Playgroud)
所以在这个例子中,我应该能够恢复(77, 81), (95, 129). 因为81-77和129-95给出了最大的范围。我怎样才能在 Python 中做到这一点?
python ×10
python-3.x ×10
list ×2
numpy ×2
arraylist ×1
arrays ×1
enchant ×1
opencv ×1
pyenchant ×1
python-2.7 ×1
scikit-learn ×1
top-n ×1
tuples ×1