- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这段代码:
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import Ridge
X = 'some_data'
y = 'some_target'
penalty = 1.5e-5
A = Ridge(normalize=True, alpha=penalty).fit(X, y)
触发以下警告:
FutureWarning: 'normalize' was deprecated in version 1.0 and will be removed in 1.2.
If you wish to scale the data, use Pipeline with a StandardScaler in a preprocessing stage. To reproduce the previous behavior:
from sklearn.pipeline import make_pipeline
- model = make_pipeline(StandardScaler(with_mean=False), Ridge())
If you wish to pass a sample_weight parameter, you need to pass it as a fit parameter to each step of the pipeline as follows:
kwargs = {s[0] + '__sample_weight': sample_weight for s in model.steps}
model.fit(X, y, **kwargs)
Set parameter alpha to: original_alpha * n_samples.
warnings.warn(
Ridge(alpha=1.5e-05)
但是这些代码给了我完全不同的系数,正如预期的那样,因为归一化和标准化是不同的。
B = make_pipeline(StandardScaler(with_mean=False), Ridge(alpha=penalty))
B[1].fit(B[0].fit_transform(X), y)
输出:
A.coefs[0], B[1].coefs[0]
(124.87330648168594, 125511.75051106009)
如果我设置 alpha = penalty * n_features
结果仍然不匹配。
输出:
A.coefs[0], B[1].coefs[0]
(124.87330648168594, 114686.09835548172)
尽管 Ridge()
使用的归一化与我预期的有点不同:
the regressor X will be normalized by subtracting mean and dividing byl2-norm
那么使用带归一化的岭回归的正确方法是什么?
考虑到 l2-norm 看起来像是预测后得到的,数据再次修改和拟合
在使用 sklearn 的岭回归的情况下,我没有想到任何事情,尤其是在 1.2 版本之后
准备 data用于实验:
url = 'https://drive.google.com/file/d/1bu64NqQkG0YR8G2CQPkxR1EQUAJ8kCZ6/view?usp=sharing'
url = 'https://drive.google.com/uc?id=' + url.split('/')[-2]
data = pd.read_csv(url, index_col=0)
X = data.iloc[:,:15]
y = data['target']
最佳答案
不同之处在于,使用normalize=True
报告的系数将直接应用于未缩放的输入,而流水线方法将其系数应用于模型的输入,哪些是缩放后的特征。
您可以通过乘以/除以特征的标准差来“归一化”(不幸的是该词重载)系数。连同 future 警告中建议的惩罚更改,我得到了相同的输出:
np.allclose(A.coef_, B[1].coef_ / B[0].scale_)
# True
(我已经使用 sklearn.datasets.load_diabetes
进行了测试。)
关于python - 如何重现 Ridge(normalize=True) 的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73583687/
这两种方法似乎都完成了从字符串中删除重音符号的相同工作,但我不确定是否存在一些内部差异,可以使一种方法优于另一种方法 最佳答案 分解处理的不仅仅是重音(在 Unicode 中称为标记),例如韩文音节
我在尝试绘制一些数据时收到此错误: findfont: Font family ['STIXGeneral'] not found. Falling back to DejaVu Sans. Trac
我理解规范化和规范化意味着删除数据表示中任何无意义或模棱两可的部分,将有效相同的数据转换为实际相同的数据。 例如,如果您想获取某些输入数据的哈希值,并且其他任何人对规范的相同数据进行哈希处理都获得相同
#!/usr/local/bin/perl use warnings; use 5.014; use Unicode::Normalize qw(NFD NFC compose); my $strin
我正在尝试将包含“áéíóú”等字符的字符串规范化为“aeiou”以简化搜索。 在对 this question 的回复之后我应该使用 Normalizer 类来完成它。 问题是 normalize
我正在尝试获取外语文本并输出人类可读、文件名安全的等效文本。环顾四周后,似乎最好的选择是 unicodedata.normalize(),但我无法让它工作。我试过将一些答案的确切代码放在这里和其他地方
我是 pymc 和贝叶斯统计的新手。在这里,我试图实现一个极其简单的 pymc 模型,以便与理论结果进行比较。在我的测试用例中,我假设正常先验为 mu~N(20,20) 并且可能性假设为 data~N
我正在编写一个 XPath 表达式,但我修复了一个奇怪的错误,但是以下两个 XPath 表达式之间有什么区别? "//td[starts-with(normalize-space()),'Posted
tf.random.normal 和 tf.distributions.Normal 有什么区别?或者 tf.distributions.Multinomial 和 tf.random.multino
第一步: xcodebuild -project Pods/Pods.xcodeproj build 第二个: xcodebuild archive -project 'test.xcodeproj'
我正在将 Adobe Xd 中的设计转换为 HTML 模板,其中一个元素建议使用以下 css 规则。 top: 149px; left: 54px; width: 463px; height: 2
我正在与另一位数据库设计人员就规范化进行有趣的讨论。在这个例子中,我们有一个 GameTitles 表,每条记录都必须包含游戏发布的年份。他说 2NF 要求所有内容都必须规范化,因此,要符合要求,年份
我正在尝试在 python 中加载文件。如果您运行下面的代码并加载仅包含英文单词的文件,它将加载得很好。 Listado.txt 是一个西类牙语文件,包含以下单词:abacá、abadí、abadía
我一个月前完成了这个游戏,直到今天一切都很好。我在线收到错误: odgovorNormalized = Normalizer.normalize(konResenje, Normalizer.Form
我正在使用gnutls aes加密,这是我的代码 const gnutls_datum_t * key; *key = (const char*)"tZOVP7o/u2vQB+4B/0O0ZqLWvy
我正在尝试训练一个用于面部性别和年龄检测的 cnn 模型。我的训练集包含彩色和灰度的面部图像。我如何标准化这个数据集?或者如何处理混合了灰度和彩色图像的数据集? 最佳答案 请记住,网络只会尝试了解您的
这是 DB 规范化理论中的一个概念: Third normal form is violated when a non-key field is a fact about another non-ke
我正在存储有关棒球统计数据的数据,并希望使用三个表来存储:players、battingStats 和 pitchingStats。就问题而言,每个球员都会有击球统计数据或投球统计数据,但不会两者都有
我现在正在学习推力。我有一个问题:如何用推力进行归一化? 我有一个有效的代码,但我想知道这是否是最佳方法。 struct square { __host__ __device__ float oper
所以我知道我自己可以如何解决这个问题,但是有人知道任何可以处理这个问题的现有库吗? (无论什么语言)? 最佳答案 此 API 仅支持英文,并具有职称规范化:http://api.dataatwork.
我是一名优秀的程序员,十分优秀!