This commit is contained in:
mjjo
2018-08-14 17:22:50 +09:00
parent e3bf92dab2
commit 6bec719ce3
2 changed files with 10 additions and 7 deletions

View File

@@ -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

View File

@@ -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)