小编Ton*_*oni的帖子

使用R进行多类逻辑回归

短格式:

如何通过R中的梯度下降实现多类Logistic回归分类算法?可optim()当有两个以上的标签可以用吗?

MatLab代码是:

function [J, grad] = cost(theta, X, y, lambda)
    m = length(y);
    J = 0;
    grad = zeros(size(theta));
    h_theta = sigmoid(X * theta);
    J = (-1/m)*sum(y.*log(h_theta) + (1-y).*log(1-h_theta)) +...
    (lambda/(2*m))*sum(theta(2:length(theta)).^2);
    trans = X';
    grad(1) = (1/m)*(trans(1,:))*(h_theta - y);
    grad(2:size(theta, 1)) = 1/m * (trans(2:size(trans,1),:)*(h_theta - y) +...
    lambda * theta(2:size(theta,1),:));
    grad = grad(:);
end
Run Code Online (Sandbox Code Playgroud)

和...

function [all_theta] = oneVsAll(X, y, num_labels, lambda)
    m = size(X, 1);
    n = size(X, 2);
    all_theta = zeros(num_labels, n + 1); …
Run Code Online (Sandbox Code Playgroud)

matlab r gradient-descent logistic-regression

13
推荐指数
1
解决办法
5192
查看次数

Python中的理解来从列表中对元组进行采样

我试图[-4, -2, 1, 2, 5, 0]使用理解从列表中获取三元素元组的列表,并检查它们是否满足条件sum([] == 0).以下代码有效.但是,毫无疑问,应该有一种更容易,更优雅的方式来表达这些理解:

[
    (i, j, k) for i in [-4, -2, 1, 2, 5, 0]
              for j in [-4, -2, 1, 2, 5, 0]
              for k in [-4, -2, 1, 2, 5, 0] if sum([i, j, k]) == 0
]
Run Code Online (Sandbox Code Playgroud)

输出:

[(-4, 2, 2), (-2, 1, 1), (-2, 2, 0), (-2, 0, 2), (1, -2, 1), 
 (1, 1, -2), (2, -4, 2), (2, -2, 0), (2, 2, -4), (2, 0, …
Run Code Online (Sandbox Code Playgroud)

python tuples list-comprehension list

12
推荐指数
1
解决办法
377
查看次数

如何控制Markdown中引用文本的字体大小

与其他(未引用的)文本相比,Markdown上的引用文本字体通常太大.这是一个例子: 在此输入图像描述

用RStudio生成的

#####Intution:

> **[Identification of an MA model is often best done with the ACF rather
> than the PACF]((https://onlinecourses.science.psu.edu/stat510/node/62))**.
> 
> For an MA model, the theoretical PACF does not shut off, but instead
> tapers toward 0 in some manner.  A clearer pattern for an MA model is
> in the ACF.  The ACF will have non-zero autocorrelations only at lags
> involved in the model.
> 
> A moving average term in a time series model …
Run Code Online (Sandbox Code Playgroud)

markdown r rstudio

11
推荐指数
2
解决办法
1711
查看次数

在PowerShell错误消息中使用touch命令创建新文件

我的桌面上有一个使用PowerShell创建的目录,现在我正在尝试在其中创建一个文本文件.

我确实将目录更改为新目录,然后键入touch textfile.txt.

这是我收到的错误消息:

touch : The term 'touch' is not recognized as the name of a cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a path was 
included, verify that the path is correct and try again.

At line:1 char:1
+ touch file.txt
+ ~~~~~
+ CategoryInfo          : ObjectNotFound: (touch:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException`
Run Code Online (Sandbox Code Playgroud)

为什么不起作用?我是否必须一直使用Git Bash?

git powershell

9
推荐指数
6
解决办法
2万
查看次数

如何使用Python 2.7在itertools中提供zip_longest

当试图在Windows 10上运行的Python Jupyter 2.7 nb上导入此函数时,我收到此错误:

在此输入图像描述

我相信我过去没有遇到任何问题,因为我使用的是Python 3.所以我想知道它是否只是在Python 2中不可用,或者是否有一种方法可以使它工作.

python python-itertools python-2.7

8
推荐指数
2
解决办法
8094
查看次数

谷歌colab更改代码单元中各处的变量名称

当我在 colab 中突出显示单元格内的变量时,该变量的所有实例都会亮起。

在此输入图像描述

是否可以同时更改变量的所有这些实例?如果可以,如何更改?

python google-colaboratory

7
推荐指数
1
解决办法
7126
查看次数

如何在嵌入 3D 的表面上绘制测地线曲线?

我想到了这个视频,或者这个模拟,我想在 3D 中重现某种表面上的测地线,由函数 f(x,y) 从某个起点给出。

中点法似乎计算和代码激烈,所以我想问一下如果有基于在不同的点法向量表面近似测曲线的方法。每个点都有一个与之相关的切向量空间,因此,似乎知道法向量并不能确定向前移动曲线的特定方向。

我曾尝试使用 Geogebra,但我意识到可能需要转移到其他软件平台,例如 Python(或 Poser?)、Matlab 或其他平台。

这个想法可行吗,我能得到一些关于如何实施它的想法吗?


如果它提供了一些关于如何回答问题的想法,之前有一个答案(现在不幸被删除)建议使用函数形式 z = F(x,y) 的地形的中点方法,从之间的直线开始端点,分裂成短段[我假设 XY 平面 (?) 上的直线],并在表面上提升 [我假设 XY 平面 (?) 上的段之间的节点]。接下来它建议找到“一个中点”[我猜是连接表面上每对连续投影点对的线段的中点(?)],并投影“它”[我猜这些中点中的每一个都接近,但不完全在表面(?)] 正交于表面(法线方向),使用方程 Z + t = F(X + t Fx, Y + t Fy) [我猜这是一个点积意味着为零...

在此处输入图片说明

(?)],其中 (X,Y,Z) 是中点的坐标,Fx,Fy 是 F 的偏导数,t 是未知数 [这是我理解这个的主要问题......我应该怎么做一旦我找到它?将其添加到 (X,Y,Z) 的每个坐标中,如 (X+t, Y+t, Z+t)?进而?]。这是 t 中的非线性方程,通过牛顿迭代求解。


作为更新/书签,Alvise的Vianello慷慨公布的启发上测地线Python的计算机模拟页面在GitHub上。非常感谢!

python matlab geometry computational-geometry geometry-surface

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

ggplot有多条回归线来显示随机效应

我知道这个这个帖子.但是,当我尝试以下操作时,我似乎没有得到预期的结果:

数据可以直接从这里加载.这个想法是在一个完全虚构的数据集,葡萄糖在血液中不同种族的完成水平几个运动员将取决于一些虚构的氨基酸(AAA):

在此输入图像描述

对情节的呼吁是:

ggplot(df, aes(x = AAA, y = glucose, color=athletes)) +  
  geom_point() + geom_smooth(method="lm", fill=NA)
Run Code Online (Sandbox Code Playgroud)

而且我希望每个运动员得到不同的线,而不是单一的回归线.我的想法是得到类似的东西这个.

plot r linear-regression ggplot2

5
推荐指数
1
解决办法
865
查看次数

在 Python 中使用列名构建 DataFrame

在尝试熟悉 Python 中的 DataFrame 时,我陷入了以下步骤......

我尝试从数组创建一个数据框:

from numpy import *
import pandas as pd

dat = array([[0.3888888888888889, 0.3888888888888889, 0.3888888888888889, 0.436943311456892, 0.7905900031193156, 0.5020468092219706, 0.8389717734280283, 0.7604923090797432, 0.8206054422776056, '0'],
[0.3888888888888889, 0.3888888888888889, 0.2222222222222222, 0.4457200178477334, 0.8114779465247448, 0.506899600792241, 0.8368566485573798, 0.760617288778523, 0.8195489478905984, '1'],
[0.2777777777777778, 0.2777777777777778, 0.05555555555555555, 0.4426231291814084, 0.7883413226205706, 0.5037172133121759, 0.8370362549229062, 0.7599752704033258, 0.8184218722901648, '2'],
[0.1111111111111111, 0.1111111111111111, 0.16666666666666666, 0.4651807845446571, 0.7983379003654792, 0.5250604537887904, 0.8463875215362144, 0.7533582308429306, 0.8241548325954007, '3'],
[0.5000000000000001, 0.5000000000000001, 0.3333333333333333, 0.4457200178477334, 0.7878040593905666, 0.506899600792241, 0.8368566485573798, 0.7605016058324149, 0.8195489478905984, '4'],
[0.3888888888888889, 0.3888888888888889, 0.2222222222222222, 0.44943322185630036, 0.7843622888520198, 0.5055757644148106, 0.8351253941103399, 0.7604171267769607, 0.8185442945328569, '5'],
[0.3888888888888889, 0.3888888888888889, 0.3333333333333333, 0.4424914587425397, …
Run Code Online (Sandbox Code Playgroud)

python arrays dataframe pandas

5
推荐指数
1
解决办法
2万
查看次数

为什么我在 Matlab 和 Octave(以及 Matlab 内)中得到相同代码的不同版本?

在此输入图像描述

对于上下文,这是引发此问题的原始帖子。

这是代码(请注意,我按原样包含了代码,尽管绘图是通过在模拟开始运行时从图形窗口中 x-ing 生成的,并让程序自动打开没有曲面的新窗口):

    x = linspace(-1.5,1.5);
    y = linspace(-1,1);
    [x,y] = meshgrid(x,y);
    z = 0.5 *y.*sin(5 * x) - 0.5 * x.*cos(5 * y)+1.5; 
    S = [x;y;z];
    h = surf(x,y,z)
    zlim([0 8])
    set(h,'edgecolor','none')
    colormap('gray');
    axis off
    hold on

    f = @(x,y) 0.5 *y.* sin(5 * x) - 0.5 * x.*cos(5 * y)+1.5;     % The actual surface

    dfdx = @(x,y) (f(x + eps, y) - f(x - eps, y))/(2 * eps); % ~ partial f wrt x
    dfdy = …
Run Code Online (Sandbox Code Playgroud)

algorithm matlab plot octave

5
推荐指数
0
解决办法
131
查看次数