我正在尝试将我的 .Rmd 文档编织为 pdf。我尝试过安装tinytex和分离miktex分发,但都没有帮助。当我编译一个 .Rmd 文件时,我仍然得到:
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS file-R-20200512.utf8.md --to beamer --from markdown+autolink_bare_uris+tex_math_single_backslash --output file-R-20200512.tex --highlight-style tango --pdf-engine pdflatex --self-contained
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 2.9.7400 64-bit)
entering extended mode
Sorry, but C:\Users\my_username~1\MIKTEX~1.9\miktex\bin\x64\pdflatex.exe did not succeed.
The log file hopefully contains the information to get MiKTeX going again:
C:\Users\my_username\AppData\Local\MiKTeX\2.9\miktex\log\pdflatex.log
I was unable to find any missing LaTeX packages from the error log file-R-20200512.log.
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 2.9.7400 64-bit)
entering …Run Code Online (Sandbox Code Playgroud) 我的数据框结构如下:
group maybe_start maybe_end
0 ABC False False
1 ABC True False
2 ABC False False
3 ABC False False
4 ABC True False
5 ABC False False
6 ABC False True
7 ABC False False
8 DEF False False
9 DEF False False
10 DEF True False
11 DEF False False
12 DEF False True
13 DEF False False
14 DEF False False
15 DEF False True
16 DEF True False
17 DEF False False
18 DEF False True …Run Code Online (Sandbox Code Playgroud) 我有一个这样的 DataFrame:
import pandas as pd
df = pd.DataFrame.from_dict({'var1': {0: 0.0,
1: 0.0,
2: 0.0,
3: 0.0,
4: 0.0,
6: 0.0,
7: 0.0,
8: 0.0,
10: 0.0},
'var2': {0: 0.0,
1: 0.0,
2: 0.0,
3: 0.0,
4: 0.0,
6: 0.0,
7: 0.0,
8: 0.0,
10: 0.0},
'var3': {0: 0.0,
1: 0.0,
2: 0.0,
3: 0.0,
4: 0.0,
6: 0.0,
7: 0.0,
8: 0.0,
10: 0.0},
'var4': {0: 0.0,
1: 0.0,
2: 0.0,
3: 0.0,
4: 0.0,
6: 0.0,
7: 0.0, …Run Code Online (Sandbox Code Playgroud) 我有一个结构如下example_df所示的数据集:
example_df = pd.DataFrame({'measurement_id': np.concatenate([[0] * 300, [1] * 300]),\n 'min': np.concatenate([np.repeat(range(0, 30), 10), \n np.repeat(range(0, 30), 10)]),\n 'grp': list(np.repeat(['A', 'B'], 5)) * 60,\n 'grp2': list(np.random.choice([0, 1, 2], 10)) * 60,\n 'obj': np.array(list(range(0, 10)) * 60),\n 'x': np.random.normal(0.0, 10.0, 600),\n 'y': np.random.normal(50.0, 40.0, 600)})\nRun Code Online (Sandbox Code Playgroud)\n\n我还有一个函数,它将点组列表作为输入并执行一些计算。我想准备数据并在分组数据框中创建点列表列表。
\n\n我目前的解决方案如下:
\n\ndef df_to_points(df):\n points = []\n for index, row in df.iterrows():\n points.append(tuple(row))\n return(points)\n\nres = example_df \\\n .groupby(['measurement_id', 'min', 'grp']) \\\n .apply(lambda x: [df_to_points(g[['x', 'y']]) for _, g in x.groupby('grp2')])\n\nres.head(5)\nmeasurement_id …Run Code Online (Sandbox Code Playgroud) 我有一个这样的数据框:
structure(list(x = c(65.11, 65.11, 65.11, 43.72, 43.72, 43.72,
43.72, 43.72, 43.72, 43.72, 43.72, 59.89, 59.89, 59.89, 59.89,
36.24, 36.24, 36.24, 36.24, 67.88, 37.89, 37.89, 37.89, 56.05,
56.05, 56.05, 60.16, 60.16, 60.16, 30.92, 30.92, 30.92, 47.55,
47.55, 47.55), y = c(32.17, 32.17, 32.17, 56.09, 56.09, 56.09,
56.09, 56.09, 56.09, 56.09, 56.09, 15.64, 15.64, 15.64, 15.64,
81.61, 81.61, 81.61, 81.61, 56.96, 21.69, 21.69, 21.69, 86.47,
86.47, 86.47, 68.31, 68.31, 68.31, 51.56, 51.56, 51.56, 43.44,
43.44, 43.44), xend = c(59.89, 60.16, 43.72, …Run Code Online (Sandbox Code Playgroud) 我尝试根据文档设置 XGBoost sklearn APIXGBClassifier以使用自定义目标函数 ( brier):
.. note:: Custom objective function
A custom objective function can be provided for the ``objective``
parameter. In this case, it should have the signature
``objective(y_true, y_pred) -> grad, hess``:
y_true: array_like of shape [n_samples]
The target values
y_pred: array_like of shape [n_samples]
The predicted values
grad: array_like of shape [n_samples]
The value of the gradient for each sample point.
hess: array_like of shape [n_samples]
The value of the second derivative for …Run Code Online (Sandbox Code Playgroud) 我想准备一个子图,其中每个方面都是一个变量相对于其他变量的单独的双 y 轴图。因此,我制作了一个基本图p并在循环中添加辅助 y 轴变量:
library(rlang)
library(plotly)
library(tibble)
dual_axis_lines <- function(data, x, y_left, ..., facets = FALSE, axes = NULL){
x <- rlang::enquo(x)
y_left <- rlang::enquo(y_left)
y_right <- rlang::enquos(...)
y_left_axparms <- list(
title = FALSE,
tickfont = list(color = "#1f77b4"),
side = "left")
y_right_axparms <- list(
title = FALSE,
overlaying = "y",
side = "right",
zeroline = FALSE)
p <- plotly::plot_ly(data , x = x) %>%
plotly::add_trace(y = y_left, name = quo_name(y_left),
yaxis = "y1", type = 'scatter', …Run Code Online (Sandbox Code Playgroud) 有一个lm对象,我需要根据其表示为字符向量的变量创建一个函数。我尝试结合使用eval和expr创建一个f功能,该功能将进一步用于后者obj并对其进行nlm优化。
library(tidyverse)
df <- drop_na(airquality)
model <- lm(Ozone~. - Temp, data = df, x=TRUE, y=TRUE)
base_vars <- all.vars(formula(model)[-2])
k <- length(base_vars)
f <- function(base_df, x, y, parms) {
with(base_df, parms[1] +
eval(expr(paste(paste(paste0('parms[', 2:(k+1), ']'), base_vars, sep = '*'), collapse = '+'))) +
log(parms[k+2] * (x - parms[k+3] ^ 2)))
}
obj <- function(parms, y, x) mean((residuals(model) - f(df, x, y, parms))^2)
fit <- with(data, nlm(obj, c(0, 0, 0, …Run Code Online (Sandbox Code Playgroud)