Skip to content

Instantly share code, notes, and snippets.

@dukn
Last active May 14, 2019 15:06
Show Gist options
  • Save dukn/35b33391f08400d4a6f08bec5bd05197 to your computer and use it in GitHub Desktop.
Save dukn/35b33391f08400d4a6f08bec5bd05197 to your computer and use it in GitHub Desktop.
Just 4 fun =)))
import random
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
from sklearn.datasets.samples_generator import make_blobs
from sklearn.preprocessing import MinMaxScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
data = np.asarray([[random.random(), random.random()] for i in range(1000)])
lable = np.asarray([np.argmax(e) for e in data] )
X_train, X_test, y_train, y_test = train_test_split(data, lable, test_size=0.1, random_state=69)
model = Sequential()
model.add(Dense(4, input_dim=2, activation='relu'))
model.add(Dense(4, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam')
model.fit(X_train, y_train, epochs=200, verbose=0)
ypred = model.predict(X_test)
mse = mean_squared_error(y_test, ypred)
print ("MSE =",mse)
print()
print ("Sample first 5 elements")
print ("Data")
print (X_test[:5])
print ("Lable")
print (np.around(y_test,0)[:5])
print ("Predict")
print(np.around(ypred,0).reshape((-1))[:5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment