我在anaconda环境中使用python.当我导入matplotlib时,我遇到了与xwpython的兼容性问题.所以,我想切换后端.通常,这将使用matplotlibrc文件完成.但是,似乎~/.config/matplotlib/忽略了matplotlibrc .是否可以检查在导入matplotlib期间是否使用了matplotlibrc文件?使用python 2.7.
我已经用 2 个参数对数据进行了分组:
set.seed(1)
dat <- data.frame( xx=sample(10,9),
yy=sample(20,9),
group=c('A','B', 'C') )
Run Code Online (Sandbox Code Playgroud)
我可以为每个维度绘制箱线图:
ggplot(dat, aes(x=group, y=yy, fill=group)) + geom_boxplot()
ggplot(dat, aes(x=group, y=xx, fill=group)) + geom_boxplot() + coord_flip()
Run Code Online (Sandbox Code Playgroud)

现在我将结合这些并绘制反映两个变量数据的箱线图,如下所示:
(此图像是在图形编辑器中手动制作的)
有没有什么简单的方法可以绘制这种箱线图?
我正在训练带有两个输出的CovNet。我的训练样本如下所示:
[0, value_a1], [0, value_a2], ...
Run Code Online (Sandbox Code Playgroud)
和
[value_b1, 0], [value_b2, 0], ....
Run Code Online (Sandbox Code Playgroud)
我想生成自己的损失函数和包含的掩码对mask_value = 0。我具有此功能,尽管不确定是否确实可以实现我想要的功能。所以,我想写一些测试。
from tensorflow.python.keras import backend as K
from tensorflow.python.keras import losses
def masked_loss_function(y_true, y_pred, mask_value=0):
'''
This model has two target values which are independent of each other.
We mask the output so that only the value that is used for training
contributes to the loss.
mask_value : is the value that is not used for training
'''
mask = K.cast(K.not_equal(y_true, mask_value), K.floatx())
return …Run Code Online (Sandbox Code Playgroud) 我想测试 pandas.Series() 是否仅包含整数。下面的事情都不起作用。我更喜欢使用的解决方案isinstance()。
import pandas as pd
import numpy
print(isinstance(pd.Series([1, 2]).dtype, numpy.int64))
print(isinstance(pd.Series([1, 2]).dtype.type, numpy.int64))
print(pd.Series([1, 2]).dtype)
print(isinstance(pd.Series([1, 2]).dtype.type, int64))
# False
# False
# int64
# NameError: name 'int64' is not defined
Run Code Online (Sandbox Code Playgroud)
我认为这个问题肯定已经被解决了,尽管我在搜索时没有找到它。
我按照本教程安装了hadoop和hive .该教程已过时,因此我使用了当前版本.当我启动配置单元时,我收到以下错误:
hive SLF4J:实际绑定的类型为[org.apache.logging.slf4j.Log4jLoggerFactory]线程"main"中的异常java.lang.RuntimeException:com.ctc.wstx.exc.WstxParsingException:非法字符实体:扩展字符(代码0x8)在[row,col,system-id]:org.apache.hadoop的[3210,96,"file:.../software/apache-hive-3.1.0-bin/conf/hive-site.xml"]位于org.apache.hadoop.conf.confo.conf.:::::: org.apache.hadoop.conf.Configuration.getProps上的org.apache.hadoop.conf.Configuration.loadResources(Configuration.java:2931)中的.conf.Configuration.loadResource(Configuration.java:3003),Configuration.java:2806 )org.apache.hadoop.conf.Configuration.get(Configuration.java:1460)org.apache.hadoop.hive.conf.HiveConf.getVar(HiveConf.java:4990)org.apache.hadoop.hive. conf.HiveConf.getVar(HiveConf.java:5063)位于org.apache.hadoop.hive.conf.HiveConf的org.apache.hadoop.hive.conf.HiveConf.initialize(HiveConf.java:5150).(HiveConf.java) :5093)在org.apache.hadoop.hive上的org.apache.hadoop.hive.common.LogUtils.initHiveLog4jCommon(LogUtils.java:97).common.LogUtils.initHiveLog4j(LogUtils.java:81)org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:699)org.apache.hadoop.hive.cli.CliDriver.main(CliDriver) .java:683)在sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java. lang.reflect.Method.invoke(Method.java:498)org.apache.hadoop.util.RunJar.run(RunJar.java:318)org.apache.hadoop.util.RunJar.main(RunJar.java: 232)
我看了一下指定的文件,发现了这个条目:
<description>
Ensures commands with OVERWRITE (such as INSERT OVERWRITE) acquire Exclusive locks fortransactional tables. This ensures that inserts (w/o overwrite) running concurrently
are not hidden by the INSERT OVERWRITE.
</description>
Run Code Online (Sandbox Code Playgroud)
我正在运行Ubuntu 16.04,hive 3.1.0,derby 10.8.1.2,hadoop 3.1.1,Java:openjdk version"1.8.0_181".我在教程中添加了一些行文件以进行配置,但我根本没有触及这一行.我是否必须下载不同版本的配置单元?
我有一个带有可删除行和列的破折号 DataTable 对象。我想根据可见行更新数字。我不确定如何创建回调以及要传递哪些参数。当在浏览器中删除行时,存储在表对象中的数据实际上可能不会改变。
from dash_table import DataTable
def lineplot(id, df, cols, title=None, xlabel=None, ylabel=None, x=None,
xaxis_type=None, yaxis_type=None, plotly_config=plotly_config,
):
if x is None:
x_values = df.index
xlabel = df.index.name
else:
x_values = df[x]
data = [{
'x': x_values,
'y': df[col],
'name': col } for col in cols]
layout = go.Layout(
title=go.layout.Title(
text=title,
xref='paper',
xanchor='center'
),
xaxis = go.layout.XAxis(
title=go.layout.xaxis.Title(
text=xlabel,
font=plotly_config['font'],
),
type=xaxis_type
),
yaxis=go.layout.YAxis(
title=go.layout.yaxis.Title(
text=ylabel,
font=plotly_config['font'],
),
type=yaxis_type
),
showlegend=True
)
return dcc.Graph(
id=id,
figure={'data': data,
'layout': layout}, …Run Code Online (Sandbox Code Playgroud) 以下跟踪在绘图中显示了一些文本。我想将此文本旋转到 90\xc2\xb0。我尝试了textangle关键字,但不起作用。
trace = go.Scatter(\n x=[1999],\n y=[1],\n mode='text',\n name='Note',\n text=['Missing data due to database change'],\n textposition='middle center'\n)\nRun Code Online (Sandbox Code Playgroud)\n 我用 训练了一个模型fastai.tabular。现在,我有了一个合适的学习者。最终,模型应用于新数据,而不仅仅是适应训练集并在测试集上进行评估等。我尝试了不同的方法,但都导致了错误或一些奇怪的情况。有没有办法将用 fastai 训练的模型应用于以前不可用的数据?或者我是否必须一次又一次地训练模型并输入新的测试数据?这似乎不太可能。
df_test = pd.read_parquet('generated_test.parquet').head(100)
test_data = TabularList.from_df(df_test, cat_names=cat_names, cont_names=cont_names)
prediction = learn.predict(test_data)
Run Code Online (Sandbox Code Playgroud)
关键错误:“原子距离”
atomic_distance是训练数据和测试数据中存在的列的名称,也包含在cont_names.
prediction = learn.get_preds(kaggle_test_data)
Run Code Online (Sandbox Code Playgroud)
这做了一些事情,但它返回了一些奇怪的东西:
[tensor([[136.0840],
[ -2.0286],
[ -2.0944],
...,
[135.6165],
[ 2.7626],
[ 8.0316]]),
tensor([ 84.8076, -11.2570, -11.2548, ..., 81.0491, 0.8874, 4.1235])]
Run Code Online (Sandbox Code Playgroud)
文档说:
Docstring:返回
ds_type数据集的预测和目标。
这是新的、未标记的数据。我不知道为什么返回的对象应该有标签。他们来自哪里?而且尺寸也没有意义。我期待有 100 个值的东西。
我找到了一种通过逐行传递数据框的方法:
prediction = [float(learn.predict(df_test.loc[i])[0].data) for i in df_test.index]
Run Code Online (Sandbox Code Playgroud)
还有predict_batch可用的方法,但它似乎确实接受数据名。有更好的方法来做到这一点吗?
我有一个 cudf 数据框
type(pred)
> cudf.core.dataframe.DataFrame
print(pred)
> action
1778378 0
1778379 1
1778381 1
1778383 0
1778384 0
... ...
2390444 0
2390446 0
2390478 0
2390481 0
2390489 1
Run Code Online (Sandbox Code Playgroud)
我想将其转换为pandas.DataFrame(). 尽管
pd.DataFrame(pred)
> 0
0 action
Run Code Online (Sandbox Code Playgroud)
刚刚找到了答案:
pred.to_pandas()
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 FastAPI 上传 csv 文件,然后将其加载到 pandas 中。
import pandas as pd
import os
import io, base64
from fastapi import FastAPI, File, UploadFile, Form
app = FastAPI()
@app.post('/uploadfile/')
async def create_data_file(
experiment: str = Form(...),
file_type: str = Form(...),
file_id: str = Form(...),
data_file: UploadFile = File(...),
):
#decoded = base64.b64decode(data_file.file)
#decoded = io.StringIO(decoded.decode('utf-8'))
print(pd.read_csv(data_file.file, sep='\t'))
return {'filename': data_file.filename,
'experiment':experiment,
'file_type': file_type,
'file_id': file_id}
Run Code Online (Sandbox Code Playgroud)
我尝试直接使用内容或使用或file.file转换它。我也尝试过。我在示例代码中得到的错误是base64StringIOcodec
Run Code Online (Sandbox Code Playgroud)AttributeError: 'SpooledTemporaryFile' object has no attribute 'readable'
python ×4
plotly ×2
cudf ×1
fast-ai ×1
fastapi ×1
ggplot2 ×1
hadoop ×1
hive ×1
keras ×1
matplotlib ×1
pandas ×1
plotly-dash ×1
python-2.7 ×1
r ×1
tensorflow ×1
testing ×1
wxpython ×1