수정
This commit is contained in:
@@ -6,15 +6,15 @@ import pandas as pd
|
||||
|
||||
|
||||
def load_data():
|
||||
df = pd.read_csv('data/sample.txt', delimiter=',', header=None)
|
||||
df[2] = pd.Series([1]*len(df[0]))
|
||||
#df = pd.read_csv('data/sample.txt', delimiter=',', header=None)
|
||||
#df[2] = pd.Series([1]*len(df[0]))
|
||||
|
||||
#df = pd.read_csv('data/ex1data1.txt', delimiter=',', header=None)
|
||||
#df[2] = pd.Series([1]*len(df[0]))
|
||||
|
||||
#df = pd.read_csv('data/train.csv', delimiter=',', comment='#')
|
||||
#df[0] = df['x']
|
||||
#df[1] = df['y']
|
||||
df = pd.read_csv('data/train.csv', delimiter=',', comment='#')
|
||||
df[0] = df['x']
|
||||
df[1] = df['y']
|
||||
|
||||
df[2] = pd.Series([1]*len(df[0]))
|
||||
df = df.reindex(columns=[1, 2, 0])
|
||||
@@ -23,8 +23,10 @@ def load_data():
|
||||
|
||||
def feature_scaling(x):
|
||||
mean = x.mean(0)
|
||||
mean[0] = 0
|
||||
std = x.std(0)
|
||||
std[std==0] = 1
|
||||
std[0] = 1
|
||||
x = (x-mean)/std
|
||||
return x, mean, std
|
||||
|
||||
@@ -40,7 +42,7 @@ x, mean, std = feature_scaling(x)
|
||||
|
||||
sum_ = 0
|
||||
gap = 0.001
|
||||
break_gap = 1.0e-20
|
||||
break_gap = 1.0e-10
|
||||
trycnt = 0
|
||||
while True:
|
||||
h = x@w
|
||||
|
||||
@@ -44,9 +44,10 @@ def get_derived_regularization_term(w: np.array, wlambda: float, alpha: float) -
|
||||
# [5,15+1],
|
||||
# ])
|
||||
|
||||
data = np.loadtxt('data/sample.txt', delimiter=',')
|
||||
#data = np.loadtxt('data/ex1data1.txt', delimiter=',')
|
||||
# train excercize
|
||||
data = np.loadtxt('data/train.csv', delimiter=',', skiprows=1, comments='#')
|
||||
#data = np.loadtxt('data/train.csv', delimiter=',', skiprows=1, comments='#')
|
||||
# auto mpg
|
||||
#df = pd.read_csv('data/auto-mpg.data', sep='\t')
|
||||
#df = df.drop(df.loc[df['horsepower'] == '?'].index)
|
||||
|
||||
Reference in New Issue
Block a user