Blogs

Supervised Learning in R: Classification

Chapter 1 - k-Nearest Neighbors (kNN) 1.1 - Recognizing a road sign with kNN After several trips with a human behind the wheel, it is time for the self-driving car to attempt the test course alone. As it begins to drive away, its camera captures the following image: Figure 1: A caption Can you apply a kNN classifier to help the car recognize this sign? The dataset signs must be loaded in your workspace along with the dataframe next_sign, which holds the observation you want to classify.

Continue reading

Deploying R Model as API Web Service using Docker and Microsoft Azure

Objective Our goal here is to create a R Model and put-in into production by deploying it as web service API using Docker to containerize (encapsulate) it and Microsoft Azure to host it. R Model To create the model, we going to use mtcars dataset which one’s is present inside R. head(mtcars) ## mpg cyl disp hp drat wt qsec vs am gear carb ## Mazda RX4 21.0 6 160 110 3.

Continue reading

Credit Card Fraud Detection

Objective Our goal is to train a Neural Network to detect fraudulent credit card transactions in a dataset referring to two days transactions by european cardholders. Source: https://www.kaggle.com/mlg-ulb/creditcardfraud/data Data credit = read.csv(path) The datasets contains transactions made by credit cards in September 2013 by european cardholders. This dataset presents transactions that occurred in two days. As we can see, this dataset consists of thirty explanatory variables, and a response variable which represents whether a transation was a fraud or not.

Continue reading

Intermediate Importing Data in Python

1. Importing flat files from the web: your turn! # Import package from urllib.request import urlretrieve # Import pandas import pandas as pd # Assign url of file: url url = 'https://s3.amazonaws.com/assets.datacamp.com/production/course_1606/datasets/winequality-red.csv' # Save file locally urlretrieve(url, 'winequality-red.csv') # Read file into a DataFrame and print its head ## ('winequality-red.csv', <http.client.HTTPMessage object at 0x000000001FBF52C8>) df = pd.read_csv('winequality-red.csv', sep=';') print(df.head()) ## fixed acidity volatile acidity citric acid ... sulphates alcohol quality ## 0 7.

Continue reading

Introduction to Importing Data in Python

1. Importing entire text files # Open a file: file file = open('c:/blogdown/moby_dick.txt', mode='r') # Print it print(file.read()) # Check whether file is closed ## CHAPTER 1. Loomings. ## ## Call me Ishmael. Some years ago--never mind how long precisely--having ## little or no money in my purse, and nothing particular to interest me on ## shore, I thought I would sail about a little and see the watery part of ## the world.

Continue reading

Supervised Learning with Scikit-Learn

1. The Iris dataset in scikit-learn from sklearn import datasets import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.style.use('ggplot') iris = datasets.load_iris() type(iris) ## <class 'sklearn.utils.Bunch'> print(iris.keys()) ## dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename']) print(iris.DESCR) ## .. _iris_dataset: ## ## Iris plants dataset ## -------------------- ## ## **Data Set Characteristics:** ## ## :Number of Instances: 150 (50 in each of three classes) ## :Number of Attributes: 4 numeric, predictive attributes and the class ## :Attribute Information: ## - sepal length in cm ## - sepal width in cm ## - petal length in cm ## - petal width in cm ## - class: ## - Iris-Setosa ## - Iris-Versicolour ## - Iris-Virginica ## ## :Summary Statistics: ## ## ============== ==== ==== ======= ===== ==================== ## Min Max Mean SD Class Correlation ## ============== ==== ==== ======= ===== ==================== ## sepal length: 4.

Continue reading

Python Data Science - part 1

1. Single Parameter Function # Define shout with the parameter, word def shout(word): """Print a string with three exclamation marks""" # Concatenate the strings: shout_word shout_word = word + '!!!' # Print shout_word print(shout_word) # Call shout with the string 'congratulations' shout("Congratulations") ## Congratulations!!! 2. Functions that return single values # Define shout with the parameter, word def shout(word): """Return a string with three exclamation marks""" # Concatenate the strings: shout_word shout_word = word + "!

Continue reading

Linear Models - Scikit Learn

1. Linear Models The target value is expected to be a linear combination of the features. 1.1. Ordinary Least Squares (OLS) The OLS is a optimization math technique that aim to find the better adjustment for a set data and try to minimize the residual sum of squares between the observed targets in the dataset and the targets predicted by the linear approximation. from sklearn import linear_model reg = linear_model.

Continue reading

TensorFlow 2 - Quickstart for Beginners

from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf mnist = tf.keras.datasets.mnist (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10) ]) predictions = model(x_train[:1]).numpy() ## WARNING:tensorflow:Layer flatten is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2.

Continue reading

Iterables versus Iterators

1. Defining a list flash1 = ['jay garrick', 'barry allen', 'wally west', 'bart allen'] a = 1

Continue reading