我有一个概念列表(myconcepts)和一个句子列表(sentences)如下.
concepts = [['natural language processing', 'text mining', 'texts', 'nlp'], ['advanced data mining', 'data mining', 'data'], ['discourse analysis', 'learning analytics', 'mooc']]
sentences = ['data mining and text mining', 'nlp is mainly used by discourse analysis community', 'data mining in python is fun', 'mooc data analysis involves texts', 'data and data mining are both very interesting']
Run Code Online (Sandbox Code Playgroud)
概括地说,我想找到concepts在sentences.更具体地说,给定concepts(例如['natural language processing', 'text mining', 'texts', 'nlp'])中的列表,我想在句子中识别这些概念并用它的第一个元素(即natural language processing)替换它们.
例子: 那么,如果我们考虑这句话 …
你如何干净地去除Python的,当它被用make安装altinstall?我没有altuninstall在makefile中找到一个或类似的东西,这也不是一个常见的问题。
在这种情况下,我正在Ubuntu中使用Python 2.7.x,但我希望答案将适用于早期和更高版本/子版本。
为什么?我正在对各种Python子版本进行构建测试,并希望干净地进行这些测试,以便没有其他版本的“剩菜”。我可以消灭一切都在/usr/local/lib和/usr/local/bin,但有可能是其他的东西存在,我想不去除,所以有一个简单的方法来分离去除Python的部件将是理想的。
由于某种原因,我不能,pip install %CD%\*.whl因为我会得到:
Requirement 'C:\\Users\fredrik\\Downloads\\*.whl' looks like a filename, but the file does not exist
`*.whl is not a valid wheel filename.
Run Code Online (Sandbox Code Playgroud)
在macOS上(我相信Linux),我可以毫无问题地做到这一点:
pip install *.whl
Processing ./certifi-2017.11.5-py2.py3-none-any.whl
Processing ./chardet-3.0.4-py2.py3-none-any.whl
Processing ./idna-2.6-py2.py3-none-any.whl
Processing ./requests-2.18.4-py2.py3-none-any.whl
Processing ./urllib3-1.22-py2.py3-none-any.whl
...
Run Code Online (Sandbox Code Playgroud)
pip install *.whl)在Windows上工作?将我的数据拟合成 X = 我的数据后
pca = PCA(n_components=1)
pca.fit(X)
X_pca = pca.fit_transform(X)
Run Code Online (Sandbox Code Playgroud)
现在 X_pca 有一个维度。
当我按照定义执行逆变换时,它不应该返回原始数据,即X,二维数组吗?
当我做
X_ori = pca.inverse_transform(X_pca)
Run Code Online (Sandbox Code Playgroud)
我得到相同的尺寸但不同的数字。
另外,如果我同时绘制 X 和 X_ori 它们是不同的。
locale.setlocale(locale.LC_ALL, 'french') 在我的本地机器上工作(Windows 7 + Python 3)
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') 在我的另一台机器(Unix)上工作,但如果我在我的本地机器上使用它,我有这个错误:
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')' failed: unsupported locale setting
Run Code Online (Sandbox Code Playgroud) 完成执行每个 dags 后,如何在气流中获得成功邮件。
这是我尝试过的。我正在尝试在完成 dags 后收到成功邮件 任何人都可以帮助我。我已经导入了所有需要的文件。
i = datetime.now()
default_args = {
'owner': 'owner',
'depeneds_on_past': False,
'start_date': datetime(i.year, i.month, i.day-1),
'email': ['owner@gmail.com'],
'email_on_failure': True,
'email_on_retry': True,
'email_on_success': True,
'retries': 0,
'retry_delay': timedelta(minutes=10)
}
dag = DAG('update', default_args = default_args,
schedule_interval="0 3 * * *")
t0 = PythonOperator(
task_id='clear',
python_callable=empty_tables,
email_on_failure=True,
email_on_success=True,
email=['owner@gmail.com'],
dag=dag
)
# Add tasks now
t1 = BashOperator(
task_id='export',
bash_command=script,
dag=dag
)
t2 = PythonOperator(
task_id='load',
python_callable=load,
email_on_failure=True,
email_on_success=True,
email=['owner@gmail.com'],
dag=dag
)
t0 >> t1 >> …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 python 3.6 中安装 deepmatcher 包。要让这个包在 python 中运行,你需要有一个torch==0.3.1版本。所以我试图torch==0.3.1通过运行来安装:
pip install torch==0.3.1
Run Code Online (Sandbox Code Playgroud)
安装过程中出错:
收集火炬==0.3.1
错误:找不到满足要求的版本火炬==0.3.1(来自版本:0.1.2、0.1.2.post1)
错误:找不到与火炬==0.3 匹配的发行版。 1
我什至尝试使用“peterjc123”包安装它,但仍然无法卸载它。
我写了一个函数,它接受数据集(excel/pandas)和一些值,然后用决策树分类器预测结果。我已经用 sklearn 做到了。你能帮我解决这个问题吗,我已经浏览了网络和这个网站,但我找不到有效的答案。我试图这样做,但它不起作用:
from sklearn.metrics import accuracy_score
score = accuracy_score(variable_list, result_list)
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
ValueError: Classification metrics can't handle a mix of continuous-multioutput and multiclass targets
Run Code Online (Sandbox Code Playgroud)
这是代码(为了准确起见,我删除了代码)
import pandas as pd
import math
import xlrd
from sklearn.model_selection import train_test_split
from sklearn import tree
def predict_concrete_class(input_data, cement, blast_fur_slug,fly_ash,
water, superpl, coarse_aggr, fine_aggr, days):
data_for_tree = concrete_strenght_class(input_data)
variable_list = []
result_list = []
for index, row in data_for_tree.iterrows():
variable = row.tolist()
variable = variable[0:8]
variable_list.append(variable)
result_list.append(row[-1])
decision_tree = tree.DecisionTreeClassifier()
decision_tree = decision_tree.fit(variable_list,result_list)
input_values = …Run Code Online (Sandbox Code Playgroud) 考虑一个非常简单的setup.py:
from setuptools import setup, find_packages
print('WAAAAAAAAA') # executed twice!
setup(
name="foo",
version="190425",
description="bar",
author="Developers",
author_email="me@domain.com",
install_requires=["pyzmq", "pybullet"],
packages=find_packages(),
)
Run Code Online (Sandbox Code Playgroud)
为什么模块在运行时加载两次pip install . -v?我可以做些什么来保护代码,以便它每次调用只运行一次pip,就像setup()?
我有一个字典列表,其中每个字典都有键“ shape”和“ colour”。例如:
info = [
{'shape': 'pentagon', 'colour': 'red'},
{'shape': 'rectangle', 'colour': 'white'},
# etc etc
]
Run Code Online (Sandbox Code Playgroud)
我需要找到最常见的形状/颜色组合。我决定通过在列表中找到最常见的字典来做到这一点。我将方法缩减为:
frequency = defaultdict(int)
for i in info:
hashed = json.dumps(i) # Get dictionary, turn into string to store as key in frequency dict
frequency[hashed] += 1
most_common = max(frequency, key = frequency.get) # Get most common key and unhash it back into dict
print(json.loads(most_common))
Run Code Online (Sandbox Code Playgroud)
我是python的新手,我总是总会发现大约1-2行的函数,这些函数最终会做我想做的事情。我想知道在这种情况下是否存在更快的方法?也许这可以最终帮助另一个初学者,因为经过数年的搜索后我找不到任何东西。
python ×9
pip ×3
installation ×2
python-3.x ×2
scikit-learn ×2
airflow ×1
dictionary ×1
email ×1
french ×1
json ×1
linux ×1
list ×1
locale ×1
pca ×1
setuptools ×1
version ×1
windows ×1