Last active
May 21, 2018 02:08
-
-
Save b00033811/76f474f3bbe1394e1b76d1e7f6733747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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