- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我知道可以使用以下方法获取多项式特征作为数字:polynomial_features.transform(X)
。根据manual ,对于二度的特征是:[1, a, b, a^2, ab, b^2]
。但是我如何获得高阶特征的描述呢? .get_params()
不显示任何功能列表。
最佳答案
顺便说一句,现在有更合适的功能: PolynomialFeatures.get_feature_names .
from sklearn.preprocessing import PolynomialFeatures
import pandas as pd
import numpy as np
data = pd.DataFrame.from_dict({
'x': np.random.randint(low=1, high=10, size=5),
'y': np.random.randint(low=-1, high=1, size=5),
})
p = PolynomialFeatures(degree=2).fit(data)
print p.get_feature_names(data.columns)
这将输出如下:
['1', 'x', 'y', 'x^2', 'x y', 'y^2']
注意出于某种原因,您必须先拟合 PolynomialFeatures 对象,然后才能使用 get_feature_names()。
如果您是 Pandas 爱好者(就像我一样),您可以轻松地构建具有所有新功能的 DataFrame,如下所示:
features = DataFrame(p.transform(data), columns=p.get_feature_names(data.columns))
print features
结果如下所示:
1 x y x^2 x y y^2
0 1.0 8.0 -1.0 64.0 -8.0 1.0
1 1.0 9.0 -1.0 81.0 -9.0 1.0
2 1.0 1.0 0.0 1.0 0.0 0.0
3 1.0 6.0 0.0 36.0 0.0 0.0
4 1.0 5.0 -1.0 25.0 -5.0 1.0
关于python - sklearn : how to get coefficients of polynomial features,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31290976/
有什么区别 https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html 和 https://docs.scipy.o
我不明白为什么 polynomial.Polynomial.fit() 给出的系数与预期的系数非常不同: import numpy as np x = np.linspace(0, 10, 50) y
为什么要 numpy.polyfit 和 numpy.polynomial.polynomial.polyfit 在下面的测试中产生不同的图? import numpy as np from nump
Strassen 的算法在多项式上比 n 次方正则矩阵乘法快。 “多项式更快”是什么意思? 最佳答案 您的问题与“复杂性”的理论概念有关。例如,据说正则矩阵乘法的复杂度为 O(n^3)。这意味着随着维
这三个函数似乎都可以做简单的线性回归,例如 scipy.stats.linregress(x, y) numpy.polynomial.polynomial.polyfit(x, y, 1) x =
我想出了一个新算法来解决 subset sum problem ,我认为是多项式时间。告诉我我要么错了,要么就是个天才。 快速入门事实: 子集和问题是一个 NP 完全问题。在多项式时间内求解它意味着
我有一个非常简单的问题:在我的 python 工具箱中,我必须从一个大向量(大小 >> 10^6)计算多项式的值(通常是 3 或 2 次,很少有其他次数,总是整数次)。将结果存储在缓冲区中不是一种选择
我有一个 Polynomial 类,它有一个 get_vect 成员函数,它将整数存储在一个 vector 中,该 vector 是多项式系数的表示。现在,我正在尝试使用 Multiply 非成员函数
我有一组测量值,我想对其进行近似。我知道我可以用 4 次多项式来做到这一点,但我不知道如何使用 Scilab 找到它的五个系数。 现在,我必须使用 Open office calc 的用户友好功能..
我可以使用 numpy.polynomial 来拟合一维多项式的项,例如 f(x) = 1 + x + x^2。我如何拟合多维多项式,例如 f(x,y) = 1 + x + x^2 + y + yx
我 = 输入 |I| = 输入数 A(I) = P(I) 表示算法A 在输入I. 为什么Time(A, I) <= |I|^2 不适用于小的I? 最佳答案 来自 wiki : ...Since thi
我试图完成我的 junit 测试以找到多项式方法的导数,但我在使其工作时遇到了一些麻烦。这是方法: public Polynomial derivative() { MyDouble a
public String toString(){ String mytoString=""; if(!a.equals(0)){ mytoString = a.toS
public String toString(){ String mytoString=""; if(!a.equals(0)){ mytoString = a.toS
我创建了一个 Polynomial 类,但我想重载索引运算符以用作 setter,例如 myPolyObject[0] = 2.5,但在尝试重载它时出现错误。 class Polynomial { p
因此,我试图为我的多项式数组重载运算符 +,但我不断收到 _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 错误(第 52 行),我无法弄清楚原因。问题一定出在我重载 op
这个问题在这里已经有了答案: Simplest way to make a polynomial regression with sklearn? (2 个答案) polynomial regres
我正在尝试绘制多项式的根,但我就是做不到。 首先我创建多项式 p5 = [1 0 0 0 0 -1] %x^5 - 1 r5 = roots(p5) stem (p5) 我正在使用 stem 函数,但
我想求以下两个常量cons1和cons2的区间我写了下面的代码 from sympy import Poly from sympy import Abs from sympy.solvers.i
所以我有一个类(class)作业是问一个关于复杂性理论的问题,我有一些问题,PRIMES,它在 NPTime 复杂性类中。 到目前为止一切都很好。 让我头疼的是一个计算 (a^p)mod(b) 的多项
我是一名优秀的程序员,十分优秀!