I used sklearn in python to fit polynomial functions:
from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression poly = PolynomialFeatures(degree=2, include_bias=False) poly_reg_model = LinearRegression() poly_features = poly.fit_transform(xvalues.reshape(-1, 1)) poly_reg_model.fit(poly_features, y_values) final_predicted = poly_reg_model.predict(poly_features) ...
Instead of only using x^n parts, I want to incude a (1-x^2)^(1/2) part in the fit-function. Is this possible with sklearn?
I tried to define a Feature which includes more complex terms but I falied to achieve this.
CodePudding user response:
No idea whether it is possible within scikitlearn - after all polynomial fit is constrained to specific polynomial formulations from the mathematical stanndpoint. If you want to fit a formula with some unknown parameters, you can use
So now you can use f_opt(new_x, *popt)
to predict new points (alternatively you can print the values and hard-code them). popt
basically has the parameters that you specify in f_opt
except x
- for more details check the documentation I've linked!