text_plain_output_1.png image_output_1.png
from sklearn.datasets import load_breast_cancer

from sklearn.ensemble import RandomForestClassifier

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import classification_report, confusion_matrix

from sklearn.metrics import 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.model_selection import train_test_split

from sklearn.neighbors import KNeighborsClassifier

from sklearn.tree     import DecisionTreeClassifier

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd

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

import seaborn as sns

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

M = data[data['diagnosis'] == 'M']
B = data[data['diagnosis'] == 'B']

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)

score_list = []
for each in range(1, 15):
    knn2 = KNeighborsClassifier(n_neighbors=each)
    knn2.fit(x_train, y_train)
    current_score = knn2.score(x_test, y_test)
    score_list.append(current_score)

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)

clf = DecisionTreeClassifier()
clf = clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)

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)
dt_cm = confusion_matrix(y_test, dt_pred)
rf_cm = confusion_matrix(y_test, rf_pred)

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)
import numpy as np
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.15, random_state=42)

from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier(n_estimators=100, random_state=1)
rf.fit(x_train, y_train)
y_pred = rf.predict(x_test)
y_true = y_test

from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_true, y_pred)

import seaborn as sns
import matplotlib.pyplot as plt

f,ax=plt.subplots(figsize=(5,5))
sns.heatmap(cm,annot=True,linewidth=0.5,linecolor='red',fmt='.0f',ax=ax)
plt.xlabel('y_pred')
plt.ylabel('y_true')
plt.show()

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
x1 = np.random.normal(25, 5, 1000)
y1 = np.random.normal(25, 5, 1000)
x2 = np.random.normal(55, 5, 1000)
y2 = np.random.normal(60, 5, 1000)
x3 = np.random.normal(55, 5, 1000)
y3 = np.random.normal(15, 5, 1000)
x = np.concatenate((x1, x2, x3), axis=0)
y = np.concatenate((y1, y2, y3), axis=0)
dictionary = {'x': x, 'y': y}
data = pd.DataFrame(dictionary)

data.head()