Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentiment Analysis of Movie Reviews #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Machine Learning from Scratch
# Machine Learning from Scratch.
This is the code repository for my [Machine Learning from Scratch youtube playlist](https://www.youtube.com/watch?v=4PHI11lX11I&list=PLP3ANEJKF1TzOz3hwOoRclgRFVi8A76k2)
## 01 Linear Regression using Least Squares
## 01 Linear Regression using Least Squares.
[Check out the tutorial video](https://www.youtube.com/watch?v=kR6tBAq16ng&t=2s)
## 02 Linear Regression using Gradient Descent
## 02 Linear Regression using Gradient Descent.
[Check out the tutorial video](https://www.youtube.com/watch?v=4PHI11lX11I&t=2s)
[Check out the medium post](https://towardsdatascience.com/linear-regression-using-gradient-descent-97a6c8700931)
## 03 Linear Regression in 2 minutes
## 03 Linear Regression in 2 minutes.
[Check out the medium post](https://towardsdatascience.com/linear-regression-in-6-lines-of-python-5e1d0cd05b8d)
70 changes: 70 additions & 0 deletions movie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
"""
Created on Sat May 12 00:18:03 2018
@author: jishn
"""
#Code which is used to find sentiment of the viewers.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Churn_Modelling.csv')
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Encoding categorical data
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1])
labelencoder_X_2 = LabelEncoder()
X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2])
onehotencoder = OneHotEncoder(categorical_features = [1])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

# Splitting the dataset into the Training set and Test set
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)

# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)


import keras
from keras.models import Sequential
from keras.layers import Dense

## used to initialise differnet layers
classifier=Sequential()
## adding the first layer init specifies the initial value to the weights closer to 0
## activation fn is Rectifier
## here the number of nodes taken is the avg of no of input parameters and output
## Best method is k cross validation
classifier.add(Dense(output_dim=6,init='uniform',activation='relu',input_dim=11))

classifier.add(Dense(output_dim=6,init='uniform',activation='relu'))


classifier.add(Dense(output_dim=1,init='uniform',activation='sigmoid'))

# Compiling the ANN
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

# Fitting the ANN to the Training set
classifier.fit(X_train, y_train, batch_size = 10, nb_epoch = 100)

# Part 3 - Making the predictions and evaluating the model

# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)

# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)

print("Accuracy:",((cm[0][0]+cm[1][1])/2000))