Lab3. Normal Equation 코드 관련 문의드립니다.
198
작성한 질문수 2
아래와 같이 작성하여 Lab 설명 내용대로 테스트해보면
결과는 테스트 내용과 동일하게 나옵니다.
헌데, 퀴즈를 제출하면 모두 Fail로 표시되어 문의드립니다.
class LinearRegression(object): def __init__(self, fit_intercept=True, copy_X=True):
self.fit_intercept = fit_intercept
self.copy_X = copy_X
self._coef = None
self._intercept = None
self._new_X = None
def fit(self, X, y):
self.X = np.array(X)
self.y = np.array(y).reshape(-1, 1)
if self.fit_intercept == True:
self.X = np.concatenate((np.ones((len(self.X), 1)), np.array(self.X).reshape(len(self.X), -1)), axis=1)
self._intercept = np.linalg.inv(self.X.T.dot(self.X)).dot(self.X.T).dot(y)[0]
self._coef = np.linalg.inv(self.X.T.dot(self.X)).dot(self.X.T).dot(y)[1:]
return self
def predict(self, X):
self.X = np.array(X)
if self.fit_intercept == True:
self.X = np.concatenate((np.ones((len(self.X), 1)), np.array(self.X).reshape(len(self.X), -1)), axis=1)
return self.X.dot(np.concatenate((np.array([self._intercept]), self._coef)).reshape(-1, 1))
@property
def coef(self):
return self._coef
@property
def intercept(self):
return self._intercept
답변 2
0
X 를 매트릭스로 만드셔야 되는데 Y를 매트릭스로 만드신것 같네요.
그리고 self._intercept = np.linalg.inv(self.X.T.dot(self.X)).dot(self.X.T).dot(y)[0]
여기서 X.T * Y 를 하실때 () 를 치셔야 따로따로 곱해지지않고 둘이 곱해진상태에서 X.T * X 를 곱해지는것 같아요.
그 외에는 딱히 제가 찾을수 있는게 없어보이네요
environment setup - windows 사용자는 어떻게
0
214
0
Chapter 10에 대한 강의안이 없는것 같습니다.
0
287
0
이게 이렇게 어려운 이유가 뭐죠?
0
232
0
Python 코드 실행을 위한 코드 다운로드 관련
0
252
1
matrix product문제 질문 드립니다.
0
222
0
강의자료중 코드는 다운로드 안 되나요?
0
192
0
scikit-learn preprocessing 할때 Data Frame object has no attribute 'as matrix'라는 오류가 뜹니다
0
351
1
pdf 강의자료 다운로드 관련
0
214
1
과제 제출 시 위 에러가 나옵니다. 어떻게 해야 하나요?
0
228
1
Gradient Boosting에서 Light GBM, XGBOOST
0
331
1
np.where 값 리턴
0
305
1
숙제 제출 오류
0
218
1
다른분들이 짠 코드를 볼수있을까요?
0
205
1
house data 전처리 코드 관련 질문
0
684
1
설치이후 Pandas import 문제
0
1629
2
import sklearn import preprocessing 부터 에러가 납니다.
0
389
2
엑셀 파일 생성이 안됩니다.
0
489
2
딥러닝 강좌 관련해서 질문올립니다.
0
214
1
ch11 강의 코드
0
216
0
코드를 볼수 가 없어요
0
272
0
소스코드
0
171
1
질문있습니다
0
149
1
deactivate 가 되지 않는 경우
0
254
1
kaggle_titanic_pclass one-hot encoding에 대해 질문드립니다.
0
161
0





