The following template creates one AWS Systems Manager parameter resource and consumes the TTL stack as a nested resource, passing its name as a reference and the TTL as 5 minutes. When the TTL has elapsed, A lambda function called "DeleteCFNLambda" will delete the main stack as well as clean up the nested stack.
Description: Demo stack, creates one SSM parameter and gets deleted after 5 minutes.
Description: "SSM Parameter for running date command."
StackName: !Ref 'AWS::StackName'
The External template that will create a lambda function is available here...
Labels: aws, aws_cloudformation
streamlit is an ultimate visualization tool with built-in pandas and altair support.
It is very easy to get started...
# start the standard python + pandas container:
docker run -p 8501:8501 -d shantanuo/notebook
# login to container:
docker exec -it 12345 bash
# install within the container:
pip install streamlit
# start the app:
streamlit run https://raw.githubusercontent.com/streamlit/demo-uber-nyc-pickups/master/app.py
# Visit the URL with port 8501 that we have already exposed using --net parameter, for e.g.:
Labels: pandas, python, usability
If I have parent-child relations defined in a pandas dataframe, how do I find the child elements of a given "boss"?
For e.g. in this example, B reports to A while C and D are reporting to B. How do I find B's assistants?
import pandas as pd
data = [["A", "B"], ["B", "C"], ["B", "D"], ["X", "Y"], ["X", "D"], ["Y", "Z"]]
df = pd.DataFrame(data=data, columns=["parent", "child"])
# This is a networkx problem!
import networkx as nx
dg = nx.from_pandas_edgelist(df, source="parent", target="child", create_using=nx.DiGraph)
Labels: pandas, python
This cloudformation template will create an elastic instance that can be used for testing.
It will not have a password and will be accessible from any IP address. It means unsecure but good enough for testing with dummy data.
Labels: aws, aws_cloudformation, elastic, usability
The ultimate goal of solving a system of linear equations is to find the values of the unknown variables. Here is an example of a system of linear equations with two unknown variables, x (Child) and y (adults):
Bus: 3 * x + 3.2 * y = 118.4
Train: 3.5 * x + 3.6 * y = 135.20
A group took a trip on a bus, at $3 per child and $3.20 per adult for a total of $118.40. They took the train back at $3.50 per child and $3.60 per adult for a total of $135.20.
How many children, and how many adults were in the group?
numpy implementation has inv (inverse) and dot methods:
A = np.array([[3, 3.2], [3.5, 3.6]])
B = np.array([118.4, 135.2])
# numpy also has solve method that is easier to use:
Labels: machine_learning, python
Here is the code that will load the popular mnist digits data and apply Support Vector Classifier. The overall accuracy is 97% for this multi-class classification problem and that is not bad for 10 lines of code!
from sklearn import datasets, svm, metrics
digits = datasets.load_digits()
n_samples = len(digits.images)
data = digits.images.reshape((n_samples, -1))
classifier = svm.SVC(gamma=0.001)
classifier.fit(data[: n_samples // 2], digits.target[: n_samples // 2])
predicted = classifier.predict(data[n_samples // 2 :])
expected = digits.target[n_samples // 2 :]
print (metrics.confusion_matrix(expected, predicted))
# Optionally, we can save the model using pickle.
with open('mymodel.pkl', 'wb') as file:
pickle.dump(classifier, file, protocol=pickle.HIGHEST_PROTOCOL)
Labels: machine_learning, python
I was trying to launch an Amazon Redshift cluster in a specific VPC, but I could not select any VPC in the drop-down list. I checked that a VPC exist (though it's not default one!)
In order to resolve this, follow these 3 steps to create a cluster subnet group.
1) click "Security" from redshift console.
2) On the Subnet Groups tab, click Create Cluster Subnet Group.
3) Specify a Name, Description, VPC ID and Click add "all the subnets" link.
Labels: athena, aws, redshift
Here is the copy command to load data from parquet file format to existing table in redshift.
copy favoritemovies from 'S3://some_bucket/parquet_file/'
The IAM role needs to be created using the steps mentioned below:
To create an IAM role to allow Amazon Redshift to access AWS services
1) Open the IAM Console.
2) In the navigation pane, choose Roles.
3) Choose Create role.
4) Choose AWS service, and then choose Redshift.
5) Under Select your use case, choose Redshift - Customizable and then choose Next: Permissions.
6) The Attach permissions policy page appears. choose
AmazonS3ReadOnlyAccess, AWSGlueConsoleFullAccess and AmazonAthenaFullAccess.
7) Choose Next: Tags.
8) Choose Next: Review.
9) For Role name, type a name for your role, for example RedshiftCopyUnload. Choose Create role.
Now you need to attach the role to the current cluster.
1) Sign in to the AWS Management Console and open the Amazon Redshift console
2) In the navigation pane, choose Clusters.
3) In the list, choose the cluster that you want to manage IAM role associations for. Choose Manage IAM Roles.
4) Select your IAM role from the Available roles list to associate or remove current one.
5) choose Apply Changes to update the IAM roles that are associated with the cluster.
Labels: athena, aws, redshift
Let’s suppose we have a large collection of questions and answers. A user can ask a question, and we want to retrieve the most similar question in our collection to help them find an answer.
* "zipping up files" should return "Compressing / Decompressing Folders & Files"
* "determine if something is an IP" should return "How do you tell whether a string is an IP or a hostname"
* "translate bytes to doubles" should return "Convert Bytes to Floating Point Numbers in Python"
Because that is the closest entry of all.
The indexed document should look like this...
'tags': ['xcode', 'git', 'osx', 'version-control', 'gitignore'],
'title': 'Git ignore file for Xcode projects',
'body': 'Which files should I include in .gitignore when using Git in conjunction with Xcode? ',
The title_vector has exactly 512 elements in it for all records irrespective of the number of words in the title. This is because we are using google tensorflow "Universal Sentence Encoder".
Here is the article on this topic:
And github repo:
If you want to test the application:
docker run --name text_embeddings -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -d shantanuo/textembeddings
docker exec -it text_embeddings bash
Labels: elastic, machine_learning