text_plain_output_1.png
from sklearn.datasets import load_breast_cancer

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import classification_report, confusion_matrix

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

from sklearn.tree     import DecisionTreeClassifier

import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data = pd.read_csv('../input/classification/data.csv')
data.drop(['id', 'Unnamed: 32'], axis=1, inplace=True)

data.diagnosis = [1 if each == 'M' else 0 for each in data.diagnosis]
y = data.diagnosis.values
x_data = data.drop(['diagnosis'], axis=1)
x = (x_data - np.min(x_data)) / (np.max(x_data) - np.min(x_data))
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3, random_state=42)
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=8)
knn.fit(x_train, y_train)
prediction = knn.predict(x_test)

pima = pd.read_csv('../input/pima-indians-diabetes-database/diabetes.csv')
pima['Pregnancies'] = pima['Pregnancies'].astype('float')

feature_cols = ['pregnant', 'insulin', 'bmi', 'age', 'glucose', 'bp', 'pedigree']
y = pima.Outcome
X = pima.drop(['Outcome'], axis=1)

from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix
bc = load_breast_cancer()
X = bc.data
y = bc.target
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
decision_tree = DecisionTreeClassifier()
random_forest = RandomForestClassifier(n_estimators=100)
decision_tree.fit(X_train, y_train)
random_forest.fit(X_train, y_train)
dt_pred = decision_tree.predict(X_test)
rf_pred = random_forest.predict(X_test)
print('Decision Tree Model')
print(classification_report(y_test, dt_pred, target_names=bc.target_names))
print('Random Forest Model')
print(classification_report(y_test, rf_pred, target_names=bc.target_names))
dt_cm = confusion_matrix(y_test, dt_pred)
rf_cm = confusion_matrix(y_test, rf_pred)