polynomials

NumPy Polynomial Fitting

NumPy Polynomial Fitting Question: I have the following lines of code import numpy as np from numpy.polynomial import Polynomial x=Polynomial.fit([0,1,2,3,4],[0,1,2,3,4],4) print(x) print(x.call(0)) I would expect numpy to fit the data to the polynomial f(x)=x. But instead it outputs 2.0 + 2.0 x + (1.2915422e-15) x2 – (7.05812123e-16) x3 – (9.57512621e-17) x**4. Even stranger when i …

Total answers: 1

Why are my numpy polyfit results not realistic?

Why are my numpy polyfit results not realistic? Question: I use the following code to fit a 2 degree polynomial to my 2D data: deg = 1 fig, ax = plt.subplots(1,facecolor="white") fig.set_size_inches(5,4) x = [0.843291,0.873922,0.903581,0.93344,0.961478,0.990968, 1.019434,1.047562,1.075373,1.102883,1.130106,1.157059, 1.183751,1.210195,1.236399,1.262376,1.288134,1.313679, 1.339022,1.364167,1.389123,1.413896,1.438492,1.462916, 1.505685,1.57998,1.690303,1.730423,1.761613,1.791332, 1.63034,1.652749,1.675848,1.698821,1.721672,1.744402] y = [291000000,291000000,292000000,291000000,290000000,290000000, 290000000,290000000,289000000,289000000,288000000,288000000, 288000000,287000000,287000000,287000000,287000000,286000000, 286000000,286000000,285000000,285000000,284000000,284000000, 284000000,283000000,283000000,282000000,282000000,281000000, 280000000,280000000,279000000,278000000,277000000,277000000] ax.scatter(x, y,label = "data", c="black", alpha = …

Total answers: 1

ValueError: x and y must have same first dimension, but have different shapes

ValueError: x and y must have same first dimension, but have different shapes Question: I am currently trying to fit some measurement data into three polynomial functions of the degrees 1, 2, and 3. My code is as follows: ylist = [81, 50, 35, 27, 26, 60, 106, 189, 318, 520] y = np.array(ylist) t …

Total answers: 1

Adding a 2nd order polynomial trend line px.scatter

Adding a 2nd order polynomial trend line px.scatter Question: I have a data (a lot of rows in a dataframe) and was able to generate a linear trend line. I want also to add to the plot 2nd order polynomial trend line. How can this be done? thanks this is the code only on one …

Total answers: 1

Open parenthesis of sympy Mul

Open parenthesis of sympy Mul Question: I have the following expression multiplying two expressions: from sympy import * c1, c2, x = symbols("c1, c2, x") expr = c2*x*(c1*x + c2*x) I would like to be able to open the parenthesis, so that this expression would be c1*c2*x**2 + c2**2*x**2 I need this because I want …

Total answers: 1

Manipulating sympy polynomial

Manipulating sympy polynomial Question: I have a polynomial with multiple variables, for example: 2c1^2*c2*x^3+c2*x represented in python by Poly(2*c1**2*c2*x**3 + c2*x, c1, c2, x, domain=’ZZ’) I would like to iterate over the monomials, and each time I find "c1^2", divide this monomial by c1*x. For the example above, the result should be: 2c1*c2*x^2+c2*x represented in …

Total answers: 2

how to plot the decision boundary of a polynomial logistic regression in python?

how to plot the decision boundary of a polynomial logistic regression in python? Question: I have looked into the example on this website: https://scipython.com/blog/plotting-the-decision-boundary-of-a-logistic-regression-model/ I understand how they plot the decision boundary for a linear feature vector. But how would I plot the decision boundary if I apply from sklearn.preprocessing import PolynomialFeatures … poly = …

Total answers: 2

Integral of a Polynomial in Python

Integral of a Polynomial in Python Question: How would we write a function in python that returns the definite integral of a polynomial between two points (X_1 and X_2)? The function takes 3 arguments: a list A of polynomial coefficients (i.e. for polynomial f(x)=5x^4−2x+1, this list becomes A=[5,0,0,−2,1]) a real number X_1 a real number …

Total answers: 3