Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
class RandomForest(): | |
""" Python implementation of a random forest regressor """ | |
def __init__(self, x, y, num_trees, sample_size, feature_proportion=1.0, | |
min_leaf=5, bootstrap=False, random_seed=12): | |
np.random.seed(random_seed) | |
self.x = x | |
self.y = y | |
self.num_trees = num_trees | |
self.sample_size = sample_size | |
self.feature_proportion = feature_proportion |
This file contains hidden or 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
class DecisionTree(): | |
""" Form a basic decision tree """ | |
def __init__(self, x, y, idxs=None, oob_idxs=None, | |
min_leaf=5, feat_proportion=1.0): | |
if idxs is None: | |
idxs = np.arange(len(y)) | |
self.x = x | |
self.y = y | |
self.idxs = idxs | |
self.oob_idxs = oob_idxs |
This file contains hidden or 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 bs4 import BeautifulSoup | |
import requests | |
from time import sleep | |
# select Guardian website - Military news and obtain a set of URLs | |
crawl_url = 'https://www.theguardian.com/uk/military?page=' | |
# form a set to store unique urls of all articles | |
guardian_urls = set() |
This file contains hidden or 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 nltk.sentiment.vader import SentimentIntensityAnalyzer | |
sent_i = SentimentIntensityAnalyzer() | |
def vadar_sentiment(text): | |
""" Calculate and return the nltk vadar (lexicon method) sentiment """ | |
return sent_i.polarity_scores(text)['compound'] | |
# create new column for vadar compound sentiment score | |
news_sentiments['vadar compound'] = news_sentiments['title'].apply(vadar_sentiment) |
This file contains hidden or 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
class Adaline(object): | |
""" Adaline (Adaptive Linear Neuron) for binary classification. | |
Minimises the cost function using gradient descent. """ | |
def __init__(self, learn_rate = 0.01, iterations = 100): | |
self.learn_rate = learn_rate | |
self.iterations = iterations | |
def fit(self, X, y, biased_X = False, standardised_X = False): |
This file contains hidden or 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
class Perceptron(object): | |
""" Perceptron for demonstrating a binary classifier """ | |
def __init__(self, learn_rate = 0.01, iterations = 100): | |
self.learn_rate = learn_rate | |
self.iterations = iterations | |
def fit(self, X, y, biased_X = False): | |
""" Fit training data to our model """ |
This file contains hidden or 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 | |
import numpy as np | |
import pandas as pd | |
# make up random data for bird wingspans and weights for golden eagles and horned owls | |
bird_wingspans = np.concatenate([np.random.randint(170, 230, size = 50)/100.0, | |
np.random.randint(60, 100, size = 50)/100.0]) | |
bird_weights = np.concatenate([(11 - 10)*np.random.randn(50)+10, np.abs(np.random.randn(50))+1]) | |
# combine X vectors into a 2-dimensional array with 100 rows and 2 columns |
This file contains hidden or 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
# Arda Mavi | |
import os | |
import numpy as np | |
from os import listdir | |
from scipy.misc import imread, imresize | |
from keras.utils import to_categorical | |
from sklearn.model_selection import train_test_split | |
# Settings: | |
img_size = 64 |
This file contains hidden or 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
/************************************************************************* | |
* Remote node - nRF24L01+ radio communications * | |
* A program to operate a remote-node slave device that sends * | |
* data to a command unit on a given request message. The radio * | |
* transceiver used is the nRF24L01+, and it operates using the * | |
* TMRh20 RF24 library. * | |
* * | |
* Author: B.D. Fraser * | |
* * | |
* Last modified: 27/06/2017 * |
NewerOlder