我正在尝试使用类似于 Altair 多行工具提示示例中显示的垂直规则https://altair-viz.github.io/gallery/multiline_tooltip.html。我也想使用文本工具提示,因为我的数据集包含与每个点相关的文本注释。
这是示例代码,我在其中添加了一个带有虚拟文本的“注释”列,并且还将工具提示添加到了行组件中,但工具提示不起作用。
import altair as alt
import pandas as pd
import numpy as np
np.random.seed(42)
source = pd.DataFrame(np.cumsum(np.random.randn(100, 3), 0).round(2),
columns=['A', 'B', 'C'], index=pd.RangeIndex(100, name='x'))
source = source.reset_index().melt('x', var_name='category', value_name='y')
Run Code Online (Sandbox Code Playgroud)
我添加了这一行来创建评论栏:
source['comments']='comment'+source.category+source.x.apply(str)
Run Code Online (Sandbox Code Playgroud)
# Create a selection that chooses the nearest point & selects based on x-value
nearest = alt.selection(type='single', nearest=True, on='mouseover',
fields=['x'], empty='none')
# The basic line
Run Code Online (Sandbox Code Playgroud)
我在这里添加了工具提示:
line = alt.Chart(source).mark_line(interpolate='basis').encode(
x='x:Q',
y='y:Q',
color='category:N',tooltip='comments'
)
Run Code Online (Sandbox Code Playgroud)
其余代码:
# Transparent selectors across the chart. This is what tells …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 imblearn 中的 RandomOverSampler 但出现错误。
看看其他帖子,旧版本似乎有问题,但我检查了我的版本,发现:
sklearn.__version__
'0.24.1'
imblearn.__version__
'0.8.0'
Run Code Online (Sandbox Code Playgroud)
这是我试图运行的代码:
from imblearn.over_sampling import RandomOverSampler
OS = RandomOverSampler(sampling_strategy='auto', random_state=0)
osx, osy = OS.fit_sample(X, y)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-a080b92fc7bc> in <module>
2
3 OS = RandomOverSampler(sampling_strategy='auto', random_state=0)
----> 4 osx, osy = OS.fit_sample(X, y)
AttributeError: 'RandomOverSampler' object has no attribute 'fit_sample'
Run Code Online (Sandbox Code Playgroud)