<jupyter_start><jupyter_text>Anotações preciosas do Módulo II - curso IGTI. Python para análise de Dados.  Numpy<jupyter_code>import numpy as np
l=[1,2,3]
x= np.array(l)
print('x: ',x)
print(x.shape)
l = [2,2]
x = np.zeros(l)
print(x)
gamma = np.linspace(1, 47, 3) #mesmo espaço entre esse range
print(gamma)
gamma[1]
# o slice é compartilhado na memória
x = np.array([1,2,3])
print("x antes: ", x)
y = x[:2]
y[0] = -100
print("x depois: ", x)
print("ipisilon: ", y)<jupyter_output>x antes:  [1 2 3]
x depois:  [-100    2    3]
ipisilon:  [-100    2]<jupyter_text>Produto Matriarcal e vetorial<jupyter_code>a = [1,0]
b = [2,1]
c = [4,5]
print(a+b)
print(a@c)<jupyter_output>[1, 0, 2, 1]<jupyter_text>Transformando em Numpy Array<jupyter_code>A = np.array([1,2,3])
B = np.array([2,0,2])
s = 3
print(A > B)
print(A==B)
cond = A<=2
D = A[cond]
print(D)<jupyter_output><empty_output><jupyter_text>Comparação<jupyter_code>x = np.array([[1,2],[3,4]])
y = np.array([1.5, 3.5])
print('comparanado x menor ou igual a 2', x<=2)
x = np.array([[1,2,3],
     [4,5,6],
     [7,8,9]])
print(x.reshape(9,1))<jupyter_output><empty_output><jupyter_text>Biblioteca Matplotlib<jupyter_code>import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Plotando gráfico<jupyter_code>plt.figure(figsize=(10,5))
plt.plot(x,y,'o', label="dados originais")
plt.legend()
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.show()
x,y = np.array(x).reshape(-1,1), np.array(y).reshape(-1,1)
np.hstack(x, np.ones(x.shape))
beta = np.linalg.pinv(x).dot(y)
print("a estimado", beta[0][0])
print("b estimado", beta[1][0])
import pandas as pd
#leitura de dados csv
df = pd.read_csv('http://pycourse.s3.amazonaws.com/temperature.csv')
df<jupyter_output><empty_output><jupyter_text>Leitura de Dados do Excel<jupyter_code>df_xlx = pd.ExcelFile('http://pycourse.s3.amazonaws.com/temperature.xlsx')
df2 = pd.read_excel(df_xlx, sheet_name='Sheet1') 
df2
df.head(3)<jupyter_output><empty_output><jupyter_text>Especificando o tamanho da amostra de dados<jupyter_code>df.tail(2)
df.dtypes

df.describe() #estatística humilde
df.info()
df.columns = ['col 1', 'col 2 teste'] #renomear a coluna
df['classification']=='quente'<jupyter_output><empty_output><jupyter_text>Condicional em amostra de dados<jupyter_code>df[df['classification']=='quente']
print(df.loc[df['classification'] == 'quente', 'temperatura'])<jupyter_output>[29.1 28.5 28. ]<jupyter_text>Conversão de data<jupyter_code>df['date'] = pd.to_datetime(df['date'])
df.dtypes
df = df.set_index('date')
df
df[df['temperatura'] >=25]<jupyter_output><empty_output><jupyter_text>Redes Neurais  Biblioteca Sklearn<jupyter_code>from sklearn.preprocessing import LabelEncoder
from sklearn.linear_model import LogisticRegression
x,y = df[['temperatura']].values, df[['classification']].values #EXÓGENAS E O QUE QUEREMOS PREDITAR, respectivamente.
print(x)
print(y)

LabelEncoder?
le = LabelEncoder()
y = le.fit_transform(y.ravel()) #codificação para input
print("y \n", y)
#classfier
clf = LogisticRegression()
clf.fit(x,y) #modelo treinado
x_test = np.linspace(start=0., stop=45., num=100).reshape(-1,1) #ver o que ele vai gerar para valores distintos, sem amostras
y_pred = clf.predict(x_test)
print(y_pred)<jupyter_output>[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2
 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2]<jupyter_text>Transformação padrão para a regressão linear q está implementada<jupyter_code>y_pred = le.inverse_transform(y_pred)
print(y_pred)
print(x_test)<jupyter_output><empty_output><jupyter_text>Prática Scikit Learn<jupyter_code>def classifyTemp():
  ask = True
  while ask:
    temp = input('Digite a temp:')
    temp = np.array(float(temp)).reshape(-1,1)
    class_temp = clf.predict(temp)
    class_temp=le.inverse_transform(class_temp)
    print(f'A classificação da temperatura {temp.ravel()[0]} é {class_temp[0]}')
    ask = input('Continuar: [S/N]').upper()[0] == 'S'
classifyTemp()
print('Obrigado!')
x = np.array([-1.,-0.7777778, -0.5555554, -0.344444, -0.111111111115, 0.1111111112, 0.3333333, 0.55555, 0.777777777, 1. ])
y = np.array([-1.13952846, -0.571454, -0.2154684,  0.45648465165151, 0.5148585, 1.256465561, 1.6265868486, 2.1786, 2.3486, 2.568941684])
plt.figure(figsize=(10,5))
plt.plot(x, y, 'o', label="dados originais")
plt.legend()
plt.xlabel("x")
plt.ylabel("y")
plt.grid()
plt.show()
x,y = x.reshape(-1,1),y.reshape(-1,1)
reg = LinearRegression()
reg.fit(x,y)
print(reg.coef_)<jupyter_output><empty_output><jupyter_text>Mostrando todos os campos no Google Colab<jupyter_code>%load_ext google.colab.data_table
df.describe()<jupyter_output>The google.colab.data_table extension is already loaded. To reload it, use:
  %reload_ext google.colab.data_table<jupyter_text>Upload e Configuração com Google Drive<jupyter_code>from google.colab import drive
drive.mount('/gdrive')
with open('/gdrive/My Drive/foo.txt', 'w') as f:
  f.write('Hello Google Drive!')
!cat '/gdrive/My Drive/foo.txt'<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1648223645894001, 'fraction_numerical': 0.07377208309066201, 'mean_word_length': 5.384138785625774, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '482099', 'license': 'MIT', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2246, 'n_words': 477, 'path': 'modulo2.ipynb', 'repo_name': 'diogojorgebasso/bootcamp-python-', 'size': '5151'}