<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.
df.columns

#Columns that are likely to be significant (Error measurement columns are excluded)
#koi_time0bk,koi_impact,koi_duration,koi_depth,koi_prad,koi_teq,koi_insol,koi_model_snr,koi_steff,koi_slogg,koi_srad,koi_kepmag
X = df[['koi_kepmag','koi_slogg','koi_period']]
df.columns<jupyter_output><empty_output><jupyter_text>Create a Train Test SplitUse `koi_disposition` for the y values<jupyter_code>y=df[["koi_disposition"]]
# label_encoder = LabelEncoder()
# label_encoder.fit(y)
# encoded_y = label_encoder.transform(y)
#encoded_y_test = label_encoder.transform(y_test)


X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
X_scaler = MinMaxScaler().fit(X_train)
X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)


# Step 1: 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)

# Step 2: Convert encoded labels to one-hot-encoding
y_train_categorical = to_categorical(encoded_y_train)
y_test_categorical = to_categorical(encoded_y_test)
y_test_categorical

#To re-add the labels use the below code after the model is finished
#predicted=label_encoder.inverse_transform(encoded_y)
#predicted
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
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 import tree
model = tree.DecisionTreeClassifier()
model = model.fit(X_train_scaled, y_train_categorical)
print(f"Training score: {model.score(X_train_scaled,y_train_categorical)}")
print(f"Test score: {model.score(X_test_scaled,y_test_categorical)}")

# model_loss, model_accuracy = model.evaluate(
#     X_train_scaled, y_train_categorical, verbose=0)
# #print(f"Training Data Score: {model.score(X_train_scaled, y_train)}")
# print(f"Training Model Loss:{X_train_scaled}\n Training Model Accuracy: {model_accuracy}")
# model_loss, model_accuracy = model.evaluate(
#     X_test_scaled, y_test_categorical, verbose=0)
# #print(f"Testing Data Score: {model.score(X_test_scaled, y_test)}")
# print(f"Test Model Loss:{X_test_scaled}\n Test Model Accuracy: {model_accuracy}")
# Support vector machine linear classifier
from sklearn.svm import SVC 
model2 = SVC(kernel='linear')
model2.fit(X_train_scaled, y_train)<jupyter_output>C:\Users\sdelc\anaconda3\envs\PythonData\lib\site-packages\sklearn\utils\validation.py:63: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  return f(*args, **kwargs)<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],
              'gamma': [0.0001, 0.001, 0.01]}
grid = GridSearchCV(model2, param_grid, verbose=3)
# Train the model with GridSearch
grid.fit(X_train_scaled, y_train)
print(grid.best_params_)
print(grid.best_score_)
model2=grid.best_estimator_<jupyter_output>{'C': 1, 'gamma': 0.0001}
0.4949457498599175
<bound method ClassifierMixin.score of SVC(kernel='linear')><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 = 'Salvador_SVC_Model.sav'
joblib.dump(model2, filename)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup