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 keras | |
from keras.datasets import mnist | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Flatten | |
from keras.layers import Conv2D, MaxPooling2D | |
from keras import backend as K | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
img_rows, img_cols = 28, 28 |
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
from tpot import TPOTClassifier | |
from sklearn.datasets import load_digits | |
from sklearn.model_selection import train_test_split | |
digits = load_digits() | |
x_train, x_test, y_train, y_test = train_test_split(digits.data,digits.target,train_size=0.75,test_size=0.25) | |
clf = TPOTClassifier(generations=10, population_size=20, verbosity=2) | |
clf.fit(x_train,y_train) | |
print(clf.score(x_test,y_test)) |
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 pandas as pd | |
import numpy as np | |
df = pd.read_csv("/Users/rohith/Documents/Datasets/Tesla_Stock_prices/Tesla_Stock.csv") # read csv file | |
rows = df.values.tolist() # convert dataframe into a list | |
rows.reverse() |
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
from sklearn.model_selection import train_test_split | |
x_train = [] | |
y_train = [] | |
x_test = [] | |
y_test = [] | |
X = [] | |
Y = [] | |
for row in rows: | |
X.append(int(''.join(row[0].split('/')))) | |
Y.append(row[3]) |
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
# Linear Regression model | |
from sklearn.linear_model import LinearRegression | |
clf_lr = LinearRegression() | |
clf_lr.fit(x_train,y_train) | |
y_pred_lr = clf_lr.predict(x_test) | |
# Support Vector Machine with a Radial Basis Function as kernel | |
from sklearn.svm import SVR | |
clf_svr = SVR(kernel='rbf', C=1e3, gamma=0.1) | |
clf_svr.fit(x_train,y_train) |
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 matplotlib.pyplot as plt | |
f,(ax1,ax2) = plt.subplots(1,2,figsize=(30,10)) | |
# Linear Regression | |
ax1.scatter(range(len(y_test)),y_test,label='data') | |
ax1.plot(range(len(y_test)),y_pred_lr,color='green',label='LR model') | |
ax1.legend() | |
# Support Vector Machine |
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
print("Accuracy of Linear Regerssion Model:",clf_lr.score(x_test,y_test)) | |
print("Accuracy of SVM-RBF Model:",clf_svr.score(x_test,y_test)) | |
print("Accuracy of Random Forest Model:",clf_rf.score(x_test,y_test)) | |
print("Accuracy of Gradient Boosting Model:",clf_gb.score(x_test,y_test)) |
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 keras | |
from keras.datasets import mnist | |
from keras.models import Sequential | |
from keras.layers import Dense, Dropout, Flatten | |
from keras.layers import Conv2D, MaxPooling2D | |
import numpy as np |
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
batch_size = 128 | |
num_classes = 10 | |
epochs = 12 | |
# input image dimensions | |
img_rows, img_cols = 28, 28 | |
# the data, split between train and test sets | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() |
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
model = Sequential() | |
model.add(Conv2D(32, kernel_size=(3, 3), | |
activation='relu', | |
input_shape=(28,28,1))) | |
model.add(Conv2D(64, (3, 3), activation='relu')) | |
model.add(MaxPooling2D(pool_size=(2, 2))) | |
model.add(Dropout(0.25)) | |
model.add(Flatten()) | |
model.add(Dense(128, activation='relu')) | |
model.add(Dropout(0.5)) |
OlderNewer