Skip to content

Instantly share code, notes, and snippets.

@b00033811
Last active May 21, 2018 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b00033811/76f474f3bbe1394e1b76d1e7f6733747 to your computer and use it in GitHub Desktop.
Save b00033811/76f474f3bbe1394e1b76d1e7f6733747 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
def fit_transform_poly(x,w,n,b):
'''Evaluates f=W*x^n+b'''
p_Matrix=[]
for weights,power in zip(w,n):
p_Matrix.append([weights*x**power for x in x])
return [sum(i)+b for i in zip(*p_Matrix)]
coef=[1,-.1] # Define the Poly. Weights.
power=[1,2] # Define the order of the Polynomial
bias=0 # Define the bias
n_samples=100
x=np.linspace(0,5,n_samples) # Create linear space of 100 points between (0,5).
std=0.3 # Standard deviation of the noise.
e=np.random.normal(0,std,len(x)) # Generate noise.
assert len(coef)==len(power), " The number of coef. (W)\
must equal the power (n)"
f=fit_transform_poly(x,coef,power,bias) + e #Eval. the poynomial and add noise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment