<jupyter_start><jupyter_text><jupyter_code># Update sklearn to prevent version mismatches
!pip install sklearn --upgrade
# install joblib. This will be used to save your model. 
# Restart your kernel after installing 
!pip install joblib
import pandas as pd
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()
# Set features. This will also be used as your x values.
#selected_features = df[['names', 'of', 'selected', 'features', 'here']]
X = df.drop("koi_disposition", axis=1)
y = df["koi_disposition"]
print(X.shape, y.shape)
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, MinMaxScaler
from tensorflow.keras.utils import to_categorical
X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=1, stratify=y)
X_train.head()
# Scale your data
X_scaler = MinMaxScaler().fit(X_train)
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)
# Create the SVC Model
from sklearn.svm import SVC 
model2 = SVC(kernel='linear')
model2
model2.fit(X_train_scaled, y_train)
print(f"Training Data Score: {model2.score(X_train_scaled, y_train)}")
print(f"Testing Data Score: {model2.score(X_test_scaled, y_test)}") 
# Create the GridSearch estimator along with a parameter object containing the values to adjust
from sklearn.model_selection import GridSearchCV
param_grid = {'C': [1, 5, 10],
              'gamma': [0.0001, 0.0005, 0.001]}

# Create the GridSearchCV model
grid2 = GridSearchCV(model, param_grid, verbose=3)
# Train the model with GridSearch
grid2.fit(X_train_scaled, y_train)
print(grid2.best_params_)
print(grid2.best_score_)
best_model=SVC(kernel='linear', C=10, gamma=0.0001)
best_model
# 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 = 'exoplanet_svm.sav'
joblib.dump(best_model, filename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10324349017816355, 'fraction_numerical': 0.016902695294655094, 'mean_word_length': 5.311239193083574, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '423910', 'license': 'RSA-MD', 'n_tokens_mistral': 784, 'n_tokens_neox': 760, 'n_words': 223, 'path': 'machine_learning_challenge.ipynb', 'repo_name': 'glennmacapinlac/machine-learning-challenge', 'size': '2189'}