<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>df.columns
# Set features. This will also be used as your x values.
selected_features = df
selected_features.head()<jupyter_output><empty_output><jupyter_text>Create a Train Test SplitUse `koi_disposition` for the y values<jupyter_code>X = df.drop('koi_disposition', axis =1)
y = df['koi_disposition']
print(X.shape, y.shape)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42, stratify=y)
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 numpy import asarray
from sklearn.preprocessing import MinMaxScaler

# define min max scaler
X_scaler = MinMaxScaler().fit(X_train)
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)<jupyter_output><empty_output><jupyter_text>Train the Model<jupyter_code>from sklearn.svm import SVC 
from sklearn.neighbors import KNeighborsClassifier

model_svc = SVC(kernel='linear')
model_svc.fit(X_train_scaled, y_train)
print(f"Training Data Score: {model_svc.score(X_train_scaled, y_train)}")
print(f"Testing Data Score: {model_svc.score(X_test_scaled, y_test)}")
from sklearn.metrics import classification_report
predictions = model_svc.predict(X_test_scaled)
print(classification_report(y_test,predictions))<jupyter_output>precision    recall  f1-score   support

     CANDIDATE       0.76      0.61      0.68       422
     CONFIRMED       0.69      0.79      0.74       450
FALSE POSITIVE       0.99      1.00      0.99       876

      accuracy                           0.85      1748
     macro avg       0.81      0.80      0.80      1748
  weighted avg       0.85      0.85      0.85      1748<jupyter_text>Hyperparameter TuningUse `GridSearchCV` to tune the model's parameters<jupyter_code># 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_search = GridSearchCV(model_svc, param_grid, verbose=3)
# Train the model with GridSearch
grid_search.fit(X_train_scaled, y_train)
print(grid_search.best_params_)
print(grid_search.best_score_)
grid_search.score(X_train_scaled, y_train)
# Make predictions 
predictions = grid_search.predict(X_test_scaled)

# Calculate 
from sklearn.metrics import classification_report
print(classification_report(y_test, predictions))<jupyter_output>precision    recall  f1-score   support

     CANDIDATE       0.84      0.71      0.77       422
     CONFIRMED       0.76      0.86      0.80       450
FALSE POSITIVE       0.99      1.00      0.99       876

      accuracy                           0.89      1748
     macro avg       0.86      0.85      0.86      1748
  weighted avg       0.89      0.89      0.89      1748<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 = 'Jackie.sav'
joblib.dump(model_svc, filename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08475524475524475, 'fraction_numerical': 0.04699300699300699, 'mean_word_length': 3.705263157894737, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '321785', 'license': 'Apache-2.0', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1215, 'n_words': 299, 'path': 'Instructions/starter_code/model_1.ipynb', 'repo_name': 'claire9501/machine-learning-challenge', 'size': '3575'}