<jupyter_start><jupyter_text>Read the CSV and Perform Basic Data Cleaning<jupyter_code>df = pd.read_csv("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.
X = df.drop("koi_disposition", axis=1)
y = df["koi_disposition"]
print(X.shape, y.shape)<jupyter_output>(6991, 40) (6991,)<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(X, y, random_state=42)
X_train.head()
y_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)
X_train_minmax = X_scaler.transform(X_train)
X_test_minmax = X_scaler.transform(X_test)
from sklearn.preprocessing import LabelEncoder

# Label-encode data set
label_encoder = LabelEncoder()
label_encoder.fit(y_train)

encoded_y_train = label_encoder.transform(y_train)
encoded_y_test = label_encoder.transform(y_test)
!pip install keras
import tensorflow as tf
from keras.models import Sequential
from keras.utils import to_categorical
from keras.layers import Dense
from sklearn.preprocessing import LabelEncoder
# One-hot encoding
one_hot_y_train = to_categorical(encoded_y_train)
one_hot_y_test = to_categorical(encoded_y_test)

one_hot_y_train<jupyter_output><empty_output><jupyter_text>Train the Model<jupyter_code>model2 = Sequential()
model2.add(Dense(units=100, activation='relu', input_dim=40))
model2.add(Dense(units=3, activation='softmax'))
# Compile the model
model2.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
# Fit the model to the training data
model2.fit(
    X_train_minmax,
    one_hot_y_train,
    epochs=100,
    shuffle=True,
    verbose=2
)
model_loss, model_accuracy = model2.evaluate(
    X_test_minmax, one_hot_y_test, verbose=2)
print(
    f"Normal Neural Network - Loss: {model_loss}, Accuracy: {model_accuracy}")<jupyter_output>55/55 - 0s - loss: 0.2686 - accuracy: 0.8947
Normal Neural Network - Loss: 0.2686375677585602, Accuracy: 0.8947368264198303<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 = 'model_3.sav'
#joblib.dump(model2, filename)

model2.save('model_3')

import numpy as np
import tensorflow as tf
from tensorflow import keras
model_3_saved = tf.keras.models.load_model('model_3')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09665551839464882, 'fraction_numerical': 0.028428093645484948, 'mean_word_length': 6.496240601503759, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '366381', 'license': 'ADSL', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1048, 'n_words': 251, 'path': 'starter_code/model_3.ipynb', 'repo_name': 'bnatha/machine-learning-challenge', 'size': '2990'}