训练LightGBM模型时出现以下错误:
# Train the model
import lightgbm as lgb
lgb_train = lgb.Dataset(x_train, y_train)
lgb_val = lgb.Dataset(x_test, y_test)
parameters = {
'application': 'binary',
'objective': 'binary',
'metric': 'auc',
'is_unbalance': 'true',
'boosting': 'gbdt',
'num_leaves': 31,
'feature_fraction': 0.5,
'bagging_fraction': 0.5,
'bagging_freq': 20,
'learning_rate': 0.05,
'verbose': 0
}
model = lgb.train(parameters,
train_data,
valid_sets=test_data,
num_boost_round=5000,
early_stopping_rounds=100)
y_pred = model.predict(test_data)
Run Code Online (Sandbox Code Playgroud) 我的数据框:
data = {'Input':[133217,133217,133217,133217,133217,133217,132426,132426,132426,132426,132426,132426,132426,132426],
'Font':[30,25,25,21,20,19,50,50,50,38,38,30,30,29]}
Input Font
0 133217 30
1 133217 25
2 133217 25
3 133217 21
4 133217 20
5 133217 19
6 132426 50
7 132426 50
8 132426 50
9 132426 38
10 132426 38
11 132426 30
12 132426 30
13 132426 29
Run Code Online (Sandbox Code Playgroud)
我想创建一个仅包含Font中属于 3 个唯一最大值的值的新数据框。例如,输入 133217 的 3 个最大字体值为 30、25、21。
预期输出:
op_data = {'Input':[133217,133217,133217,133217,132426,132426,132426,132426,132426,132426,132426],
'Font':[30,25,25,21,50,50,50,38,38,30,30]}
Input Font
0 133217 30
1 133217 25
2 133217 25
3 133217 21
4 132426 …Run Code Online (Sandbox Code Playgroud) fake_useragent 包可以随机生成用户代理:
from fake_useragent import UserAgent
ua = UserAgent()
user_agent = ua.random
Run Code Online (Sandbox Code Playgroud)
有时生成的用户代理具有过时的浏览器版本,一些网站不接受它们。有没有办法只使用最新的浏览器版本生成用户代理?
python selenium web-scraping python-requests selenium-webdriver
将 selenium webdriver 设置为无头模式后是否可以将其设置回正常模式?
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get(http://stackoverflow.com)
# set driver back to normal mode
Run Code Online (Sandbox Code Playgroud) python selenium-chromedriver selenium-firefoxdriver google-chrome-headless firefox-headless
如何根据另一个列值过滤数据框中的行?
我有一个数据框,它是
ip_df:
class name marks min_marks min_subjects
0 I tom [89,85,80,74] 80 2
1 II sam [65,72,43,40] 85 1
Run Code Online (Sandbox Code Playgroud)
根据“min_subject”和“min_marks”的列值,应过滤该行。
对于索引 0,"min_subjects" 为 "2","marks" 列中至少有 2 个元素应大于 80 即,"min_marks" 列然后必须添加名为 "flag" 的新列作为 1
对于索引 1,“min_subjects”为“1”,“marks”列中至少有 1 个元素应大于 85,即“min_marks”列,然后必须将名为“flag”的新列添加为 0(即, flag=0 因为这里不满足条件)
最后的结局应该是
op_df:
class name marks min_marks min_subjects flag
0 I tom [89,85,80,74] 80 2 1
1 II sam [65,72,43,40] 85 1 0
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我在数据框中实现相同的目标吗?
复制包含不同分隔符、列名中的空格等的表的最佳方法是什么。该函数pd.read_clipboard()无法自行管理此任务。
示例 1:
| Age Category | A | B | C | D |
|--------------|---|----|----|---|
| 21-26 | 2 | 2 | 4 | 1 |
| 26-31 | 7 | 11 | 12 | 5 |
| 31-36 | 3 | 5 | 5 | 2 |
| 36-41 | 2 | 4 | 1 | 7 |
| 41-46 | 0 | 1 | 3 | 2 |
| 46-51 | 0 | 0 | …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Plotly 绘制腿部的 3D 扫描图Mesh3D。
我使用scatter_3dXYZ 点来展示这个概念:
fig = px.scatter_3d(df, x='x', y='y', z='z', opacity = 0.8)
Run Code Online (Sandbox Code Playgroud)
然而,它看起来并不像一个表面。因此,我尝试Mesh3d使用:
fig = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z, color='lightpink', opacity=0.50)])
Run Code Online (Sandbox Code Playgroud)
显然,这个剧情并不顺利。我尝试在渲染绘图之前对 df 进行排序,但没有帮助。
重申一下,我正在寻找该 XYZ 数据的平滑曲面图。
这是扫描的XYZ 数据。
编辑:有关曲面图介绍的继续信息
我用下面的代码实现了曲面图。不幸的是,没有渲染任何图(也没有伴随错误)。
colnames = ['x', 'y', 'z']
df = pd.read_csv('sandbox\leg.txt', sep = ' ', header = None, names = colnames)
x, y = np.array(df['x'].tolist()), np.array(df['y'].tolist())
df2 = df.pivot(index = 'x', columns = 'y', values = 'z')
z = df2.values
fig …Run Code Online (Sandbox Code Playgroud) (问题末尾的数据样本和尝试)
使用这样的数据框:
Type Class Area Decision
0 A 1 North Yes
1 B 1 North Yes
2 C 2 South No
3 A 3 South No
4 B 3 South No
5 C 1 South No
6 A 2 North Yes
7 B 3 South Yes
8 B 1 North No
9 C 1 East No
10 C 2 West Yes
Run Code Online (Sandbox Code Playgroud)
如何找到[A, B, C, D]属于每个区域的每种类型的百分比[North, South, East, West]?
期望的输出:
North South East West
A …Run Code Online (Sandbox Code Playgroud) 我要处理的文本文件中有一些字符串。我尝试了许多正则表达式模式,但没有一个对我有用。
someone can tell/figure
a/the squeaky wheel gets the grease/oil
accounts for (someone or something)
that's/there's (something/someone) for you
Run Code Online (Sandbox Code Playgroud)
我需要以下字符串组合:
someone can tell
someone can figure
a squeaky wheel gets the grease
a squeaky wheel gets the oil
the squeaky wheel gets the grease
the squeaky wheel gets the oil
accounts for someone
accounts for something
that's something for you
that's someone for you
there's something for you
there's someone for you
Run Code Online (Sandbox Code Playgroud) 我在变压器模型中使用MultiHeadAttention层(我的模型与命名实体识别模型非常相似)。因为我的数据具有不同的长度,所以我使用填充和attention_mask参数MultiHeadAttention来屏蔽填充。如果我使用Masking之前的图层,它会和参数MultiHeadAttention有相同的效果吗?attention_mask或者我应该同时使用:attention_mask和Masking图层?
python ×9
pandas ×3
python-3.x ×2
3d ×1
clipboard ×1
combinations ×1
copy-paste ×1
data-science ×1
dataframe ×1
group-by ×1
keras ×1
list ×1
plot ×1
plotly ×1
regex ×1
selenium ×1
string ×1
tensorflow ×1
wavefront ×1
web-scraping ×1