Created
May 24, 2020 03:01
-
-
Save Pawandeep-prog/2e4b80f67b247c470888fbad307f24d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import random | |
X = [] | |
logx=[] | |
logy=[] | |
for i in range(10000): | |
X.append([random.randint(1,1000), random.randint(1,1000)]) | |
logx.append([np.log(X[i][0]), np.log(X[i][1])]) | |
logy.append([logx[i][0] + logx[i][1]]) | |
logx = np.array(logx) | |
logy = np.array(logy).reshape(-1,1) | |
#### ml algo ####### | |
from sklearn.model_selection import train_test_split | |
X_train,X_test,y_train,y_test = train_test_split(logx, logy,test_size=0.2) | |
from sklearn.linear_model import LinearRegression | |
lr = LinearRegression() | |
lr.fit(X_train, y_train) | |
lr.score(X_test, y_test) | |
############### neural network | |
from keras.models import Sequential | |
from keras.layers import Dense | |
model = Sequential() | |
model.add(Dense(output_dim=1, input_dim=2, activation='relu')) | |
model.compile('adam', 'mean_squared_error') | |
model.fit(logx, logy, epochs=20, batch_size=12) | |
test = np.array([np.log(10), np.log(5)]).reshape(-1,1).T | |
pred = model.predict(test) | |
pred = exp(pred) | |
#### ml algo | |
pred = lr.predict(test) | |
pred=exp(pred) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment