-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetodoDinamico.py
More file actions
executable file
·86 lines (71 loc) · 1.87 KB
/
MetodoDinamico.py
File metadata and controls
executable file
·86 lines (71 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import random
from random import sample
import random as rnd
import sys
import os
import winpython
import pip
import sklearn
from sklearn.naive_bayes import GaussianNB
import pandas as pd
import csv
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import train_test_split
from sklearn import preprocessing
from matplotlib import pyplot
import matplotlib.pyplot as plt
import numpy as np
df = pd.read_csv("regLin.csv")
print (df)
X_train, X_test, Y_train, Y_test = train_test_split(df[["X"]],df[["y"]], train_size=.75)
Y_tra = Y_train['y'].values.tolist()
X_tra = X_train['X'].values.tolist()
Y_tes = Y_test['y'].values.tolist()
X_tes = X_test['X'].values.tolist()
scaleX = preprocessing.StandardScaler()
scaleY = preprocessing.StandardScaler()
scaleX.fit(X_tra)
X_train=scaleX.transform(X_tra)
scaleY.fit(Y_tra)
Y_train=scaleY.transform(Y_tra)
scaleX.fit(X_tes)
X_train=scaleX.transform(X_tes)
scaleY.fit(Y_tes)
Y_train=scaleY.transform(Y_tes)
nu = .0001
numX = len(X_tra)
ListWo= []
ListW= []
ListYest= []
ListErrora= []
ListYpred = []
w = rnd.random()
w0 = rnd.random()
clf = LinearRegression()
for j in range(numX):
w_sum = (w * X_tra[j])
y_est = w_sum + w0
errora = Y_tra[j] - y_est
print(w0,w,y_est,errora)
ListWo.append(w0)
ListW.append(w)
ListYest.append(y_est)
ListErrora.append(errora)
w = w + nu*(errora*X_tra[j])
w0 = w0 + nu*errora
print('\n')
print("y_est",y_est)
print("wo",w0)
print("w1",w)
print("error",errora)
print('\n')
for i in range(numX):
Ypred = w0+ w*X_tra[i]
ListYpred.append(Ypred)
plt.scatter(X_tra,Y_tra,color='red')
plt.scatter(X_tes,Y_tes,color='black')
plt.scatter(X_tra,ListErrora,color="yellow")
plt.scatter(X_tra,ListYpred,color='darkblue')
plt.show()
#plt.scatter(X_tra,Ypred,color='blue')
#plt.show()