Skip to content

Instantly share code, notes, and snippets.

Last active Dec 18, 2018
What would you like to do?
polynomial regression try with keras
%matplotlib inline
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import Adam
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
#Generate data
x_train = np.random.random((num_data,2))* 10
x = x_train[:, 0]
y = x_train[:, 1]
y_train = x*x*y + y + 2
print x_train.shape
print y_train.shape
x_test = np.array([3,4])
model = Sequential()
# 이렇게 하면 되나 몰라..
# Dense(64) is a fully-connected layer with 64 hidden units.
model.add(Dense(100, activation='relu', input_dim=2))
model.add(Dense(100, activation='relu'))
model.add(Dense(1, activation='linear'))
model.compile(loss='mean_squared_error', optimizer='adam'), y_train,
y = model.predict(x_test, batch_size=32, verbose=1)
print "3^2*4+4+2 = %r (should be 42)" % y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment