小编Ste*_*ler的帖子

Keras fit_generator:__getitem__ 方法的意外使用

我正在使用 fit_generator 函数来训练我的模型,并希望验证我的数据是否按预期构建和使用。我从 keras.utils.Sequence() 派生的类实现了方法__getitem____len__并且on_epoch_end看起来像这样:

class PairwiseSequence(Sequence):
"""Generator that returns a combination of simulations (over a
parametrizable amount of timesteps) and the corresponding metric distance.

pair_list: List of pairwise combinations of simulations
results: dictionary with results for the metric distance between
         simulation pairs
sim_files: List of filenames representing single timesteps
batch_size: number of samples to process in a single interference run
"""

def __init__(self, pair_list, results, mean, std, train=False, sim_files=None,
             batch_size=1):
    self.pair_list = pair_list …
Run Code Online (Sandbox Code Playgroud)

python neural-network keras

6
推荐指数
1
解决办法
3797
查看次数

f 字符串中的空格导致 ValueError:格式说明符无效

我和一位同事刚刚使用 f 字符串偶然发现了一个有趣的问题。这是一个最小的例子:

>>> f"{ 42:x}"
'2a'
Run Code Online (Sandbox Code Playgroud)

在十六进制类型后面写入空格会导致ValueError

>>> f"{ 42:x }"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid format specifier
Run Code Online (Sandbox Code Playgroud)

我理解PEP 498 中忽略表达式中的前导和尾随空白段落意味着该空格实际上应该被忽略。

为什么空格字符会导致错误,其背后的原因是什么?

python python-3.x f-string

4
推荐指数
1
解决办法
2476
查看次数

在箱线图中标记异常值 - Python

我正在分析极端天气事件。我的数据框名为 df ,如下所示:

|    Date    |      Qm      |
|------------|--------------|                                              
| 1993-01-01 |  4881.977061 |
| 1993-02-01 |  4024.396839 |
| 1993-03-01 |  3833.664650 |
| 1993-04-01 |  4981.192526 |
| 1993-05-01 |  6286.879798 |  
| 1993-06-01 |  6939.726070 |
| 1993-07-01 |  6492.936065 |
|    ...     |      ...     |
Run Code Online (Sandbox Code Playgroud)

我想知道极端事件是否与测量的异常值发生在同一年。因此,我使用 seaborn 做了我的箱线图:

# Qm boxplot analysis

boxplot = sns.boxplot(x=df.index.month,y=df['Qm'])
plt.show()
Run Code Online (Sandbox Code Playgroud)

获得的箱线图

现在,我想在同一个数字中显示与异常值相对应的年份。因此,用日期标记它们。

我已经检查了多个包含箱线图的库,但没有关于如何标记它们的线索。

PD:我在这个例子中使用了 seaborn,但任何可以提供帮助的库都将受到高度赞赏

谢谢!

python label boxplot seaborn

3
推荐指数
1
解决办法
3117
查看次数

标签 统计

python ×3

boxplot ×1

f-string ×1

keras ×1

label ×1

neural-network ×1

python-3.x ×1

seaborn ×1