<jupyter_start><jupyter_text>Aquisição de dados---<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt 

df = pd.read_csv("../data/01_raw/train.csv")
df.head()<jupyter_output><empty_output><jupyter_text>Pré Processamento---<jupyter_code>df.isna().sum().sort_values(ascending=False)
df.Survived.value_counts()
df.Embarked.value_counts()
label_df = df["Survived"]

feat_cols = df.columns
feat_cols = feat_cols.drop(["Survived","Name","Ticket","Cabin"])

features_df = df[feat_cols]
features_df.head()
from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(features_df, label_df, 
                                                    test_size=0.33, random_state=42)
from sklearn.preprocessing import LabelEncoder

category_cols = ["Sex", "Embarked"]

# Label encode categorical features
le = {}
for col in category_cols:
    le[col] = LabelEncoder()
    X_train[col] = le[col].fit_transform(X_train[col])
X_train.fillna(0.0, inplace=True)
from sklearn.preprocessing import StandardScaler

ss = StandardScaler()
X_train = ss.fit_transform(X_train)
from imblearn.over_sampling import SMOTE

oversample = SMOTE()
X_, y_ = oversample.fit_resample(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Dados de entrada<jupyter_code>import pickle

with open('../data/05_model_input/input_data_exp1.pkl', 'wb') as handle:
    pickle.dump({'X': X_, 'y': y_}, handle)<jupyter_output><empty_output><jupyter_text>Criação do Modelo---<jupyter_code>with open('../data/05_model_input/input_data_exp1.pkl', 'rb') as handle:
    input_data = pickle.load(handle)
    
X, y = input_data['X'], input_data['y']
import xgboost as xgb

clf = xgb.XGBClassifier(
    n_estimators=300,
    max_depth=15
)
clf.fit(X, y)<jupyter_output>c:\users\lucas\anaconda3\envs\titanic\lib\site-packages\xgboost\sklearn.py:888: UserWarning: The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].
  warnings.warn(label_encoder_deprecation_msg, UserWarning)<jupyter_text>Salvando os modelos<jupyter_code>import pickle

with open("../data/06_models/model.pkl", "wb") as handle:
    pickle.dump({"model": clf, "se": ss, "le":le}, handle)<jupyter_output><empty_output><jupyter_text>Validação do Modelo---<jupyter_code>with open("../data/06_models/model.pkl", "rb") as handle:
    data = pickle.load(handle)
for col in category_cols:
    X_test[col] = le[col].transform(X_test[col])
X_test.fillna(0.0, inplace=True)
X_test = ss.transform(X_test)
from sklearn.metrics import plot_confusion_matrix

plot_confusion_matrix(clf, X_test, y_test, normalize="true")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13233761722820422, 'fraction_numerical': 0.012851684612712747, 'mean_word_length': 5.605504587155964, 'pattern_counts': {'":': 3, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '454785', 'license': 'MIT', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1063, 'n_words': 205, 'path': 'Titanic/.ipynb_checkpoints/Exp1-checkpoint.ipynb', 'repo_name': 'Lucas-Buk/Data_Mining', 'size': '2879'}