<jupyter_start><jupyter_text>Tratamento de dados inconsistentes<jupyter_code>base.loc[base['age']<=0]
print(base.loc[15].age)
print(base.loc[21].age)
print(base.loc[26].age)
# 1-Apagar coluna
# base.drop('age',1,inplace=True)
# Ou 2-Apagar registros
# base.drop(base[base.age <=0].index,inplace=True)
# Ou 3-Preencher manualmente
# Ou 4-Preencher com a média
base.mean()
base.age[base.age>0].mean()
base.loc[base['age']<=0,'age'] = base.age[base.age>0].mean()
print(base.loc[0].age)
print(base.loc[15].age)
print(base.loc[21].age)
print(base.loc[26].age)<jupyter_output>59.017015066929204
40.92770044906149
40.92770044906149
40.92770044906149<jupyter_text>Valores nulos<jupyter_code>base.loc[pd.isnull(base.age)]
## Previsores e classe
previsores = base.iloc[:,1:4]
previsores.head(3)
classe = base.iloc[:,4]
classe.head(3)
import numpy as np
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')

imputer = imputer.fit(previsores.iloc[:, 0:3])
previsores.iloc[:, 0:3] = imputer.transform(previsores.iloc[:,0:3])
print(previsores.loc[0].age)
print(previsores.loc[28].age)
print(previsores.loc[30].age)
print(previsores.loc[31].age)
previsores.head(3)<jupyter_output>59.017015066929204
40.92770044906149
40.92770044906149
40.92770044906149<jupyter_text>Escalonamento de variáveisStandardisation x = (x - média) / desvio<jupyter_code>print(previsores.loc[28].age)
print(previsores.loc[30].age)
print(previsores.loc[31].age)
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
print(scaler.fit(previsores))
print(scaler.mean_)
print(scaler.fit_transform(previsores))
previsores = scaler.fit_transform(previsores)
type(previsores)<jupyter_output><empty_output><jupyter_text>Divisão em base de treinos e testes<jupyter_code>from sklearn.model_selection import train_test_split
previsores_treinamento, previsores_teste, classe_treinamento, classe_teste = train_test_split(previsores, classe, test_size=0.15, random_state=0)
print(previsores_treinamento.shape)
print(classe_treinamento.shape)
print(previsores_teste.shape)
print(classe_teste.shape)
#importação da biblioteca
#criacao do classificador
classificador.fit(previsores_treinamento,classe_treinamento)
previsoes = classificador.predict(previsores_teste)
from sklearn.metrics import confusion_matrix,accuracy_score
precisao = accuracy_score(classe_teste,previsoes)
matriz = confusion_matrix(classe_teste,previsoes)
import collections
collections.Counter(classe_teste)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13277843836702338, 'fraction_numerical': 0.07213634562029331, 'mean_word_length': 9.605042016806722, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '49811', 'license': 'MIT', 'n_tokens_mistral': 1102, 'n_tokens_neox': 1009, 'n_words': 130, 'path': 'notebook/_PreProcess/PreProcess_DadosCredito.ipynb', 'repo_name': 'victorblois/py_datascience', 'size': '2523'}