진행 중
This commit is contained in:
41
linear_regression3.py
Normal file
41
linear_regression3.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
import utility
|
||||||
|
|
||||||
|
df = utility.load_data()
|
||||||
|
y_data = df.values[:, 0]
|
||||||
|
x_data = df.values[:, 1:]
|
||||||
|
m, n = x_data.shape
|
||||||
|
|
||||||
|
|
||||||
|
import tensorflow as tf
|
||||||
|
y = tf.Variable(y_data)
|
||||||
|
x = tf.Variable(x_data)
|
||||||
|
w = tf.Variable(tf.zeros((n, 1)))
|
||||||
|
|
||||||
|
a = 0.1
|
||||||
|
|
||||||
|
#h = tf.matmul(x, w)
|
||||||
|
#cost = tf.reduce_mean(tf.square(h - y))
|
||||||
|
#optimizer = tf.train.GradientDescentOptimizer(a)
|
||||||
|
#train = optimizer.minimize(cost)
|
||||||
|
|
||||||
|
a = tf.Variable([[1], [2], [3]])
|
||||||
|
b = tf.Variable([1,2,3])
|
||||||
|
|
||||||
|
with tf.Session() as sess:
|
||||||
|
sess.run(tf.global_variables_initializer())
|
||||||
|
|
||||||
|
#k = sess.run(a*b)
|
||||||
|
#kk = sess.run(b*a)
|
||||||
|
##kkk = sess.run(tf.matmul(a, b))
|
||||||
|
#kkkk = sess.run(tf.matmul(b, a))
|
||||||
|
|
||||||
|
h = tf.matmul(x, w)
|
||||||
|
cost = tf.reduce_mean((h-y)**2)/2
|
||||||
|
gradient = (h-y)*x
|
||||||
|
|
||||||
|
values = sess.run((h, cost, gradient))
|
||||||
|
|
||||||
|
print(values)
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>db253b3a-f559-48b8-9804-846029a6ebef</ProjectGuid>
|
<ProjectGuid>db253b3a-f559-48b8-9804-846029a6ebef</ProjectGuid>
|
||||||
<ProjectHome>.</ProjectHome>
|
<ProjectHome>.</ProjectHome>
|
||||||
<StartupFile>regression2.py</StartupFile>
|
<StartupFile>linear_regression3.py</StartupFile>
|
||||||
<SearchPath>
|
<SearchPath>
|
||||||
</SearchPath>
|
</SearchPath>
|
||||||
<WorkingDirectory>.</WorkingDirectory>
|
<WorkingDirectory>.</WorkingDirectory>
|
||||||
@@ -25,13 +25,19 @@
|
|||||||
<Compile Include="graph.py">
|
<Compile Include="graph.py">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="regression2.py">
|
<Compile Include="linear_regression3.py">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="regressions.py" />
|
<Compile Include="linear_regression2.py">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="linear_regression.py" />
|
||||||
<Compile Include="test.py">
|
<Compile Include="test.py">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="utility.py">
|
||||||
|
<SubType>Code</SubType>
|
||||||
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
|
|||||||
17
utility.py
Normal file
17
utility.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
|
def load_data():
|
||||||
|
df = pd.read_csv('data/sample.txt', delimiter=',', header=None).astype(np.float32)
|
||||||
|
|
||||||
|
#df = pd.read_csv('data/ex1data1.txt', delimiter=',', header=None).astype(np.float32)
|
||||||
|
|
||||||
|
#df = pd.read_csv('data/train.csv', delimiter=',', comment='#').astype(np.float32)
|
||||||
|
#df[0] = df['x']
|
||||||
|
#df[1] = df['y']
|
||||||
|
|
||||||
|
df[2] = pd.Series([1]*len(df[0]))
|
||||||
|
df = df.reindex(columns=[1, 2, 0])
|
||||||
|
|
||||||
|
return df
|
||||||
Reference in New Issue
Block a user