# ---
# 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
# ---

# # Membuat model dengan pipeline

# +
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

import sklearn
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.preprocessing import MinMaxScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from sklearn.impute import SimpleImputer
# -

df = pd.read_csv('breast-cancer-datasets.csv')
df.head()

df.isnull().sum()

df.drop(columns=['Unnamed: 32','id'], inplace=True)

df.head()

df_baru = df.copy(deep=True)

df_baru['diagnosis'] = df['diagnosis'].map({'M':1, 'B':0})

df_baru.head()

correlation = df_baru.corr()['diagnosis']
correlation

strong_corr = correlation[correlation >= 0.5]
strong_corr

strong_corr.keys().to_list()

y = df_baru['diagnosis']
X = df_baru[strong_corr.keys().to_list()[1:]]

X.shape , y.shape

X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=0.8, random_state=42)

X_train.dtypes

X_train.shape, X_test.shape, y_train.shape, y_test.shape

numerical_pipeline = Pipeline([
    ('inputer', SimpleImputer(strategy='mean')),
    ('sclare', MinMaxScaler())
])

from sklearn.svm import SVC

pipeline = Pipeline([
    ('prepo', numerical_pipeline),
    ('algo', SVC())
])

# ## parameter Tuning

parameter = {
    'algo__C': [1,10,100,1000],
    'algo__degree': range(1,5)
}

model = GridSearchCV(pipeline, param_grid=parameter, cv=3, n_jobs=-1, verbose=2)
model.fit(X_train, y_train)

model.best_params_

model.score(X_test, y_test)

pd.DataFrame(model.cv_results_).sort_values('rank_test_score')



StarcoderdataJupyterScriptsDedupFiltered