Skip to content

Instantly share code, notes, and snippets.

View rpgd60's full-sized avatar

Rafael Portillo rpgd60

View GitHub Profile
@rpgd60
rpgd60 / missing1.py
Last active August 21, 2019 16:31
[Data preparation - missing values] Tips to handle missing values to improve accuracy #pandas #pyplot
# Preliminary investigation
# Shape of training data (num_rows, num_columns)
print(X_train.shape)
# Number of missing values in each column of training data
missing_val_count_by_column = (X_train.isnull().sum())
print(missing_val_count_by_column[missing_val_count_by_column > 0])
# Result
'''
@rpgd60
rpgd60 / visualize_classifier.py
Last active August 26, 2019 05:24
Helper function to visualize classifiers #randomforest #visualization
# Source: https://jakevdp.github.io/PythonDataScienceHandbook/05.08-random-forests.html
#
def visualize_classifier(model, X, y, ax=None, cmap='rainbow'):
ax = ax or plt.gca()
# Plot the training points
ax.scatter(X[:, 0], X[:, 1], c=y, s=30, cmap=cmap,
clim=(y.min(), y.max()), zorder=3)
ax.axis('tight')
ax.axis('off')
# Typical / useful include
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pandas_profiling as pp
import plotly.express as px
import plotly.graph_objs as go
from plotly.offline import iplot
import plotly.express as px
@rpgd60
rpgd60 / boxplot.df1.py
Last active September 8, 2019 13:22
Dataframe plot - boxes for each column side by side
import numpy as np;
import pandas as pd
import matplotlib.pyplot as plt
np.random.seed(42)
# df from np.ndarray
df = pd.DataFrame(data = np.random.random(size=(4,4))*100, columns = ['A','B','C','D'])
df.plot(kind='box')
plt.show()
@rpgd60
rpgd60 / 1. Numpy_Introduction.py
Created September 8, 2019 13:29 — forked from shivashriti/1. Numpy_Introduction.py
Python for Data Science
import numpy as np
positions = ['GK', 'M', 'A', 'D']
heights = [191, 184, 185, 180]
# Convert positions and heights to numpy arrays: np_positions, np_heights
np_heights = np.array(heights)
np_positions = np.array(positions)
# Heights of the goalkeepers: gk_heights
@rpgd60
rpgd60 / vpc.example.yaml
Last active April 13, 2020 09:44
Cloudformation - Create VPC and subnets from two AZs
---
Parameters:
ipBlockParam:
Description: IP cidr block for VPC
Default: "172.16.0.0/16"
Type: String
MinLength: '9'
MaxLength: '18'
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
@rpgd60
rpgd60 / workstation-external-ip.tf
Created June 11, 2020 04:59
Terraform automate obtaining public workstation ID to populate security groups source CIDR
# Source: https://github.com/terraform-providers/terraform-provider-aws/blob/master/examples/eks-getting-started/workstation-external-ip.tf
#
# Workstation External IP
#
# This configuration is not required and is
# only provided as an example to easily fetch
# the external IP of your local workstation to
# configure inbound EC2 Security Group access
# to the Kubernetes cluster.
#
@rpgd60
rpgd60 / amzn2-ami-ssm.tf
Created April 18, 2022 05:45
Terraform get amazon linux 2 AMI through SSM parameters
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.6" # v3.38.0 minimal version to use default tags
}
}
}
provider "aws" {
@rpgd60
rpgd60 / amzn2_linux5_ami.tf
Created May 1, 2022 09:18
Terraform data source : aws amazon 2 linux 5 ami filter
data "aws_ami" "amazon_linux2_kernel_5" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-kernel-5.10-hvm-2.0*x86_64-gp2"]
}
filter {
@rpgd60
rpgd60 / outputs.tf
Created May 1, 2022 09:23
Use terraform outputs to ssh to instance
## Assume aws_instance resource called "flask1"
output "public_ip" {
description = "Public IP of instance"
value = aws_instance.flask1.public_ip
}
output "key_name" {
description = "SSH Key Name"
value = aws_instance.flask1.key_name