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
# 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
with open("/Users/rohith/Documents/Datasets/sentiment_labelled_sentences/amazon_cells_labelled.txt") as f1: | |
lines = f1.readlines() | |
with open("/Users/rohith/Documents/Datasets/sentiment_labelled_sentences/imdb_labelled.txt") as f1: | |
temp = f1.readlines() | |
lines=lines+temp | |
with open("/Users/rohith/Documents/Datasets/sentiment_labelled_sentences/yelp_labelled.txt") as f1: | |
temp = f1.readlines() | |
lines=lines+temp |
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
x = [] | |
y = [] | |
for value in lines: | |
temp = value.split('\t') | |
x.append(temp[0]) | |
temp[1].replace('\n','') | |
y.append(int(temp[1])) |
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 keras.preprocessing.text import Tokenizer | |
tokenizer = Tokenizer(num_words=2500,split=' ') | |
tokenizer.fit_on_texts(x) |
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 keras.preprocessing.sequence import pad_sequences | |
X = tokenizer.texts_to_sequences(x) | |
X = pad_sequences(X) |
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.layers import Embedding, LSTM, Dense | |
from keras.models import Sequential | |
model = Sequential() | |
model.add(Embedding(2500,128,input_length=X.shape[1],dropout=0.2)) | |
model.add(LSTM(300, dropout_U=0.2,dropout_W=0.2)) | |
model.add(Dense(2,activation='softmax')) | |
model.compile(loss=keras.losses.categorical_crossentropy,optimizer='adam',metrics=['accuracy']) |
OlderNewer