# -*- coding: utf-8 -*-
'''
Created on 2018年1月24日
@author: Jason.F
@summary: 有监督回归学习-基于最小二乘法构建线性回归模型
最小二乘法(Ordinary Least Square,LOS),估计回归曲线的参数,使得回归曲线到样本点垂直距离(残差或误差)的平方和最小
'''
import pandas as pd
import numpy as np
import time
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
def lin_regplot(X,y,model):
plt.scatter(X,y,c='blue')
plt.plot(X,model.predict(X),color='red')
return None
'''
class LinearRegressionGD(object):
def __init__(self,eta=0.01,n_iter=20):
self.eta=eta
self.n_iter=n_iter
def fit(self,X,y):
self.w_=np.zeros(1+X.shape[1])
self.costs_=[]
for _ in range(self.n_iter):
output=self.net_input(X)
errors=(y-output)
self.w_[1:] += se