<jupyter_start><jupyter_text>Random Forest Base Credit Data<jupyter_code>from sklearn import tree 
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
import pickle
with open('credit.pkl','rb') as f: #importação
  X_credit_treinamento, y_credit_treinamento, X_credit_teste, y_credit_teste = pickle.load(f)
X_credit_teste.shape, y_credit_teste.shape
 X_credit_treinamento.shape, y_credit_treinamento.shape
random_forest_credit = RandomForestClassifier(n_estimators=100, criterion='entropy', random_state=0)#'n_estimator é o numero de arvores que irá conter
random_forest_credit.fit(X_credit_treinamento, y_credit_treinamento)<jupyter_output><empty_output><jupyter_text>Previsões<jupyter_code>previsoes = random_forest_credit.predict(X_credit_teste)
previsoes<jupyter_output><empty_output><jupyter_text>comparação com as respostas reais<jupyter_code>y_credit_teste
from sklearn.metrics import accuracy_score, classification_report
accuracy_score(y_credit_teste, previsoes)<jupyter_output><empty_output><jupyter_text>Matriz de confusão<jupyter_code>from yellowbrick.classifier import ConfusionMatrix
cm = ConfusionMatrix(random_forest_credit)
cm.fit(X_credit_trinamento, y_credit_treinamento) #treinamento
cm.score(X_credit_teste, y_credit_teste) #calculo do score  
print(classification_report(y_credit_teste, previsoes))<jupyter_output>precision    recall  f1-score   support

           0       0.99      0.99      0.99       436
           1       0.95      0.91      0.93        64

    accuracy                           0.98       500
   macro avg       0.97      0.95      0.96       500
weighted avg       0.98      0.98      0.98       500<jupyter_text>Base Census<jupyter_code>with open('census.pkl', 'rb') as f:
    X_census_treinamento, y_census_treinamento, X_census_teste, y_census_teste = pickle.load(f)

    X_census_treinamento.shape, y_census_treinamento.shape #base de treinamento

 X_census_teste.shape, y_census_teste.shape
y_census_treinamento<jupyter_output><empty_output><jupyter_text>Treinamento<jupyter_code>random_forest_census = RandomForestClassifier(n_estimators=40, criterion='entropy', random_state=0)
random_forest_census.fit(X_census_treinamento, y_census_treinamento)<jupyter_output><empty_output><jupyter_text>previsão<jupyter_code>previsoes = random_forest_census.predict(X_census_teste)
previsoes
y_census_teste
from sklearn.metrics import accuracy_score, classification_report
accuracy_score(y_census_teste, previsoes)<jupyter_output><empty_output><jupyter_text>Matriz de confusão<jupyter_code>from yellowbrick.classifier import ConfusionMatrix
cm = ConfusionMatrix(random_forest_census)
cm.fit(X_credit_trinamento, y_census_treinamento) #treinamento
cm.score(X_census_teste, y_census_teste) #calculo do score  
print(classification_report(y_census_teste, previsoes))<jupyter_output>precision    recall  f1-score   support

       <=50K       0.88      0.93      0.90      3693
        >50K       0.72      0.61      0.66      1192

    accuracy                           0.85      4885
   macro avg       0.80      0.77      0.78      4885
weighted avg       0.84      0.85      0.84      4885
{'fraction_non_alphanumeric': 0.07140610254797106, 'fraction_numerical': 0.03994966970745518, 'mean_word_length': 4.618374558303887, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '521372', 'license': 'MIT', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1141, 'n_words': 182, 'path': 'Random_Forest.ipynb', 'repo_name': 'GGMmattos/Machine-Learning-And-Data-Science', 'size': '3179'}