我正在尝试通过危险因素明智地预测肺癌。我困惑于我是否获得正确的价值,以及可视化SVM预测数据的最佳方法是什么。
脚本
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('lung_cancer.csv')
dataset.loc[dataset['GENDER'] == 'F', 'GENDER'] = 0
dataset.loc[dataset['GENDER'] == 'M', 'GENDER'] = 1
X = dataset.iloc[:, 0:14].values
y = dataset.iloc[:, 15].values
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
from sklearn.svm import SVC
C = 1.0
classifier = SVC(kernel='poly', C=C, decision_function_shape='ovr').fit(X, y)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
from sklearn.metrics import classification_report, confusion_matrix
cm = confusion_matrix(y_test,y_pred)
class_report = classification_report(y_test,y_pred)
输入文件
GENDER AGE SMOKING YELLOW_FINGERS ANXIETY PEER_PRESSURE CHRONIC DISEASE FATIGUE ALLERGY WHEEZING ALCOHOL CONSUMING COUGHING SHORTNESS OF BREATH SWALLOWING DIFFICULTY CHEST PAIN LUNG_CANCER
F 59 0 0 0 1 0 1 0 1 0 1 1 0 1 0
F 63 0 1 0 0 0 0 0 1 0 1 1 0 0 0
F 75 0 1 0 0 1 1 1 1 0 1 1 0 0 1
M 69 0 1 1 0 0 1 0 1 1 1 1 1 1 1
M 74 1 0 0 0 1 1 1 0 0 0 1 1 1 1
M 63 1 1 1 0 0 0 0 0 1 0 0 1 1 0
请提出相同的建议。预先谢谢你