Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras import Sequential
- from keras.layers import Dense
- import random
- import numpy as np
- model = Sequential()
- model.add(Dense(32, activation='relu', input_dim=100))
- model.add(Dense(1, activation='sigmoid'))
- model.compile(optimizer='rmsprop',
- loss='binary_crossentropy',
- metrics=['accuracy'])
- def get_random_power(power, samples=100, interval=(0.5,2)):
- m = random.random() * (interval[1]-interval[0]) + interval[0]
- return [x**power * m for x in range(samples)]
- def np_get_random_power(power, samples=100, interval=(0.5,2)):
- m = random.random() * (interval[1]-interval[0]) + interval[0]
- return np.array(x**power * m for x in range(samples))
- def sinus(offset, samples = 100):
- import math
- return [math.sin(offset*x/samples) for x in range(samples)]
- def get_data_set(size):
- X = []
- Y = []
- choice = [0,1]
- for i in range(size):
- val = random.choice([0,1])
- if val == 0:
- X.append(get_random_power(val))
- else:
- X.append(sinus(val,))
- Y.append([val])
- return X,Y
- X,Y = get_data_set(1000)
- print(np.array(X).shape, np.array(Y).shape)
- # Generate dummy data
- data = np.random.random((1000, 100))
- print("Shape:", data.shape)
- labels = np.random.randint(2, size=(1000, 1))
- print("Shape:", labels.shape)
- # Train the model, iterating on the data in batches of 32 samples
- model.fit(np.array(X), np.array(Y), epochs=10, batch_size=32)
- X,Y = get_data_set(1000)
- result = model.predict(np.array(X))
- for i in range(len(Y)):
- print(int(result[i]*1000)/1000,Y[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement