This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
np.random.seed(123) #generamos semilla | |
variables = ['X', 'Y', 'Z'] #variables | |
labels = ['ID_0', 'ID_1', 'ID_2', 'ID_3', 'ID_4'] #valores | |
X = np.random.random_sample([5, 3])*10 #Le damos valores | |
df = pd.DataFrame(X, columns=variables, index=labels) #Creamos nuestro dataframe aleatorio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importamos las librerrias | |
from pyclustering.cluster.clarans import clarans; | |
from pyclustering.utils import timedcall; | |
import pyreadstat | |
#cargamos la data | |
filesav = 'datos/democracias_latam.sav' | |
df, meta = pyreadstat.read_sav(filesav ) | |
df.head(25) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#crear un h2oframe desde pandas | |
df_medicine = h2o.H2OFrame(df) | |
#Convertir H2Odataframe a un Dataframe de Pandas | |
df_python=h2o.h2o.as_list(df_medicine, use_pandas=True) | |
type(df_python) | |
#Encoding | |
from collections import defaultdict | |
from sklearn import preprocessing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests #pip install requests | |
from bs4 import BeautifulSoup as bs # pip install beautifulsoup4 | |
#Load our first page: | |
r = request.get("URL") | |
#Convert to a beautiful soup object | |
soup = bs(r.content) | |
#Print our html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import train_test_split | |
from sklearn import svm | |
from sklearn.metrics import accuracy_score | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) | |
model = svm.SVC() | |
model.fit(X_train, y_train) | |
predictions = model.predict(X_test) |