markdown stringlengths 0 37k | code stringlengths 1 33.3k | path stringlengths 8 215 | repo_name stringlengths 6 77 | license stringclasses 15
values |
|---|---|---|---|---|
Equivalently, we could explicitly set the equality operator: | ag.apps.list(search={'id.eq': app.id}) | content/notebooks/Python SDK.ipynb | agaveapi/SC17-container-tutorial | bsd-3-clause |
Typically, the list of available search terms is identical to the attributes included in the JSON returned when requesting the full resource description. Operators include 'like', 'lt', 'gt', 'lte', 'gte', etc. See the official Agave documentation for the complete list.
Here we retrieve all apps with a name is "like" ... | ag.apps.list(search={'name.like': 'opensees'}) | content/notebooks/Python SDK.ipynb | agaveapi/SC17-container-tutorial | bsd-3-clause |
Two results were returned, both with name "opensees".
You can include multiple search expressions in the form of additional key:value pairs to build a more restrictive query. Here we restrict the result to opensees apps with revision at least 25: | ag.apps.list(search={'name.like': 'opensees', 'revision.gte': 25}) | content/notebooks/Python SDK.ipynb | agaveapi/SC17-container-tutorial | bsd-3-clause |
Preparation
To get started, we first load all the required imports. Please make sure you installed dist-keras, and seaborn. Furthermore, we assume that you have access to an installation which provides Apache Spark.
Before you start this notebook, place the MNIST dataset (which is provided in a zip in examples/data wit... | %matplotlib inline
import numpy as np
import seaborn as sns
import time
from pyspark import SparkContext
from pyspark import SparkConf
from matplotlib import pyplot as plt
from pyspark.ml.feature import StandardScaler
from pyspark.ml.feature import VectorAssembler
from pyspark.ml.feature import OneHotEncoder
from... | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
In the following cell, adapt the parameters to fit your personal requirements. | # Modify these variables according to your needs.
application_name = "MNIST Preprocessing"
using_spark_2 = False
local = False
path_train = "data/mnist_train.csv"
path_test = "data/mnist_test.csv"
if local:
# Tell master to use local resources.
master = "local[*]"
num_processes = 3
num_executors = 1
els... | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
As shown in the output of the cell above, we see that every pixel is associated with a seperate column. In order to ensure compatibility with Apache Spark, we vectorize the columns, and add the resulting vectors as a seperate column. However, in order to achieve this, we first need a list of the required columns. This ... | # First, we would like to extract the desired features from the raw dataset.
# We do this by constructing a list with all desired columns.
features = raw_dataset_train.columns
features.remove('label') | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Once we have a list of columns names, we can pass this to Spark's VectorAssembler. This VectorAssembler will take a list of features, vectorize them, and place them in a column defined in outputCol. | # Next, we use Spark's VectorAssembler to "assemble" (create) a vector of all desired features.
# http://spark.apache.org/docs/latest/ml-features.html#vectorassembler
vector_assembler = VectorAssembler(inputCols=features, outputCol="features")
# This transformer will take all columns specified in features, and create a... | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Once we have the inputs for our Neural Network (features column) after applying the VectorAssembler, we should also define the outputs. Since we are dealing with a classification task, the output of our Neural Network should be a one-hot encoded vector with 10 elements. For this, we provide a OneHotTransformer which ac... | # Define the number of output classes.
nb_classes = 10
encoder = OneHotTransformer(nb_classes, input_col="label", output_col="label_encoded")
training_set = encoder.transform(training_set)
test_set = encoder.transform(test_set) | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
MNIST
MNIST is a dataset of handwritten digits. Every image is a 28 by 28 pixel grayscale image. This means that every pixel has a value between 0 and 255. Some examples of instances within this dataset are shown in the cells below.
Normalization
In this Section, we will normalize the feature vectors between the 0 and ... | # Clear the datasets in the case you ran this cell before.
training_set = training_set.select("features", "label", "label_encoded")
test_set = test_set.select("features", "label", "label_encoded")
# Allocate a MinMaxTransformer using Distributed Keras.
# o_min -> original_minimum
# n_min -> new_minimum
transformer = Mi... | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Convolutions
In order to make the dense vectors compatible with convolution operations in Keras, we add another column which contains the matrix form of these images. We provide a utility class (MatrixTransformer), which helps you with this. | reshape_transformer = ReshapeTransformer("features_normalized", "matrix", (28, 28, 1))
training_set = reshape_transformer.transform(training_set)
test_set = reshape_transformer.transform(test_set) | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Dense Transformation
At the moment, dist-keras does not support SparseVectors due to the numpy dependency. As a result, we have to convert the SparseVector to a DenseVector. We added a simple utility transformer which does this for you. | dense_transformer = DenseTransformer(input_col="features_normalized", output_col="features_normalized_dense")
training_set = dense_transformer.transform(training_set)
test_set = dense_transformer.transform(test_set) | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Artificial Enlargement
We want to make the dataset 100 times larger to simulate larger datasets, and to evaluate optimizer performance. | df = training_set
expansion = 10
for i in range(0, expansion):
df = df.unionAll(training_set)
training_set = df
training_set.cache() | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Writing to HDFS
In order to prevent constant preprocessing, and ensure optimizer performance, we write the data to HDFS in a Parquet format. | training_set.write.parquet("data/mnist_train.parquet")
test_set.write.parquet("data/mnist_test.parquet")
# Record end of transformation.
time_end = time.time()
dt = time_end - time_start
print("Took " + str(dt) + " seconds.")
!hdfs dfs -rm -r data/mnist_test.parquet
!hdfs dfs -rm -r data/mnist_train.parquet | examples/mnist_preprocessing.ipynb | ad960009/dist-keras | gpl-3.0 |
Ideas for Lane Detection Pipeline
Some OpenCV functions (beyond those introduced in the lesson) that might be useful for this project are:
cv2.inRange() for color selection
cv2.fillPoly() for regions selection
cv2.line() to draw lines on an image given endpoints
cv2.addWeighted() to coadd / overlay two images
cv2.cvtCo... | import math
from scipy import stats
def grayscale(img):
"""Applies the Grayscale transform
This will return an image with only one color channel
but NOTE: to see the returned image as grayscale
(assuming your grayscaled image is called 'gray')
you should call plt.imshow(gray, cmap='gray')"""
#r... | P1.ipynb | nitheeshkl/Udacity_CarND_LaneLines_P1 | mit |
Build a Lane Finding Pipeline
Build the pipeline and run your solution on all test_images. Make copies into the test_images_output directory, and you can use the images in your writeup report.
Try tuning the various parameters, especially the low and high Canny thresholds as well as the Hough lines parameters. | # TODO: Build your pipeline that will draw lane lines on the test_images
# then save them to the test_images directory.
def showImage(img,cmap=None):
# create a new figure to show each image
plt.figure()
# show image
plt.imshow(img,cmap=cmap)
def detectLaneLines(image):
# get image sizes. X=columsn... | P1.ipynb | nitheeshkl/Udacity_CarND_LaneLines_P1 | mit |
Test on Videos
You know what's cooler than drawing lanes over images? Drawing lanes over video!
We can test our solution on two provided videos:
solidWhiteRight.mp4
solidYellowLeft.mp4
Note: if you get an import error when you run the next cell, try changing your kernel (select the Kernel menu above --> Change Kernel).... | # Import everything needed to edit/save/watch video clips
from moviepy.editor import VideoFileClip
from IPython.display import HTML
def process_image(image):
# NOTE: The output you return should be a color image (3 channel) for processing video below
# TODO: put your pipeline here,
# you should return the ... | P1.ipynb | nitheeshkl/Udacity_CarND_LaneLines_P1 | mit |
Load wiki page view and stock price data into Spark DataFrames.
wiki_obs is a Spark dataframe of (timestamp, page, views) of types (Timestamp, String, Double). ticker_obs is a Spark dataframe of (timestamp, symbol, price) of types (Timestamp, String, Double). | wiki_obs = ld.load_wiki_df(sqlCtx, '/user/srowen/wiki.tsv')
ticker_obs = ld.load_ticker_df(sqlCtx, '/user/srowen/ticker.tsv') | ds-for-ws-student.ipynb | cdalzell/ds-for-wall-street | apache-2.0 |
Display the first 5 elements of the wiki_obs RDD.
wiki_obs contains Row objects with the fields (timestamp, page, views).
Display the first 5 elements of the tickers_obs RDD.
ticker_obs contains Row objects with the fields (timestamp, symbol, views).
Create datetime index.
Create time series RDD from observations and ... | def print_ticker_info(ticker):
print ('The first ticker symbol is: {} \nThe first 20 elements of the associated ' +\
'series are:\n {}').format(ticker[0], ticker[1][:20]) | ds-for-ws-student.ipynb | cdalzell/ds-for-wall-street | apache-2.0 |
Create a wiki page view tsrdd and set the index to match the index of ticker_tsrdd.
Linearly interpolate to impute missing values.
wiki_tsrdd is an RDD of tuples where each tuple has the form (page title, wiki views) where page title is a string and wiki views is a 1D np.ndarray. We have cached both RDDs because we wi... | def count_nans(vec):
return np.count_nonzero(np.isnan(vec)) | ds-for-ws-student.ipynb | cdalzell/ds-for-wall-street | apache-2.0 |
Join together wiki_tsrdd and ticker_tsrdd
First, we use this dict to look up the corresponding stock ticker symbol and rekey the wiki page view time series. We then join the data sets together. The result is an RDD of tuples where each element is of the form (ticker_symbol, (wiki_series, ticker_series)). We count the n... | from scipy.stats.stats import pearsonr
def wiki_vol_corr(page_key):
# lookup individual time series by key.
ticker = ticker_tsrdd.find_series(page_symbols[page_key]) # numpy array
wiki = wiki_tsrdd.find_series(page_key) # numpy array
return pearsonr(ticker, wiki)
def corr_with_offset(page_key, offset)... | ds-for-ws-student.ipynb | cdalzell/ds-for-wall-street | apache-2.0 |
Create a plot of the joint distribution of wiki trafiic and stock prices for a specific company using seaborn's jointplot function. | def joint_plot(page_key, ticker, wiki, offset=0):
with sns.axes_style("white"):
sns.jointplot(x=ticker, y=wiki, kind="kde", color="b");
plt.xlabel('Stock Price')
plt.ylabel('Wikipedia Page Views')
plt.title('Joint distribution of {} stock price\n and Wikipedia page views.'\
... | ds-for-ws-student.ipynb | cdalzell/ds-for-wall-street | apache-2.0 |
Find the companies with the highest correlation between stock prices time series and wikipedia page traffic.
Note that comparing a tuple means you compare the composite object lexicographically.
Add in filtering out less than useful correlation results.
There are a lot of invalid correlations that get computed, so le... | def regress(X, y):
model = linear_model.LinearRegression()
model.fit(X, y)
score = model.score(X, y)
return (score, model)
lag = 2
lead = 2
joined = regressions = wiki_daily_views.flatMap(get_page_symbol) \
.join(ticker_daily_vol)
models = joined.mapValues(lambda x: regress(tsutil.lead_and_la... | ds-for-ws-student.ipynb | cdalzell/ds-for-wall-street | apache-2.0 |
To clone the local repository | $ git clone https://github.com/VandyAstroML/Vanderbilt_Computational_Bootcamp.git | notebooks/Week_02/02_Python_Git_Github_Tutorial.ipynb | VandyAstroML/Vanderbilt_Computational_Bootcamp | mit |
Problem 2
Create a generator that yields "n" random numbers between a low and high number (that are inputs). Note: Use the random library. For example: | import random
random.randint(1,10)
def rand_num(low,high,n):
for i in range(n+1):
yield random.randint(low, high)
for num in rand_num(1,10,12):
print num | Iterators and Generators Homework.ipynb | spacedrabbit/PythonBootcamp | mit |
Problem 3
Use the iter() function to convert the string below | s = 'hello'
#code here
for letter in iter(s):
print letter | Iterators and Generators Homework.ipynb | spacedrabbit/PythonBootcamp | mit |
Problem 4
Explain a use case for a generator using a yield statement where you would not want to use a normal function with a return statement.
A generator, utilizing a yield statement, returns an iterator object. The iterator object will yield/return a value each time it is called upon to iterate through its code. So ... | my_list = [1,2,3,4,5]
gencomp = (item for item in my_list if item > 3)
for item in gencomp:
print item | Iterators and Generators Homework.ipynb | spacedrabbit/PythonBootcamp | mit |
Dataset description
Datasource: http://yann.lecun.com/exdb/mnist/
The training dataset consists of 60,000 training digits and the test set contains 10,000 samples, respectively. The images in the MNIST dataset consist of pixels, and each pixel is represented by a gray scale intensity value. Here, we unroll the pixels... | training = pd.read_csv("/data/MNIST/mnist_train.csv", header = None)
testing = pd.read_csv("/data/MNIST/mnist_test.csv", header = None)
X_train, y_train = training.iloc[:, 1:].values, training.iloc[:, 0].values
X_test, y_test = testing.iloc[:, 1:].values, testing.iloc[:, 0].values
print("Shape of X_train: ", X_trai... | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Distribution of class frequencies | label_counts = pd.DataFrame({
"train": pd.Series(y_train).value_counts().sort_index(),
"test": pd.Series(y_test).value_counts().sort_index()
})
(label_counts / label_counts.sum()).plot.bar()
plt.xlabel("Class")
plt.ylabel("Frequency (normed)") | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Chisquare test on class frequencies | scipy.stats.chisquare(label_counts.train, label_counts.test) | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Display a few sample images | fig, axes = plt.subplots(5, 5, figsize = (15, 9))
for i, ax in enumerate(fig.axes):
img = X_train[i, :].reshape(28, 28)
ax.imshow(img, cmap = "Greys", interpolation="nearest")
ax.set_title("True: %i" % y_train[i])
plt.tight_layout() | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
View different variations of a digit | fig, axes = plt.subplots(10, 5, figsize = (15, 20))
for i, ax in enumerate(fig.axes):
img = X_train[y_train == 7][i, :].reshape(28, 28)
ax.imshow(img, cmap = "Greys", interpolation="nearest")
plt.tight_layout() | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Feature scaling | scaler = preprocessing.StandardScaler()
X_train_std = scaler.fit_transform(X_train.astype(np.float64))
X_test_std = scaler.transform(X_test.astype(np.float64)) | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Applying logistic regression classifier | %%time
lr = linear_model.LogisticRegression()
lr.fit(X_train_std, y_train)
print("accuracy:", lr.score(X_test_std, y_test)) | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Display wrong predictions | y_test_pred = lr.predict(X_test_std)
miss_indices = (y_test != y_test_pred)
misses = X_test[miss_indices]
print("No of miss: ", misses.shape[0])
fig, axes = plt.subplots(10, 5, figsize = (15, 20))
misses_actual = y_test[miss_indices]
misses_pred = y_test_pred[miss_indices]
for i, ax in enumerate(fig.axes):
img = ... | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
Applying SGD classifier | inits = np.random.randn(10, 784)
inits = inits / np.std(inits, axis=1).reshape(10, -1)
%%time
est = linear_model.SGDClassifier(n_jobs=4, tol=1e-5, eta0 = 0.15,
learning_rate = "invscaling",
alpha = 0.01, max_iter= 100)
est.fit(X_train_std, y_train, ... | Scikit - 10 Image Classification (MNIST dataset).ipynb | abulbasar/machine-learning | apache-2.0 |
First, we load all test data. | df = pd.read_csv('stress-ng/third/torpor-results/alltests.csv') | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Define some predicates for machines and limits | machine_is_issdm_6 = df['machine'] == 'issdm-6'
machine_is_t2_micro = df['machine'] == 't2.micro'
machine_is_kv3 = df['machine'] == 'kv3'
limits_is_with = df['limits'] == 'with'
limits_is_without = df['limits'] == 'without' | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Show the number of stress tests on different machines | df_issdm_6_with_limit = df[machine_is_issdm_6 & limits_is_with]
df_t2_micro_with_limit = df[machine_is_t2_micro & limits_is_with]
df_kv3_without_limit = df[machine_is_kv3 & limits_is_without]
print(
len(df_issdm_6_with_limit), # machine issdm-6 with limit
len(df[machine_is_issdm_6 & li... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Because those failed benchmarks are not shown in the result report, we want to know how many common successful stress tests on the target machine and kv3. | issdm_6_with_limit_merge_kv3 = pd.merge(df_issdm_6_with_limit, df_kv3_without_limit, how='inner', on='benchmark')
t2_micro_with_limit_merge_kv3 = pd.merge(df_t2_micro_with_limit, df_kv3_without_limit, how='inner', on='benchmark')
print(
# common successful tests from issdm-6 and kv3
len(issdm_6_with_limit_merg... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Read the normalized results. | df_normalized = pd.read_csv('stress-ng/third/torpor-results/alltests_with_normalized_results_1.1.csv') | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Show some of the data lines. The normalized value is the speedup based on kv3. It becomes a negative value when the benchmark runs on the target machine is slower than on kv3 (slowdown). | df_normalized.head() | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Show those benchmarks are not both successful completed on the issdm-6 and kv3. | df_issdm_6_with_limit[~df_issdm_6_with_limit['benchmark'].isin(issdm_6_with_limit_merge_kv3['benchmark'])] | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Show those benchmarks are not both successful completed on the t2.micro and kv3. | df_t2_micro_with_limit[~df_t2_micro_with_limit['benchmark'].isin(t2_micro_with_limit_merge_kv3['benchmark'])] | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
We can find the number of benchmarks are speed-up and slowdown, respectively. | normalized_limits_is_with = df_normalized['limits'] == 'with'
normalized_limits_is_without = df_normalized['limits'] == 'without'
normalized_machine_is_issdm_6 = df_normalized['machine'] == 'issdm-6'
normalized_machine_is_t2_micro = df_normalized['machine'] == 't2.micro'
normalized_is_speed_up = df_normalized['normal... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The average of normalized value for results under CPU restriction | print(
# For issdm-6
df_normalized[normalized_machine_is_issdm_6 & normalized_limits_is_with]['normalized'].mean(),
# For t2_micro
df_normalized[normalized_machine_is_t2_micro & normalized_limits_is_with]['normalized'].mean()
) | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Experiment Results from issdm-6
Let's have a look at the histogram of frequency of normalized value based on stress tests without CPU restriction running on issdm-6. | df_normalized_issdm_6_without_limit = df_normalized[normalized_machine_is_issdm_6 & normalized_limits_is_without]
df_normalized_issdm_6_without_limit.normalized.hist(bins=150, figsize=(25,12), xlabelsize=20, ylabelsize=20)
plt.title('stress tests run on issdm-6 without CPU restriction', fontsize=30)
plt.xlabel('Norma... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Here is the rank of normalized value from stress tests without CPU restriction | df_normalized_issdm_6_without_limit_sorted = df_normalized_issdm_6_without_limit.sort_values(by='normalized', ascending=0)
df_normalized_issdm_6_without_limit_sorted_head = df_normalized_issdm_6_without_limit_sorted.head()
df_normalized_issdm_6_without_limit_sorted_tail = df_normalized_issdm_6_without_limit_sorted.tail... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Now let's have a look at the histogram of frequency of normalized value based on stress tests with CPU restriction running on issdm-6. | df_normalized_issdm_6_with_limit = df_normalized[normalized_machine_is_issdm_6 & normalized_limits_is_with]
df_normalized_issdm_6_with_limit.normalized.hist(color='Orange', bins=150, figsize=(25,12), xlabelsize=20, ylabelsize=20)
plt.title('stress tests run on issdm-6 with CPU restriction', fontsize=30)
plt.xlabel('N... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Here is the rank of normalized value from stress tests with CPU restriction | df_normalized_issdm_6_with_limit_sorted = df_normalized_issdm_6_with_limit.sort_values(by='normalized', ascending=0)
df_normalized_issdm_6_with_limit_sorted_head = df_normalized_issdm_6_with_limit_sorted.head()
df_normalized_issdm_6_with_limit_sorted_tail = df_normalized_issdm_6_with_limit_sorted.tail()
df_normalized_i... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
We notice that the stressng-cpu-jenkin looks like an outlier. Let's redraw the histogram without this one. | df_normalized_issdm_6_no_outlier = df_normalized_issdm_6_with_limit['benchmark'] != 'stressng-cpu-jenkin'
df_normalized_issdm_6_with_limit[df_normalized_issdm_6_no_outlier].normalized.hist(color='Green', bins=150, figsize=(25,12), xlabelsize=20, ylabelsize=20)
plt.title('stress tests run on issdm-6 with CPU restrictio... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Summary
We got the boundary of normalized value on issdm-6 from -29.394675 to 54.266945 by using parameters --cpuset-cpus=1 --cpu-quota=7234 --cpu-period=100000, which means the docker container only uses 7.234ms CPU worth of run-time every 100ms on cpu 1 (See cpu for more details).
Experiment Results from t2.micro
Let... | df_normalized_t2_micro_without_limit = df_normalized[normalized_machine_is_t2_micro & normalized_limits_is_without]
df_normalized_t2_micro_without_limit.normalized.hist(bins=150,figsize=(30,12), xlabelsize=20, ylabelsize=20)
plt.title('stress tests run on t2.micro without CPU restriction', fontsize=30)
plt.xlabel('No... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Here is the rank of normalized value from stress tests without CPU restriction | df_normalized_t2_micro_without_limit_sorted = df_normalized_t2_micro_without_limit.sort_values(by='normalized', ascending=0)
df_normalized_t2_micro_without_limit_sorted_head = df_normalized_t2_micro_without_limit_sorted.head()
df_normalized_t2_micro_without_limit_sorted_tail = df_normalized_t2_micro_without_limit_sorte... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Let's have a look at the histogram of frequency of normalized value based on stress tests with CPU restriction running on t2.micro. | df_normalized_t2_micro_with_limit = df_normalized[normalized_machine_is_t2_micro & normalized_limits_is_with]
df_normalized_t2_micro_with_limit.normalized.hist(color='Orange', bins=150, figsize=(30,12), xlabelsize=20, ylabelsize=20)
plt.title('stress tests run on t2.micro with CPU restriction', fontsize=30)
plt.xlabe... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Here is the rank of normalized value from stress tests with CPU restriction | df_normalized_t2_micro_with_limit_sorted = df_normalized_t2_micro_with_limit.sort_values(by='normalized', ascending=0)
df_normalized_t2_micro_with_limit_sorted_head = df_normalized_t2_micro_with_limit_sorted.head()
df_normalized_t2_micro_with_limit_sorted_tail = df_normalized_t2_micro_with_limit_sorted.tail()
df_normal... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
We notice that the stressng-memory-stack looks like an outlier. Let's redraw the histogram without this one. | df_normalized_t2_micro_no_outlier = df_normalized_t2_micro_with_limit['benchmark'] != 'stressng-memory-stack'
df_normalized_t2_micro_with_limit[df_normalized_t2_micro_no_outlier].normalized.hist(color='Green', bins=150, figsize=(30,12), xlabelsize=20, ylabelsize=20)
plt.title('stress tests run on t2.micro with CPU res... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The stressng-cpu-jenkin benchmark is a collection of (non-cryptographic) hash functions for multi-byte keys. See Jenkins hash function from Wikipedia for more details.
Summary
We got the boundary of normalized value on t2.micro from -198.440535 to 119.904761 by using parameters --cpuset-cpus=0 --cpu-quota=25750 --cpu-p... | df_verification = pd.read_csv('verification/results/2/alltests_with_normalized_results_1.1.csv') | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Show number of test benchmarks. | len(df_verification) / 2 | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Order the test results by the absolute of normalized value | df_verification_rank = df_verification.reindex(df_verification.normalized.abs().sort_values(ascending=0).index)
df_verification_rank.head(8) | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Verification Tests on issdm-6
Histogram of frequency of normalized value. | df_verification_issdm_6 = df_verification[df_verification['machine'] == 'issdm-6']
df_verification_issdm_6.normalized.hist(color='y', bins=150,figsize=(20,10), xlabelsize=20, ylabelsize=20)
plt.title('verification tests run on issdm-6', fontsize=30)
plt.xlabel('Normalized Value (re-execution / original)', fontsize=25... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Print the max the min normalized value, | print(
df_verification_issdm_6['normalized'].max(),
df_verification_issdm_6['normalized'].min()
) | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The average of noramlized value is, | df_verification_issdm_6['normalized'].mean() | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
If we remove all nbench tests, the frequency histogram changes to | df_verification_issdm_6_no_nbench = df_verification_issdm_6[~df_verification_issdm_6['benchmark'].str.startswith('nbench')]
df_verification_issdm_6_no_nbench.normalized.hist(color='greenyellow', bins=150,figsize=(20,10), xlabelsize=20, ylabelsize=20)
plt.title('verification tests run on issdm-6 (no nbench)', fontsize=... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The max the min normalized value changes to, | print(
df_verification_issdm_6_no_nbench['normalized'].max(),
df_verification_issdm_6_no_nbench['normalized'].min()
) | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The average of noramlized value changes to, | df_verification_issdm_6_no_nbench['normalized'].mean() | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Verification Tests on t2.micro
Histogram of frequency of normalized value. | df_verification_t2_micro = df_verification[df_verification['machine'] == 't2.micro']
df_verification_t2_micro.normalized.hist(color='y', bins=150,figsize=(20,10), xlabelsize=20, ylabelsize=20)
plt.title('verification tests run on t2.micro', fontsize=30)
plt.xlabel('Normalized Value (re-execution / original)', fontsiz... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The average of noramlized value of the verification benchmarks is, | df_verification_t2_micro['normalized'].mean() | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Let's see the frequency histogram after removing right-most four outliers. | df_verification_top_benchmakrs = df_verification_rank[df_verification_rank['machine'] == 't2.micro'].head(4)['benchmark']
df_verification_t2_micro_no_outliers = df_verification_t2_micro[~df_verification_t2_micro['benchmark'].isin(df_verification_top_benchmakrs)]
df_verification_t2_micro_no_outliers.normalized.hist(col... | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Print the max the min normalized value, | print(
df_verification_t2_micro_no_outliers['normalized'].max(),
df_verification_t2_micro_no_outliers['normalized'].min()
) | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
The average of noramlized value without the four outliners is, | df_verification_t2_micro_no_outliers['normalized'].mean() | experiments/benchmarking/visualize_2.ipynb | ljishen/kividry | apache-2.0 |
Process Decoding Input
Implement process_decoding_input using TensorFlow to remove the last word id from each batch in target_data and concat the GO ID to the beginning of each batch. | def process_decoding_input(target_data, target_vocab_to_int, batch_size):
"""
Preprocess target data for dencoding
:param target_data: Target Placehoder
:param target_vocab_to_int: Dictionary to go from the target words to an id
:param batch_size: Batch Size
:return: Preprocessed target data
... | language-translation/Project 4 Submission/dlnd_language_translation.ipynb | tkurfurst/deep-learning | mit |
Identifying source code lines
We can now focus on the changed source code lines. We can identify | diff_raw["i"] = diff_raw.raw.str[1:].str.len() - diff_raw.raw.str[1:].str.lstrip().str.len()
diff_raw.head()
%%timeit
diff_raw['added'] = diff_raw.raw.str.extract("^\+( *).*$", expand=True)[0].str.len()
diff_raw['deleted'] = diff_raw.raw.str.extract("^-( *).*$", expand=True)[0].str.len()
diff_raw.head() | prototypes/Complexity over Time (easier way maybe).ipynb | feststelltaste/software-analytics | gpl-3.0 |
Create an input pipeline using tf.data
Next, we will wrap the dataframes with tf.data. This will enable us to use feature columns as a bridge to map from the columns in the Pandas dataframe to features used to train the model.
Here, we create an input pipeline using tf.data. This function is missing two lines. Corr... | # A utility method to create a tf.data dataset from a Pandas Dataframe
def df_to_dataset(dataframe, shuffle=True, batch_size=32):
dataframe = dataframe.copy()
# TODO 1 -- Your code here
if shuffle:
ds = ds.shuffle(buffer_size=len(dataframe))
ds = ds.batch(batch_size)
return ds | courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Now that we have created the input pipeline, let's call it to see the format of the data it returns. We have used a small batch size to keep the output readable. | # TODO 1
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
We can see that the dataset returns a dictionary of column names (from the dataframe) that map to column values from rows in the dataframe.
Numeric columns
The output of a feature column becomes the input to the model. A numeric is the simplest type of column. It is used to represent real valued features. When using th... | # TODO 1
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Scaler function
It is very important for numerical variables to get scaled before they are "fed" into the neural network. Here we use min-max scaling. Here we are creating a function named 'get_scal' which takes a list of numerical features and returns a 'minmax' function, which will be used in tf.feature_column.numeri... | # Scalar def get_scal(feature):
# TODO 1
# TODO 1
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Now that we have created an input pipeline using tf.data and compiled a Keras Sequential Model, we now create the input function for the test data and to initialize the test_predict variable. | # TODO 1
test_predict = test_input_fn(dict(test_data)) | courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
The arrays returns a predicted value. What do these numbers mean? Let's compare this value to the test set.
Go to the test.csv you read in a few cells up. Locate the first line and find the median_house_value - which should be 249,000 dollars near the ocean. What value did your model predict for the median_house_v... | # TODO 2
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Categorical Feature
In this dataset, 'ocean_proximity' is represented as a string. We cannot feed strings directly to a model. Instead, we must first map them to numeric values. The categorical vocabulary columns provide a way to represent strings as a one-hot vector.
Next, we create a categorical feature using 'ocean... | # TODO 2
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Bucketized Feature
Often, you don't want to feed a number directly into the model, but instead split its value into different categories based on numerical ranges. Consider our raw data that represents a homes' age. Instead of representing the house age as a numeric column, we could split the home age into several buck... | # TODO 2
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Feature Cross
Combining features into a single feature, better known as feature crosses, enables a model to learn separate weights for each combination of features.
Next, we create a feature cross of 'housing_median_age' and 'ocean_proximity'. | # TODO 2
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Next we create a prediction model. Note: You may use the same values from the previous prediciton. | # TODO 2
| courses/machine_learning/deepdive2/feature_engineering/labs/3_keras_basic_feat_eng-lab.ipynb | turbomanage/training-data-analyst | apache-2.0 |
Import data | folder = 'hillary-clinton-emails/'
emails = pd.read_csv(folder + 'Emails.csv', index_col='Id')
emails.head(5) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Analyse Emails | emails.head() | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
The columns ExtractedBodyText is supposed to be the content of the mail but some of the mail have a ExtractedBodyText = NaN but the Rawtext seems to contains something | emails.columns
print('Number of emails: ', len(emails))
bodyNaN = emails.ExtractedBodyText.isnull().sum()
print('Number of emails with ExtractedBodyText=NaN: {}, ({:.2f}%)'.format(emails.ExtractedBodyText.isnull().sum(), bodyNaN/ len(emails))) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
We could also use the subject since it is usually a summary of the mail | bodyNaN = emails.ExtractedSubject.isnull().sum()
print('Number of emails with ExtractedSubject=NaN: {}, ({:.2f}%)'.format(emails.ExtractedBodyText.isnull().sum(), bodyNaN/ len(emails))) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Now let's try to combine the subject and the body and drop the mail that have both subject= NaN and body = Nan | subBodyNan = emails[np.logical_and(emails.ExtractedBodyText.isnull(),emails.ExtractedSubject.isnull())]
print('Number of email where both subject and body is NaN: {}({:.2f})'.format(len(subBodyNan), len(subBodyNan)/ len(emails))) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Well, that number is small enough to drop all email where both Extracted subject and Extracted body is NaN.
Let's drop them and create a new columns subjectBody that is the concatenation of the 2 columns ExtractedSubject and ExtractedBody. From now we will work with that columns | emails = emails[~ np.logical_and(emails.ExtractedBodyText.isnull(), emails.ExtractedSubject.isnull())]
len(emails)
emails.ExtractedBodyText.fillna('',inplace=True)
emails.ExtractedSubject.fillna('',inplace=True)
emails['SubjectBody'] = emails.ExtractedBodyText + emails.ExtractedSubject
emails.SubjectBody.head() | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Last check to be sur that our columns of interest don't have anymore NaN | print('Number of NaN in columns SubjectBody: ' ,emails.SubjectBody.isnull().sum()) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Keep only mail that mentions a country
Structure of a country in pycountry.countres | list(pycountry.countries)[0] | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
First we create a dataframe with one line by countries and we count for each countries its occurences in the mail.
Since a country can be reference in many way (Switzerland, switzerland, CH), we need to consider all the possible form.
We may have a problem with word that have many meaning like US(country) and us (pron... | emails.SubjectBody.head(100).apply(print) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Tokenize and remove stopwords |
from gensim import corpora, models, utils
from nltk.corpus import stopwords
sw = stopwords.words('english') + ['re', 'fw', 'fvv', 'fwd']
sw = sw + ['pm', "a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also","although","always","am","a... | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Sentiment analysis
We explain before our precessing. Now we will do the sentiment analysis only on the subject and the body
So we will only consider the subject and the body | sentiments = pd.DataFrame(emails_country.SubjectBody)
sentiments.head()
sentiments.shape | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Analysis
We will do a sentiment analysis on each sentense and then compute a socre for each country
We will compare different module:
- nltk.sentiment.vader that attribute a score to each sentence
- liuhu that has a set of positive word and one of neg word. We count the positif word and neg word in each sentenc... | sentiments.head()
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()
def sentiment_analysis(row):
score = sid.polarity_scores(row)
return pd.Series({'Pos': score['pos'], 'Neg': score['neg'], 'Compound_':score['compound'] })
sentiments = pd.concat([sentiments, senti... | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Liuhu | from nltk.corpus import opinion_lexicon
sentimentsLihuh = pd.read_csv('mailScore.csv', index_col='Id')
#transform the array of positiv and negatif word in dict
dicPosNeg = dict()
for word in opinion_lexicon.positive():
dicPosNeg[word] = 1
for word in opinion_lexicon.negative():
dicPosNeg[word] = -1
... | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Aggregate by countries
We groupe by country and compute the mean of each score | sentiments = pd.read_csv('mailScore2.csv', index_col='Id')
sentiments.head()
def aggScoreByCountry(country):
condition = sentiments.apply(lambda x: np.any(country.isin(x.SubjectBody.split())), axis=1)
sent = sentiments[condition]
if len(sent) == 0:
print(country.Name, -999)
return pd.Series... | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Drop all country that have a score of -999 (they never appear in the mails) | countries = countries[countries.Compound_ != -999]
len(countries) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
It's a lot of country. We will also use a thresold for the appearance. We only keep mails that are mentioned in a minimum number of emails | minimum_appearance = 15
countries_min = countries[countries.Appearance >= minimum_appearance]
len(countries_min) | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Plot
We plot the 2 analysis. The first plot show an historgram with the vador score and in color the appearance in the mail.
In the second plot the histogram shows the liuhu score and in color the appearance in the mail
we only consider countries that are at least mention 15 times. Otherwise we end up with to much coun... | # Set up colors : red to green
countries_sorted = countries_min.sort(columns=['Compound_'])
plt.figure(figsize=(16, 6), dpi=80)
appearance = np.array(countries_sorted.Appearance)
colors = cm.RdYlGn((appearance / float(max(y))))
plot = plt.scatter(appearance, appearance, c=appearance, cmap = 'RdYlGn')
plt.clf()
colorB... | HW05-TamingText/Part2.ipynb | christophebertrand/ada-epfl | mit |
Let's try several polynomial fits to the data: | for j,degree in enumerate(degrees):
for i in range(sub):
#create data - sample from sine wave
x = np.random.random((n,1))*2*np.pi
y = np.sin(x) + np.random.normal(mean,std,(n,1))
#TODO
#create features corresponding to degree - ex: 1, x, x^2, x... | handsOn_lecture10_bias-variance_tradeoff/draft/bias_variance_solutions.ipynb | eecs445-f16/umich-eecs445-f16 | mit |
Here's some of the code you've written so far. Start by running it again. | # Import helpful libraries
import pandas as pd
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
# Load the data, and separate the target
iowa_file_path = '../input/train.csv'
home_data = pd.read_csv(iowa_file_path)
y... | notebooks/machine_learning/raw/ex7.ipynb | Kaggle/learntools | apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.