-
Notifications
You must be signed in to change notification settings - Fork 0
/
proy1.py
60 lines (52 loc) · 1.53 KB
/
proy1.py
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
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import glob
from sklearn import linear_model
from sklearn.metrics import r2_score
"""
AUTOR:
Team Oyentes
"""
"""
-- Lectura de los datos de entrenamiento
"""
df = pd.read_csv(
'/home/urb/PycharmProjects/Machine_Learning/Data/P1/BlogFeedback/blogData_train.csv',
header=None)
DATA = df.as_matrix()
X = DATA[:, :-1]
Y = DATA[:, -1]
"""
-- Instancias de los modelos de regresión, utilizando los dos tipos de regularización
y elasticNet que es la combinación de los dos
"""
model = linear_model.Ridge(alpha=0.01, normalize=True)
model2 = linear_model.Lasso(alpha=0.01, normalize=True)
model3 = linear_model.ElasticNet(alpha=0.01, normalize=True)
"""
-- Entrenamiento de los modelos utilizando el dataset de training
"""
model.fit(X, Y)
model2.fit(X, Y)
model3.fit(X, Y)
dir_test = glob.glob(
'/home/urb/PycharmProjects/Machine_Learning/Data/P1/BlogFeedback/blogData_test*')
"""
-- Prediccion del testing
"""
for path in dir_test:
df_test = pd.read_csv(path, header=None)
DATA_T = df_test.as_matrix()
X_test = DATA_T[:, :-1]
Y_test = DATA_T[:, -1]
y_predict1 = model.predict(X_test)
y_predict2 = model2.predict(X_test)
y_predict3 = model3.predict(X_test)
"""
Medida R cuadrada, la más óptima es 1.
"""
print("Model 1; metric R square, ", r2_score(Y_test, y_predict1))
print("Model 2; metric R square, ", r2_score(Y_test, y_predict2))
print("Model 3; metric R square, ", r2_score(Y_test, y_predict3))
print("")