-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRLiterativaReg_ArianaLopez.py
More file actions
executable file
·59 lines (50 loc) · 1.5 KB
/
RLiterativaReg_ArianaLopez.py
File metadata and controls
executable file
·59 lines (50 loc) · 1.5 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
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)
X_scaler = preprocessing.StandardScaler().fit(X_train)
Y_scaler = preprocessing.StandardScaler().fit(Y_train)
Xscaler = X_scaler.transform(X_train)
Yscaler = Y_scaler.transform(Y_train)
Xscaler = pd.DataFrame(Xscaler)
Yscaler = pd.DataFrame(Yscaler)
print(Xscaler, Yscaler)
def salida (w0, W, Xa):
Ysal = w0
for k in range(len(W)):
Ysal = Ysal + (W[k] * Xa[k])
return Ysal
def entrena(w0, W, X, y, nu):
for i in range(len(X)):
Xa = X.ix[i]
sal = salida(w0, W, Xa)
error = y.ix[i] - sal
w0 = w0 + (nu * error)
for j in range(len(Xa)):
W[j] = W[j] + (nu * error * X.ix[i][j])
return w0, W
nu = 0.01
w0 = (rnd.random())
W = [rnd.random()]
print(entrena(w0, W, Xscaler, Yscaler, nu))
Ygorro = w0 + (Xscaler * W[0])
print(Ygorro)
plt.scatter(Xscaler[0], Yscaler[0])
plt.plot(Xscaler[0], Ygorro, color = "red")
plt.show() #para que se muestre la tabla