Predictive model Flashcards

1
Q

Predictive model
- Train and test

A

x = [scegli 15 valori]
y = [scegli 15 valori]
n_valori = 10

x_train = x[:n_valori]
y_train = y[:n_valori]

x_test = x[n_valori:]
y_test = y[n_valori:]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Predictive model
- equazione linea

A

def linea(x,m,c):
return (x*m)+c

plt.plot(linea(x,0.2,0))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Predictive model
- Model

A

def show_plot(y_train, model):
if len(y_train!=model):
print(“they need to be the same size”)
size = len(y_train)
x = np.arange(size)
plt.scatter(x,y_train)
plt.plot(x,model)
plt.show

model=linea(x_train,1,0)

show_plot(y_train, model)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Predictive model
- Model evaluation

A

def square_error(y,model):
error = y - model
sq_e = error **2
return sum(sq_e)

print(‘square error: ‘,square_error(y_train,linea(x,1,0)))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Predictive model
- Fit the model + data

A

steps = 200
epsilon = 0.01

def fit(y_train,m,c,steps,epsilon):
model = linea(-x,1,0)
sq_e = square_error(y_train, model)
for i in range(steps):
m1 = m + np.random.choice([-1,1],size=1)epsilon
c1 = m + np.random.choice([-1,1],size=1)
epsilon
model1 = linea(-x,1,0)
sq:e1 = square_error(y_train, model1)
if sq_e1<sq_e:
m = m1
c = c1
sq_e = sq_e1
return m,c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly