Está en la página 1de 14

RECOPILACIÓN DE CONOCIMIENTO

Contenido
CSS.....................................................................................................................................................3
GRID...............................................................................................................................................3
Código........................................................................................................................................3
CRITICAL CSS..................................................................................................................................3
Dependencias o librerías................................................................................................................3
Bootstrap4..................................................................................................................................3
SASS................................................................................................................................................3
BEM............................................................................................................................................3
SQL.................................................................................................................................................3
Selecting.....................................................................................................................................3
Ordering.....................................................................................................................................3
Filtering......................................................................................................................................3
Aggregating................................................................................................................................3
Text Manipulation......................................................................................................................3
Join.............................................................................................................................................4
Unifying tables...........................................................................................................................4
CRUD..........................................................................................................................................4
Variables.....................................................................................................................................4
Temporary Tables.......................................................................................................................4
PYTHON..............................................................................................................................................4
DECORATORS.................................................................................................................................4
VIRTUAL ENVIRONMENT................................................................................................................4
DJANGO..........................................................................................................................................4
Start Proyect...............................................................................................................................4
Create Super User......................................................................................................................5
Connect with mysql database....................................................................................................5
ARTIFICIAL INTELLIGENCE...............................................................................................................5
SUPERVISED LEARNING..............................................................................................................5
UNSUERVISED LEARNING...........................................................................................................5
GIT......................................................................................................................................................5
START.............................................................................................................................................5
COMMIT.........................................................................................................................................5
CONNECT TO REPOSITORY.............................................................................................................5
FORCE CONECTION TO REPOSITORY..............................................................................................5
REACT.................................................................................................................................................5
INSTALL..........................................................................................................................................5
INIT PROJECT..................................................................................................................................6
INIT ENVIRONMENT DEVELOPER....................................................................................................6
ANGULAR...........................................................................................................................................6
INIT.................................................................................................................................................6
START.............................................................................................................................................6
BI SOLUTION.......................................................................................................................................7
Process of BI Solution.....................................................................................................................7
Planing BI solution..........................................................................................................................7
Master Data Managment...........................................................................................................7
ETL..............................................................................................................................................7
DataWarehouse.........................................................................................................................7
Data Models...............................................................................................................................7
Reporting and analyzis...............................................................................................................7
CSS
GRID
Código
Display: grid; /*Se utiliza para mostrar el layout de grid*/

CRITICAL CSS
https://jonassebastianohlsson.com/criticalpathcssgenerator/ #Página para obtener
el critical CSS o el css del viewport

Dependencias o librerías
Bootstrap4
https://getbootstrap.com/docs/4.4/getting-started/introduction/ #Para
iniciar a usar Bootstrap

https://getbootstrap.com/docs/4.4/layout/grid/ #Explicación para uso de


grid layout

SASS
BEM
Block __element—modifier

Button__state—red

SQL
Selecting
SELECT

Ordering
ORDER BY

Filtering
WHERE

HAVING

Aggregating
SUM

COUNT

MIN

MAX

AVG

Text Manipulation
LEFT

RIGHT
LEN

SUBSTRING

Join
INNER JOIN

LEFT JOIN

RIGHT JOIN

Unifying tables
UNION

UNION ALL

CRUD
Create

Read

Update

Delete

Variables
DECLARE @myVariable INT #or type

SET @myVariable = Value

Temporary Tables
Select * INTO #myTemporaryTable

PYTHON
DECORATORS
VIRTUAL ENVIRONMENT
pip install virtualenv #instala dependencia

virtualenv mypython #crea el entorno virtual con nombre ‘mypython’ sin escoger la
versión a usar

virtualenv sirinet -p "C:\Program Files (x86)\Microsoft Visual


Studio\Shared\Python36_64\python.exe" #Crea lo mismo que el anterior pero
escogiendo su versión enlazándola con el ejecutable de la versión de python.

mypthon\Scripts\activate #activa el entorno virtual

DJANGO
Start Proyect
django-admin startproject mysite #Write above in console
Create Super User
python manage.py createsuperuser

Connect with mysql database


CREATE DATABASE nombreDB CHARACTER SET utf8mb4;

CREATE USER nombreusuario@localhost IDENTIFIED BY 'pass';

GRANT ALL PRIVILEGES ON nombreDB.* TO nombreusuario@localhost;


FLUSH PRIVILEGES;

pip3 install mysqlclient

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'nombreDB',
'USER': 'nombreusuario',
'PASSWORD': 'pass',
'HOST': 'localhost',
'PORT': '3306',
}
} #Se agrea en settings.py de principal

ARTIFICIAL INTELLIGENCE
SUPERVISED LEARNING
ComunLibraries

KNeighborsClassifier
from sklearn.neighbors import KNeighborsClassifier #import library

knn = KNeighborsClassifier(n_neighbors=6) #using knn with 6


neighbors

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size


= 0.2, random_state=42, stratify=y) #separate the data to train and test after

knn.fit(X_train,y_train) #train model

knn.predict(X_test) #predict target

knn.score(X_test, y_test) #show the score of model, accuracy.

LinearRegression
from sklearn.linear_model import LinearRegression #import Library

reg = LinearRegression() #using LinearRegression method

reg.fit(X_train, y_train) #train model

reg.score(X_test, y_test) #show the score of model, accuracy.

Cross Validation
from sklearn.model_selection import cross_val_score #import Library

cv_scores = cross_val_score(reg, X, y, cv=5) #Cross value method


with cv= number of fold to validation in cross validation
Lasso Regression
from sklearn.linear_model import Lasso #import library

lasso = Lasso(alpha=0.4, normalize=True) #using Lasso Regression


method

lasso.fit(X, y) #train lasso

lasso_coef = lasso.coef_ #coefficients in lasso regression formula

Ridge Regression
from sklearn.linear_model import Ridge

ridge = Ridge(normalize=True)

# Compute scores over range of alphas

for alpha in alpha_space:

ridge.alpha = Alpha # Specify the alpha value to use:


ridge.alpha

ridge_cv_scores = cross_val_score(ridge, X, y, cv=10) # Perform


10-fold CV: ridge_cv_scores

ridge_scores.append(np.mean(ridge_cv_scores)) # Append the mean


of ridge_cv_scores to ridge_scores

ridge_scores_std.append(np.std(ridge_cv_scores)) # Append the


std of ridge_cv_scores to ridge_scores_std

display_plot(ridge_scores, ridge_scores_std) # Display the plot

Metrics for Classification


from sklearn.metrics import classification_report

from sklearn.metrics import confusion_matrix

# Generate the confusion matrix and classification report

print(confusion_matrix(y_test, y_pred))

print(classification_report(y_test, y_pred))

Logistic Regression
from sklearn.linear_model import LogisticRegression

logreg = LogisticRegression()

logreg.fit(X_train, y_train) # Fit the classifier to the training


data

y_pred = logreg.predict(X_test) # Predict the labels of the test


set: y_pred

#in logistic Regression we have a parameter name C that que tune


with GridSearchCv

GridSearchCv
from sklearn.model_selection import GridSearchCV
param_grid = {'C': c_space} #in logistic Regression we have
a parameter of regularization named C that is the invese of
lambda and is used like penality

logreg = LogisticRegression() # Instantiate a logistic


regression classifier: logreg

logreg_cv = GridSearchCV(logreg, param_grid, cv=5) #


Instantiate the GridSearchCV object: logreg_cv

logreg_cv.fit(X,y) # Fit it to the data

DecisionTreeClassifier

#GridSearchCV can be computationally expensive, especially


if you are searching over a large hyperparameter space and
dealing with multiple hyperparameters. A solution to this is
to use RandomizedSearchCV, in which not all hyperparameter
values are tried out. Instead, a fixed number of
hyperparameter settings is sampled from specified
probability distributions. You'll practice
using RandomizedSearchCV in this exercise and see how this
works.

param_dist = {"max_depth": [3, None],

"max_features": randint(1, 9),

"min_samples_leaf": randint(1, 9),

"criterion": ["gini", "entropy"]} # Setup the


parameters and distributions to sample from: param_dist

tree = DecisionTreeClassifier() # Instantiate a Decision


Tree classifier: tree

tree_cv = RandomizedSearchCV(tree, param_dist, cv=5) #


Instantiate the RandomizedSearchCV object: tree_cv

tree_cv.fit(X,y) # Fit it to the data

In addition to C, logistic regression has


a 'penalty' hyperparameter which specifies whether to
use 'l1' or 'l2' regularization. Your job in this exercise
is to create a hold-out set, tune
the 'C' and 'penalty' hyperparameters of a logistic
regression classifier using GridSearchCV on the training
set.

param_dist = {"max_depth": [3, None],

"max_features": randint(1, 9),

"min_samples_leaf": randint(1, 9),


"criterion": ["gini", "entropy"]} # Setup the
parameters and distributions to sample from: param_dist

tree = DecisionTreeClassifier() # Instantiate a Decision


Tree classifier: tree

tree_cv = RandomizedSearchCV(tree, param_dist, cv=5) #


Instantiate the RandomizedSearchCV object: tree_cv

tree_cv.fit(X,y) # Fit it to the data

ElasticNet
from sklearn.linear_model import ElasticNet

l1_space = np.linspace(0, 1, 30)

param_grid = {'l1_ratio': l1_space}

elastic_net = ElasticNet() # Instantiate the ElasticNet


regressor: elastic_net

gm_cv = GridSearchCV(elastic_net, cv=5,


param_grid=param_grid) # Setup the GridSearchCV object:
gm_cv

gm_cv.fit(X_train, y_train) # Fit it to the training data

UNSUPERVISED LEARNING
KMeans
from sklearn.cluster import KMeans # Import KMeans

model = KMeans(n_clusters=3) # Create a KMeans instance with 3 clusters:


model

model.fit(points) # Fit model to points

labels = model.predict(new_points) # Determine the cluster labels of


new_points: labels

import matplotlib.pyplot as plt # Import pyplot

# Assign the columns of new_points: xs and ys

xs = new_points[:,0]

ys = new_points[:,1]

# Make a scatter plot of xs and ys, using labels to define the colors

plt.scatter(xs, ys, c=labels, alpha=0.5)

# Assign the cluster centers: centroids

centroids = model.cluster_centers_
# Assign the columns of centroids: centroids_x, centroids_y

centroids_x = centroids[:,0]

centroids_y = centroids[:,1]

# Make a scatter plot of centroids_x and centroids_y

plt.scatter(centroids_x, centroids_y, marker='D', s=50)

plt.show()

#because we don´t know about how many clusters we need, so, we putt he
next code to find a solution to this problema using many differents
clusters to fit the model and find the best prediction:

ks = range(1, 6)

inertias = []

for k in ks:

# Create a KMeans instance with k clusters: model

model = KMeans(n_clusters=k)

# Fit model to samples

model.fit(samples)

# Append the inertia to the list of inertias

inertias.append(model.inertia_)

# Plot ks vs inertias

plt.plot(ks, inertias, c)

plt.xlabel('number of clusters, k')

plt.ylabel('inertia')

plt.xticks(ks)

plt.show()
#In fact we normally use the cluster that decrease the inertia but it
allow us considerable speed in training.

#after we choose the correct cluster, we use it in a new model, and print
the crosstab to find what is the relation between predicted labels and
correct labels, for example

#varieties Canadian wheat Kama wheat Rosa wheat

#labels

#0 2 60 10

#1 0 1 60

#2 68 9 0

#past table tell us that the labe predicted 0 had 60 times correlation
whit Kama wheat.

# Create a KMeans model with 3 clusters: model

model = KMeans(n_clusters=3)

# Use fit_predict to fit model and obtain cluster labels: labels

labels = model.fit_predict(samples)

print(labels)

print(varieties)

# Create a DataFrame with labels and varieties as columns: df

df = pd.DataFrame({'labels': labels, 'varieties': varieties})

# Create crosstab: ct

ct = pd.crosstab(df['labels'], df['varieties'])

# Display ct

print(ct)

#most of times we had a data that is not normalized or scaled, this makes
that training go slowly, to crrect this, we use the Scaler and Normalizer
from sklearn.

# Perform the necessary imports


from sklearn.cluster import KMeans

from sklearn.preprocessing import StandardScaler

from sklearn.pipeline import make_pipeline

# Create scaler: scaler

scaler = StandardScaler()

# Create KMeans instance: kmeans

kmeans = KMeans(n_clusters=4)

# Create pipeline: pipeline

pipeline = make_pipeline(scaler, kmeans)

# Import pandas

import pandas as pd

# Fit the pipeline to samples

pipeline.fit(samples)

# Calculate the cluster labels: labels

labels = pipeline.predict(samples)

# Create a DataFrame with labels and species as columns: df

df = pd.DataFrame({'labels':labels, 'species':species})

# Create crosstab: ct

ct = pd.crosstab(df['labels'], df['species'])

# Display ct

print(ct)

#Normalizer:

# Import Normalizer

from sklearn.preprocessing import Normalizer


# Create a normalizer: normalizer

normalizer = Normalizer()

# Create a KMeans model with 10 clusters: kmeans

kmeans = KMeans(n_clusters=10)

# Make a pipeline chaining normalizer and kmeans: pipeline

pipeline = make_pipeline(normalizer, kmeans)

# Fit pipeline to the daily price movements

pipeline.fit(movements)

# Import pandas

import pandas as pd

# Predict the cluster labels: labels

labels = pipeline.predict(movements)

# Create a DataFrame aligning labels and companies: df

df = pd.DataFrame({'labels': labels, 'companies': companies})

# Display df sorted by cluster label

print(df.sort_values('labels'))

GIT
START
git init

COMMIT
git add .

git commit -m “[message]: message ”

CONNECT TO REPOSITORY
git remote add origin git@github.com:username/new_repo #Agrega dirección
git pull origin master #actualiza archivo en local

git push origin master #actualiza archivo en remoto

FORCE CONECTION TO REPOSITORY


git push origin master –force

REACT
INSTALL
npm install -g create-react-app

INIT PROJECT
create-react-app -nombre del proyecto-

INIT ENVIRONMENT DEVELOPER


npm run start #en la carpera donde está el proyecto

ANGULAR
INIT
npm install @angular/cli -g # instala angular

ng -v #muestra la versión

ng new angular-material-begin --style=scss #Crea proyecto y usa Sass como


preprocesador

#Las siguientes son librerías que gracias a –save se agregarán a package.json

npm install --save @angular/material @angular/cdk


npm install --save @angular/animations

START
ng serve #Inicia la aplicación en el browser en http://localhost:4200/
BI SOLUTION
Process of BI Solution
Planing BI solution
Alway need to have some considerations like Data Volumen, Analysis and reporting that
includes the query you make in system, number of users and Availability

Master Data Managment


ETL
DataWarehouse
Data Models
Reporting and analyzis

También podría gustarte