我想获得稍后在笔记本中使用的最佳模型,以使用不同的测试批次进行预测。
可重现的示例(取自 Optuna Github):
import lightgbm as lgb
import numpy as np
import sklearn.datasets
import sklearn.metrics
from sklearn.model_selection import train_test_split
import optuna
# FYI: Objective functions can take additional arguments
# (https://optuna.readthedocs.io/en/stable/faq.html#objective-func-additional-args).
def objective(trial):
data, target = sklearn.datasets.load_breast_cancer(return_X_y=True)
train_x, valid_x, train_y, valid_y = train_test_split(data, target, test_size=0.25)
dtrain = lgb.Dataset(train_x, label=train_y)
dvalid = lgb.Dataset(valid_x, label=valid_y)
param = {
"objective": "binary",
"metric": "auc",
"verbosity": -1,
"boosting_type": "gbdt",
"lambda_l1": trial.suggest_loguniform("lambda_l1", 1e-8, 10.0),
"lambda_l2": trial.suggest_loguniform("lambda_l2", 1e-8, 10.0),
"num_leaves": trial.suggest_int("num_leaves", 2, 256),
"feature_fraction": trial.suggest_uniform("feature_fraction", 0.4, …Run Code Online (Sandbox Code Playgroud) 我想更改图例中项目的名称。下面是一个可重现的例子。
import plotly.express as px
df = px.data.iris()
colorsIdx = {'setosa': '#c9cba3', 'versicolor': '#ffe1a8',
'virginica': '#e26d5c'}
cols = df['species'].map(colorsIdx)
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color=cols)
fig.show()
Run Code Online (Sandbox Code Playgroud)
因为我将自己的颜色分配给了我想重命名图例的物种,所以它不会显示为“#c9cba3”、“#ffe1a8”和“#e26d5c”。相反,我想成为“setosa”“versicolor”和“virginica”
我想在同一个图上用不同的颜色绘制多个预测,但是比例尺不正确。我对任何其他方法持开放态度。
可重现的例子:
require(forecast)
# MAKING DATA
data <- c(3.86000, 19.55810, 19.51091, 20.74048, 20.71333, 29.04191, 30.28864, 25.64300, 23.33368, 23.70870 , 26.16600 ,27.61286 , 27.88409 , 28.41400 , 24.81957 , 24.60952, 27.49857, 32.08000 , 29.98000, 27.49000 , 237.26150, 266.35478, 338.30000, 377.69476, 528.65905, 780.00000 )
a.ts <- ts(data,start=c(2005,1),frequency=12)
# FORECASTS
arima011_css =stats::arima(x = a.ts, order = c(0, 1, 1), method = "CSS") # css estimate
arima011_forecast = forecast(arima011_css, h=10, level=c(99.5))
arima321_css =stats::arima(x = a.ts, order = c(3, 2, 1), method = "CSS") # …Run Code Online (Sandbox Code Playgroud) 我想在两行之间填充红色,红色的 alpha 值根据列表而变化。本质上是红色的自定义渐变,但 Alpha 使红色显得更暗或更亮。
可重现的例子:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(20))
y = [8,9,12,14] # respective y values
a = [0.3,0.1,0.5,0.7]
ax.axhspan(8, 14, alpha=0.5, color='red')
plt.show()
Run Code Online (Sandbox Code Playgroud)
这可能有助于确定将 RGB 转换为 RGBA 时所需的颜色。也许有一种方法可以使用 axhspan 在两条线之间映射这些颜色?
from matplotlib.colors import to_rgb
r, g, b = to_rgb('red')
alpha_arr = a
c = [(r, g, b, alpha) for alpha in alpha_arr]
Run Code Online (Sandbox Code Playgroud) python ×3
arima ×1
forecast ×1
lightgbm ×1
matplotlib ×1
optuna ×1
plot ×1
plotly ×1
r ×1
time-series ×1