<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.
# selected_features = df[['names', 'of', 'selected', 'features', 'here']]
data= df.drop(["koi_disposition","koi_period_err1"], axis=1)
selected_features = data.columns
data.head()

# Assign the data to X
X= pd.get_dummies(data)
X.head()<jupyter_output><empty_output><jupyter_text>Create a Train Test SplitUse `koi_disposition` for the y values<jupyter_code># Assign the data to y
# Use Pandas get_dummies to convert categorical data
y = df["koi_disposition"]

# Assign the data to y<jupyter_output><empty_output><jupyter_text>Pre-processingScale the data using the MinMaxScaler and perform some feature selection<jupyter_code>from sklearn.preprocessing import StandardScaler, LabelEncoder,MinMaxScaler
from sklearn.linear_model import LogisticRegression
from tensorflow.keras.utils import to_categorical
# Use train_test_split to create training and testing data
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()
# Scale your data
X_scaler=MinMaxScaler().fit(X_train)
# X_scaler = StandardScaler().fit(X_train)
# y_scaler= StandardScaler().fit(y_train)
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)
# 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)
# y_train_scaled = y_scaler.transform(y_train)
# y_test_scaled = y_scaler.transform(y_test)
# # Convert encoded labels to one-hot-encoding
# y_train_categorical =to_categorical(encoded_y_train)
# y_test_categorical =to_categorical(encoded_y_test)<jupyter_output><empty_output><jupyter_text>Train the Model<jupyter_code>classifier = LogisticRegression()
classifier.fit(X_train_scaled, encoded_y_train)
print(classifier.score(X_train_scaled,encoded_y_train))

print(classifier.score(X_test_scaled,encoded_y_test))
# print(f"Training Data Score: {model2.score(X_train_scaled, y_train)}")
# print(f"Testing Data Score: {model2.score(X_test_scaled, y_test)}")<jupyter_output>Training Data Score: -0.546195889125781
Testing Data Score: -0.5734645577825113<jupyter_text>Hyperparameter TuningUse `GridSearchCV` to tune the model's parameters<jupyter_code># Create the GridSearchCV model
from sklearn.model_selection import GridSearchCV
# Train the model with GridSearch
parameters={"penalty":['l1', 'l2', 'elasticnet', 'none'],"tol":[1e-4,1e-6,1e-2],"C":[1000,100, 0.001]}
clf= GridSearchCV(classifier,parameters)
clf.fit(X_train_scaled,encoded_y_train)
# print(grid2.best_params_)
# print(grid2.best_score_)
print(clf.best_params_)
print(clf.best_score_)<jupyter_output>{'C': 100, 'penalty': 'l2', 'tol': 0.0001}
0.8760195096747901<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.10883190883190884, 'fraction_numerical': 0.0245014245014245, 'mean_word_length': 8.489189189189188, 'pattern_counts': {'":': 3, '<': 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': '425679', 'license': 'RSA-MD', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1250, 'n_words': 269, 'path': 'starter_code/.ipynb_checkpoints/model_1-checkpoint.ipynb', 'repo_name': 'kdaltayli/Machine_Learning_Challenge_KA', 'size': '3510'}