# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import matplotlib.pyplot as plt
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from os import path

data = pd.read_csv("cumulative.csv")

data.head()

drop_columns = ['rowid', 'kepid', 'kepoi_name', 'kepler_name', 'koi_disposition','koi_tce_delivname']

df = data.drop(columns = drop_columns)

df = df.dropna(axis = "columns", how = "all")

df = df.dropna()

df["koi_pdisposition"].value_counts()

df.columns

df.head()

# Assign X (data) and y (target)
X = df.drop("koi_pdisposition", axis=1)
y = df["koi_pdisposition"]
print(X.shape, y.shape)

#Split our data into training and testing
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)

# ## MinMax Scaler

#Fit on the training data
X_scaler = MinMaxScaler().fit(X_train)
X_scaler.get_params()

X_train_scaled = X_scaler.transform(X_train)
X_test_scaled = X_scaler.transform(X_test)
X_test_scaled

#Create a Logistic Regression Model
classifier = LogisticRegression()
classifier

y_train.value_counts()

y_test.value_counts()

#Fit (train) or model using the training data
classifier.fit(X_train_scaled,y_train)

#Validate the model using the test data
#classifier.score makes predictions
print(f"Training Data Score: {classifier.score(X_train, y_train)}")
print(f"Testing Data Score: {classifier.score(X_test, y_test)}")

# ## Grid Search

# Create the GridSearch estimator along with a parameter object containing the values to adjust
param_grid = {'C': [1, 5, 10, 50],
              'penalty': ["l1", "l2"]}
model = LogisticRegression(solver = "liblinear")
grid = GridSearchCV(model, param_grid, verbose=3)

# Fit the model using the grid search estimator. 
# This will take the SVC model and try each combination of parameters
grid.fit(X_train_scaled, y_train)

# List the best parameters for this dataset
print(grid.best_params_)

# List the best score
print(grid.best_score_)

# Make predictions with the hypertuned model
predictions = grid.predict(X_test)

print('Test Acc: %.3f' % grid.score(X_test, y_test))











StarcoderdataJupyterScriptsDedupFiltered