Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np # For mathematical calculations
- import seaborn as sns # For data visualization
- import matplotlib.pyplot as plt # For plotting graphs
- import warnings # To ignore any warnings
- warnings.filterwarnings("ignore")
- dataset=pd.read_csv("cancer.csv")
- X = dataset.iloc[:, 1:31].values
- Y = dataset.iloc[:, 31].values
- #Encoding categorical data values
- from sklearn.preprocessing import LabelEncoder
- labelencoder_Y = LabelEncoder()
- Y = labelencoder_Y.fit_transform(Y)
- # Splitting the dataset into the Training set and Test set
- from sklearn.model_selection import train_test_split
- X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.25, random_state = 0)
- #Feature Scaling
- from sklearn.preprocessing import StandardScaler
- sc = StandardScaler()
- X_train = sc.fit_transform(X_train)
- X_test = sc.transform(X_test)
- #Using Logistic Regression Algorithm to the Training Set
- from sklearn.linear_model import LogisticRegression
- classifier = LogisticRegression(random_state = 0)
- classifier.fit(X_train, Y_train)
- #Using KNeighborsClassifier Method of neighbors class to use Nearest Neighbor algorithm
- from sklearn.neighbors import KNeighborsClassifier
- classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2)
- classifier.fit(X_train, Y_train)
- #Using SVC method of svm class to use Support Vector Machine Algorithm
- from sklearn.svm import SVC
- classifier = SVC(kernel = 'linear', random_state = 0)
- classifier.fit(X_train, Y_train)
- #Using SVC method of svm class to use Kernel SVM Algorithm
- from sklearn.svm import SVC
- classifier = SVC(kernel = 'rbf', random_state = 0)
- classifier.fit(X_train, Y_train)
- #Using GaussianNB method of naïve_bayes class to use Naïve Bayes Algorithm
- from sklearn.naive_bayes import GaussianNB
- classifier = GaussianNB()
- classifier.fit(X_train, Y_train)
- #Using DecisionTreeClassifier of tree class to use Decision Tree Algorithm
- from sklearn.tree import DecisionTreeClassifier
- classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
- classifier.fit(X_train, Y_train)
- #Using RandomForestClassifier method of ensemble class to use Random Forest Classification algorithm
- from sklearn.ensemble import RandomForestClassifier
- classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0)
- classifier.fit(X_train, Y_train)
- Y_pred = classifier.predict(X_test)
- from sklearn.metrics import confusion_matrix
- cm = confusion_matrix(Y_test, Y_pred)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement