Skip to content

Instantly share code, notes, and snippets.

View 64lines's full-sized avatar

Julian Alexander Murillo 64lines

  • Huge Inc.
  • Medellin - Colombia
View GitHub Profile
@64lines
64lines / classification_report_and_confusion_matrix.py
Created November 9, 2017 02:15
[PYTHON][SKLEARN] Clasification Report and Confussion Matrix
# Import necessary modules
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
# Create training and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.4, random_state=42)
# Instantiate a k-NN classifier: knn
knn = KNeighborsClassifier(n_neighbors=6)
@64lines
64lines / crossvalidation.py
Created November 9, 2017 01:53
[PYTHON][SKLEARN] K-Fold Cross Validation
# Import necessary modules
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import cross_val_score
# Create a linear regression object: reg
reg = LinearRegression()
# Perform 3-fold CV
cvscores_3 = cross_val_score(reg, X, y, cv=3)
print(np.mean(cvscores_3))
@64lines
64lines / lasso.py
Created November 9, 2017 01:49
[PYTHON][SKLEARN] Lasso Regression
# Import Lasso
from sklearn.linear_model import Lasso
# Instantiate a lasso regressor: lasso
lasso = Lasso(alpha=0.4, normalize=True)
# Fit the regressor to the data
lasso.fit(X, y)
# Compute and print the coefficients
# /etc/systemd/system/oracle-rdbms.service
# Ivan Kartik http://ivan.kartik.sk
# Invoking Oracle scripts to start/shutdown Instances defined in /etc/oratab
# and starts Listener
[Unit]
Description=Oracle Database(s) and Listener
Requires=network.target
[Service]
@64lines
64lines / accuracy.py
Last active November 6, 2017 19:56
[PYTHON][SKLEARN] Measuring Accuracy Linear Regression Models
# Import necessary modules
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
# Create training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state=42)
# Create the regressor: reg_all
reg_all = LinearRegression()
@64lines
64lines / regression.py
Last active November 6, 2017 19:56
[PYTHON][SKLEARN] Linear Regression Predictions
# Import LinearRegression
from sklearn.linear_model import LinearRegression
# Create the regressor: reg
reg = LinearRegression()
# Create the prediction space
prediction_space = np.linspace(min(X_fertility), max(X_fertility)).reshape(-1,1)
# Fit the model to the data
@64lines
64lines / heatmaps.py
Created November 6, 2017 19:01
[PYTHON][PLOTTING] - Heat Maps
sns.heatmap(df.corr(), square=True, cmap='RdYlGn')
@64lines
64lines / reshaping.py
Created November 6, 2017 18:57
[PYTHON][RESHAPING] - Reshaping Arrays
# Import numpy and pandas
import numpy as np
import pandas as pd
# Read the CSV file into a DataFrame: df
df = pd.read_csv('gapminder.csv')
# Create arrays for features and target variable
y = df['life'].values
X = df['fertility'].values
@64lines
64lines / plotting.py
Created November 6, 2017 17:22
[PYTHON] Plotting K-Neighbors accuracy
import matplotlib.pyplot as plt
# Setup arrays to store train and test accuracies
neighbors = np.arange(1, 9)
train_accuracy = np.empty(len(neighbors))
test_accuracy = np.empty(len(neighbors))
# Loop over different values of k
for i, k in enumerate(neighbors):
# Setup a k-NN Classifier with k neighbors: knn
@64lines
64lines / accuracy.py
Created November 6, 2017 17:06
[PYTHON][SKLEARN] Measuring Accuracy KNeighbors Classifier Predictions
# Import necessary modules
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
# Create feature and target arrays
X = digits.data
y = digits.target
# Split into training and test set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=42, stratify=y)