-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLinRegLearner.py
More file actions
executable file
·86 lines (67 loc) · 5.12 KB
/
LinRegLearner.py
File metadata and controls
executable file
·86 lines (67 loc) · 5.12 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
# coding=utf-8
""""""
"""
A simple wrapper for linear regression. (c) 2015 Tucker Balch
Copyright 2018, Georgia Institute of Technology (Georgia Tech)
Atlanta, Georgia 30332
All Rights Reserved
Template code for CS 7646
Georgia Tech asserts copyright ownership of this template and all derivative
works, including solutions to the projects assigned in this course. Students
and other users of this template code are advised not to share it with others
or to make it available on publicly viewable websites including repositories
such as github and gitlab. This copyright statement should not be removed
or edited.
We do grant permission to share solutions privately with non-students such
as potential employers. However, sharing with other current or future
students of CS 7646 is prohibited and subject to being investigated as a
GT honor code violation.
-----do not edit anything above this line---
"""
import numpy as np
class LinRegLearner(object):
"""
This is a Linear Regression Learner. It is implemented correctly.
:param verbose: If “verbose” is True, your code can print out information for debugging.
If verbose = False your code should not generate ANY output. When we test your code, verbose will be False.
:type verbose: bool
"""
def __init__(self, verbose=False):
"""
Constructor method
"""
pass # move along, these aren't the drones you're looking for
def author(self):
"""
:return: The GT username of the student
:rtype: str
"""
return "tb34" # replace tb34 with your Georgia Tech username
def add_evidence(self, data_x, data_y):
"""
Add training data to learner
:param data_x: A set of feature values used to train the learner
:type data_x: numpy.ndarray
:param data_y: The value we are attempting to predict given the X data
:type data_y: numpy.ndarray
"""
# slap on 1s column so linear regression finds a constant term
new_data_x = np.ones([data_x.shape[0], data_x.shape[1] + 1])
new_data_x[:, 0: data_x.shape[1]] = data_x
# build and save the tree
self.model_coefs, residuals, rank, s = np.linalg.lstsq(
new_data_x, data_y, rcond=None
)
def query(self, points):
"""
Estimate a set of test points given the tree we built.
:param points: A numpy array with each row corresponding to a specific query.
:type points: numpy.ndarray
:return: The predicted result of the input data according to the trained tree
:rtype: numpy.ndarray
"""
return (self.model_coefs[:-1] * points).sum(axis=1) + self.model_coefs[
-1
]
if __name__ == "__main__":
print("the secret clue is 'zzyzx'")