Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np # For mathematical calculations
  3. import seaborn as sns # For data visualization
  4. import matplotlib.pyplot as plt # For plotting graphs
  5. import warnings # To ignore any warnings
  6. warnings.filterwarnings("ignore")
  7.  
  8. dataset=pd.read_csv("cancer.csv")
  9. X = dataset.iloc[:, 1:31].values
  10. Y = dataset.iloc[:, 31].values
  11.  
  12. #Encoding categorical data values
  13. from sklearn.preprocessing import LabelEncoder
  14. labelencoder_Y = LabelEncoder()
  15. Y = labelencoder_Y.fit_transform(Y)
  16.  
  17.  
  18.  
  19.  
  20. # Splitting the dataset into the Training set and Test set
  21. from sklearn.model_selection import train_test_split
  22. X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.25, random_state = 0)
  23.  
  24.  
  25.  
  26. #Feature Scaling
  27. from sklearn.preprocessing import StandardScaler
  28. sc = StandardScaler()
  29. X_train = sc.fit_transform(X_train)
  30. X_test = sc.transform(X_test)
  31.  
  32.  
  33. #Using Logistic Regression Algorithm to the Training Set
  34. from sklearn.linear_model import LogisticRegression
  35. classifier = LogisticRegression(random_state = 0)
  36. classifier.fit(X_train, Y_train)
  37. #Using KNeighborsClassifier Method of neighbors class to use Nearest Neighbor algorithm
  38. from sklearn.neighbors import KNeighborsClassifier
  39. classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2)
  40. classifier.fit(X_train, Y_train)
  41.  
  42. #Using SVC method of svm class to use Support Vector Machine Algorithm
  43.  
  44. from sklearn.svm import SVC
  45. classifier = SVC(kernel = 'linear', random_state = 0)
  46. classifier.fit(X_train, Y_train)
  47.  
  48. #Using SVC method of svm class to use Kernel SVM Algorithm
  49.  
  50. from sklearn.svm import SVC
  51. classifier = SVC(kernel = 'rbf', random_state = 0)
  52. classifier.fit(X_train, Y_train)
  53.  
  54. #Using GaussianNB method of naïve_bayes class to use Naïve Bayes Algorithm
  55.  
  56. from sklearn.naive_bayes import GaussianNB
  57. classifier = GaussianNB()
  58. classifier.fit(X_train, Y_train)
  59.  
  60. #Using DecisionTreeClassifier of tree class to use Decision Tree Algorithm
  61.  
  62. from sklearn.tree import DecisionTreeClassifier
  63. classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
  64. classifier.fit(X_train, Y_train)
  65.  
  66. #Using RandomForestClassifier method of ensemble class to use Random Forest Classification algorithm
  67.  
  68. from sklearn.ensemble import RandomForestClassifier
  69. classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0)
  70. classifier.fit(X_train, Y_train)
  71.  
  72.  
  73.  
  74. Y_pred = classifier.predict(X_test)
  75.  
  76.  
  77. from sklearn.metrics import confusion_matrix
  78. cm = confusion_matrix(Y_test, Y_pred)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement