Skip to content
Permalink
Browse files

ML class in progress

  • Loading branch information...
dermatologist committed Mar 12, 2019
1 parent c35274e commit 3badac41ae64d1da6b049b5a2e62b50893c2778a
@@ -57,4 +57,10 @@ setup(

## Command line

* https://pymbook.readthedocs.io/en/latest/click.html
* https://pymbook.readthedocs.io/en/latest/click.html


## Getters and setters

class testDec(object):
* And one more thing that is not completely easy to spot at first, is the order: The getter must be defined first.
File renamed without changes.
@@ -5,7 +5,6 @@


def main():

print("Finding Articles citing the given reference.....")

for var in sys.argv:
@@ -21,7 +20,7 @@ def main():
articles.append(record['PMID'])

# Remove duplicates: SO 7961363
articles = list(set(articles))
articles = list(set(articles))
article_no = len(articles)

print("Finding Co-citations. This may take several hours...........")
@@ -37,6 +36,5 @@ def main():
print("-----------------------------------------")



if __name__ == '__main__': # if we're running file directly and not importing it
main() # run the main function
@@ -10,7 +10,7 @@
from keras.models import load_model
from keras.preprocessing import sequence

from src.misc.sentiment import process_msg
from src.misc_qrmine.sentiment import process_msg

model = load_model('data/classifier.h5')
vocab = pickle.load(open('data/vocab.pkl', 'rb'))
File renamed without changes.
@@ -41,8 +41,8 @@ def fib(n):
"""
assert n > 0
a, b = 1, 1
for i in range(n-1):
a, b = b, a+b
for i in range(n - 1):
a, b = b, a + b
return a


File renamed without changes.
@@ -0,0 +1,29 @@
# This is for oversampling
from pandas import read_csv


class MLQRMine(object):

def __init__(self):
self._seed = 7
self._csvfile = ""
self._dataset = None

@property
def seed(self):
return self._seed

@seed.setter
def seed(self, seed):
self._seed = seed

@property
def csvfile(self):
return self._csvfile

@csvfile.setter
def csvfile(self, csvfile):
self._csvfile = csvfile

def read_csv(self):
self._dataset = read_csv(self._csvfile, header=1)
File renamed without changes.
@@ -0,0 +1,75 @@
# Support Vector Machine (SVM)

import matplotlib.pyplot as plt
# Importing the libraries
import numpy as np
import pandas as pd

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

# 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.25, 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)

# Fitting SVM to the Training set
from sklearn.svm import SVC

classifier = SVC(kernel='linear', random_state=0)
classifier.fit(X_train, y_train)

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

# Making the Confusion Matrix
from sklearn.metrics import confusion_matrix

cm = confusion_matrix(y_test, y_pred)

# Visualising the Training set results
from matplotlib.colors import ListedColormap

X_set, y_set = X_train, y_train
X1, X2 = np.meshgrid(np.arange(start=X_set[:, 0].min() - 1, stop=X_set[:, 0].max() + 1, step=0.01),
np.arange(start=X_set[:, 1].min() - 1, stop=X_set[:, 1].max() + 1, step=0.01))
plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),
alpha=0.75, cmap=ListedColormap(('red', 'green')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
c=ListedColormap(('red', 'green'))(i), label=j)
plt.title('SVM (Training set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.legend()
plt.show()

# Visualising the Test set results
from matplotlib.colors import ListedColormap

X_set, y_set = X_test, y_test
X1, X2 = np.meshgrid(np.arange(start=X_set[:, 0].min() - 1, stop=X_set[:, 0].max() + 1, step=0.01),
np.arange(start=X_set[:, 1].min() - 1, stop=X_set[:, 1].max() + 1, step=0.01))
plt.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),
alpha=0.75, cmap=ListedColormap(('red', 'green')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
c=ListedColormap(('red', 'green'))(i), label=j)
plt.title('SVM (Test set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.legend()
plt.show()
@@ -7,6 +7,7 @@ def __init__(self):
self._documents = ''
self._titles = ''

# Getter must be defined first
@property
def content(self):
return self._content

0 comments on commit 3badac4

Please sign in to comment.
You can’t perform that action at this time.