<jupyter_start><jupyter_text>Read the CSV and Perform Basic Data Cleaning<jupyter_code>df = pd.read_csv("resources/exoplanet_data.csv")
# Drop the null columns where all values are null
df = df.dropna(axis='columns', how='all')
# Drop the null rows
df = df.dropna()
df.head()<jupyter_output><empty_output><jupyter_text>Select your features (columns)<jupyter_code># Set features. This will also be used as your x values.
#selected_features = df[['names', 'of', 'selected', 'features', 'here']]
feature_list = df.columns.to_list()
feature_list.remove("koi_disposition")

removal_list = []
for x in feature_list:
    if "err" in x:
        removal_list.append(x)
print(removal_list)
        
selected_features = df[feature_list].drop(columns=removal_list)
selected_features.head()<jupyter_output>['koi_period_err1', 'koi_period_err2', 'koi_time0bk_err1', 'koi_time0bk_err2', 'koi_impact_err1', 'koi_impact_err2', 'koi_duration_err1', 'koi_duration_err2', 'koi_depth_err1', 'koi_depth_err2', 'koi_prad_err1', 'koi_prad_err2', 'koi_insol_err1', 'koi_insol_err2', 'koi_steff_err1', 'koi_steff_err2', 'koi_slogg_err1', 'koi_slogg_err2', 'koi_srad_err1', 'koi_srad_err2']<jupyter_text>Create a Train Test SplitUse `koi_disposition` for the y values<jupyter_code>from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(selected_features, df["koi_disposition"], random_state=13)
X_train.head()<jupyter_output><empty_output><jupyter_text>Pre-processingScale the data using the MinMaxScaler and perform some feature selection<jupyter_code># Scale your data
from sklearn.preprocessing import MinMaxScaler
X_scaler = MinMaxScaler().fit(X_train)
#y_scaler = MinMaxScaler().fit(y_train)

X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)
#y_train_scaled = y_scaler.transform(y_train)
#y_test_scaled = y_scaler.transform(y_train)<jupyter_output><empty_output><jupyter_text>Train the Model<jupyter_code>from sklearn import tree
decision_tree_model = tree.DecisionTreeClassifier()
decision_tree_model = decision_tree_model.fit(X_train, y_train)

print(f"Training Data Score: {decision_tree_model.score(X_train_scaled, y_train)}")
print(f"Testing Data Score: {decision_tree_model.score(X_test_scaled, y_test)}")<jupyter_output>Training Data Score: 0.6055693305359527
Testing Data Score: 0.5835240274599542<jupyter_text>Hyperparameter TuningUse `GridSearchCV` to tune the model's parameters<jupyter_code>decision_tree_model.get_params()
# Create the GridSearchCV model
from sklearn.model_selection import GridSearchCV
param_grid = {'C': [1, 5, 10, 50],
              'gamma': [0.0001, 0.0005, 0.001, 0.005]}
grid = GridSearchCV(decision_tree_model, param_grid, verbose=3)
# Train the model with GridSearch
grid.fit(X_train,y_train)
print(grid.best_params_)
print(grid.best_score_)<jupyter_output><empty_output><jupyter_text>Save the Model<jupyter_code># save your model by updating "your_name" with your name
# and "your_model" with your model variable
# be sure to turn this in to BCS
# if joblib fails to import, try running the command to install in terminal/git-bash
import joblib
filename = 'your_name.sav'
joblib.dump(your_model, filename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10984264116013576, 'fraction_numerical': 0.025609379821042888, 'mean_word_length': 8.262857142857143, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '1022', 'license': 'MIT', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1192, 'n_words': 242, 'path': 'model_1 - DecisionTree.ipynb', 'repo_name': 'RussellMcGrath/machine-learning-challenge', 'size': '3241'}